strstr.c:105:3: error: ‘for’ loop initial declar ations are only allowed in C99 or C11 mode

Giacomo Tesio <[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <CAHL7psHHH3fkr5D7R1+tap4nmKLSoirGrGpC5qoNGTZkn4G1NQ@mail.gmail.com>
Looking at the build logs I've also noticed this:

x86_64-jehanne-gcc
-B/home/giacomo/projects/Jehanne/repos/jehanne-test2/hacking/cross/pkgs/newlib/build/x86_64-jehanne/newlib/
-isystem /home/giacomo/projects/Jehanne/repos/jehanne-test2/hacking/cross/pkgs/newlib/build/x86_64-jehanne/newlib/targ-include
-isystem /home/giacomo/projects/Jehanne/repos/jehanne-test2/hacking/cross/pkgs/newlib/src/newlib/libc/include
-B/home/giacomo/projects/Jehanne/repos/jehanne-test2/hacking/cross/pkgs/newlib/build/x86_64-jehanne/libgloss/x86_64
-L/home/giacomo/projects/Jehanne/repos/jehanne-test2/hacking/cross/pkgs/newlib/build/x86_64-jehanne/libgloss/libnosys
-L/home/giacomo/projects/Jehanne/repos/jehanne-test2/hacking/cross/pkgs/newlib/src/libgloss/x86_64
   -I/home/giacomo/projects/Jehanne/repos/jehanne-test2/hacking/cross/pkgs/newlib/src/newlib/libc/sys/jehanne/include
-DPACKAGE_NAME=\"newlib\" -DPACKAGE_TARNAME=\"newlib\"
-DPACKAGE_VERSION=\"3.1.0\" -DPACKAGE_STRING=\"newlib\ 3.1.0\"
-DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -I.
-Isrc/newlib/libc/string -fno-builtin -DREENTRANT_SYSCALLS_PROVIDED
-DMALLOC_PROVIDED -DSIGNAL_PROVIDED -D_NO_GETLOGIN -D_NO_GETCWD
-D_NO_GETPASS -D_NO_GETUT -D_NO_PWRITE -D_NO_PREAD -DHAVE_FCNTL
-fno-omit-frame-pointer -DHAVE_INIT_FINI      -g -gdwarf-2 -ggdb -O2
-c -o lib_a-strstr.o `test -f 'strstr.c' || echo
'src/newlib/libc/string/'`strstr.c
src/newlib/libc/string/strstr.c: In function ‘strstr2’:
src/newlib/libc/string/strstr.c:105:3: error: ‘for’ loop initial
declarations are only allowed in C99 or C11 mode
   for (int c = hs[0]; h1 != h2 && c != 0; c = *++hs)
   ^
src/newlib/libc/string/strstr.c:105:3: note: use option -std=c99,
-std=gnu99, -std=c11 or -std=gnu11 to compile your code
src/newlib/libc/string/strstr.c: In function ‘strstr3’:
src/newlib/libc/string/strstr.c:115:3: error: ‘for’ loop initial
declarations are only allowed in C99 or C11 mode
   for (int c = hs[0]; h1 != h2 && c != 0; c = *++hs)
   ^
src/newlib/libc/string/strstr.c: In function ‘strstr4’:
src/newlib/libc/string/strstr.c:125:3: error: ‘for’ loop initial
declarations are only allowed in C99 or C11 mode
   for (int c = hs[0]; c != 0 && h1 != h2; c = *++hs)
   ^
src/newlib/libc/string/strstr.c: In function ‘strstr’:
src/newlib/libc/string/strstr.c:173:7: error: ‘for’ loop initial
declarations are only allowed in C99 or C11 mode
       for (int i = 0; i < ne_len; i++)
       ^
Makefile:851: recipe for target 'lib_a-strstr.o' failed

I guess this use of variable initialization in the for loop works fine
in linux, in cygwin and in amdgcn but it's a bit annoying in common
code like strstr.c

It also occurs in

newlib/libc/locale/freelocale.c:49
newlib/libc/string/memmem.c:149

Is it possible to move the counter declaration outside the loop?


Giacomo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.