[prog] [C] strings bug

Robert J. Hansen rjh at sixdemonbag.org
Thu Apr 10 10:53:49 EST 2003

> Well, I have less exalted sources to refer to, but I remember being taught
> that with C++, unlike C, uninitialised variables were initialised to zero

C is the same way:


#include <stdio.h>

int x;

int main(int argc, char *argv[])
  printf("Value of x = %d\n", x);
  return 0;


[rjh at numbers fishtank2]$ gcc test.c -o t -Wall -W -ansi -pedantic
test.c: In function `main':
test.c:5: warning: unused parameter `argc'
test.c:5: warning: unused parameter `argv'
[rjh at numbers fishtank2]$ ./t

... Putting GCC into its strictest ANSI conformance mode, with maximum
warnings, gives warnings about unused parameters but not about using
global variables which haven't been explicitly initialized.

I've seen quite a bit of real-world C code (telephone switching
software, PGP 6.x/7.x, etc.) which have used implicit variable
initialization--regardless of whether it's good form or not (I agree
that it's bad form), it's in widespread enough usage that C programmers
ought to know it exists.  :)

Robert J. Hansen <rjh at sixdemonbag.org>

More information about the Programming mailing list