diff options
| author | Alex Colomar <alx.manpages@gmail.com> | 2022-09-15 16:40:27 +0200 |
|---|---|---|
| committer | Alex Colomar <alx.manpages@gmail.com> | 2022-09-15 18:07:48 +0200 |
| commit | b42296e4feaffd0ca4e5675fa181d19891f947ce (patch) | |
| tree | b16ebd13da8366c95ace85f538f32f3043dc12e3 /man3/regex.3 | |
| parent | 489712257bb14b3674f9e9037c65b371b3f570c0 (diff) | |
| download | man-pages-b42296e4feaffd0ca4e5675fa181d19891f947ce.tar.gz | |
Various pages: EXAMPLES: Use unsigned types for loop iterators
Looping with unsigned types is safer. See the link below.
When the iterators are used for accessing an array, use size_t;
otherwise, use the most appropriate unsigned type, which in most
cases is just 'unsigned int'.
Also adjust other variables that have to interact with the
iterators, to avoid comparison of integers of different
signedness.
Link: <https://gustedt.wordpress.com/2013/07/15/a-praise-of-size_t-and-other-unsigned-types/>
Cc: Jens Gustedt <jens.gustedt@inria.fr>
Signed-off-by: Alex Colomar <alx.manpages@gmail.com>
Diffstat (limited to 'man3/regex.3')
| -rw-r--r-- | man3/regex.3 | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/man3/regex.3 b/man3/regex.3 index e423e442d8..c86628e9a2 100644 --- a/man3/regex.3 +++ b/man3/regex.3 @@ -351,13 +351,13 @@ int main(void) printf("String = \e"%s\e"\en", str); printf("Matches:\en"); - for (int i = 0; ; i++) { + for (unsigned int i = 0; ; i++) { if (regexec(®ex, s, ARRAY_SIZE(pmatch), pmatch, 0)) break; off = pmatch[0].rm_so + (s \- str); len = pmatch[0].rm_eo \- pmatch[0].rm_so; - printf("#%d:\en", i); + printf("#%zu:\en", i); printf("offset = %jd; length = %jd\en", (intmax_t) off, (intmax_t) len); printf("substring = \e"%.*s\e"\en", len, s + pmatch[0].rm_so); |
