Mail Archives: djgpp/1993/06/06/07:55:46
> jih-shin ho: "static variable initialization" (Jun 5, 9:05):
> > I find that gcc won't initialize static variable if you don't initialize
> > it by hand.
> >
> > For example:
> >
> > static int i; <-- The value of i is undefined.
> >
> > static int i = 0; <-- You must use '= 0' to initialize i.
> >
> >
> > This behavior violates ANSI definition.
>
> Are You sure that ANSI C demands implicit initialisation to zero for any
> variables? I don't remember it that way, and could not find any mention
> about that in the book I had handy. Initialising to zero would
Initialization to 0 IS ANSI standard for static variables. From K&R 2:
"A static object not explicitly initialized is initialized as if it (or its
memberes) were assigned the constant 0."
> >Is this a bug ?
Yes, it is a bug.
--
Chris Adams | "Don't touch that! That's the history
Georgia Tech | eraser button!" - R&S
Internet: gt8741b AT prism DOT gatech DOT edu| "I chortle at thee, thou pathetic
----------------------------------+ chucklehead!" - the Wizard
- Raw text -