Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Reportbug-Version: 3.39 X-Debbugs-Cc: [EMAIL PROTECTED] Package: gcc-4.2 Version: 4.2.3-3 Severity: minor
I try to compile the attached C file via the command $ gcc -Wall -Os -S % and get several warnings: test.c:6: warning: initializer element is not constant test.c:6: warning: (near initialization for ‘i’) test.c:7: warning: initializer element is not constant test.c:7: warning: (near initialization for ‘si’) test.c:8: warning: initializer element is not constant test.c:8: warning: (near initialization for ‘ci’) test.c:11: warning: initializer element is not constant test.c:11: warning: (near initialization for ‘s’) Now all of the strlen() calls get (correctly!) optimized out into constants; but why do I get the warnings? I know that constants used within functions could be done via atstart() mechanism or on first function call; but as these lengths are already constants in the assembler output, any strlen() overloading wouldn't work anyway. So, as conclusion: If strlen() is taken as known for constant strings (and optimized as such), no warning about its return value being non-constant should be given. Or am I missing some part of the picture? -- System Information: Debian Release: lenny/sid APT prefers testing APT policy: (600, 'testing'), (50, 'unstable'), (1, 'experimental') Architecture: i386 (i686) Kernel: Linux 2.6.22-1-686 (SMP w/1 CPU core) Locale: LANG=de_AT.UTF-8, LC_CTYPE=de_AT.UTF-8 (charmap=UTF-8) (ignored: LC_ALL set to de_AT.utf8) Shell: /bin/sh linked to /bin/bash Versions of packages gcc-4.2 depends on: ii binutils 2.18.1~cvs20080103-3 The GNU assembler, linker and bina ii cpp-4.2 4.2.3-3 The GNU C preprocessor ii gcc-4.2-base 4.2.3-3 The GNU Compiler Collection (base ii libc6 2.7-10 GNU C Library: Shared libraries ii libgcc1 1:4.3.0-3 GCC support library Versions of packages gcc-4.2 recommends: ii libc6-dev 2.7-10 GNU C Library: Development Librari -- no debconf information
test.s
Description: Binary data
#include <string.h> #include <stdio.h> #define STG "asdf" int i=strlen(STG); static int si=strlen(STG); const int ci=strlen(STG); struct { int i; } s={ .i=strlen(STG) }; int main(void) { int l=strlen(STG); const int cl=strlen(STG); printf("local %d, const local %d; global %d, static %d, const %d, struc %d\n", l, cl, i, si,ci, s.i); return 0; }