Mail Archives: djgpp/1993/06/06/08:55:51
>
> jih-shin ho: "static variable initialization" (Jun 5, 9:05):
> > Hi:
> > 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
> be a bad idea anyway, since half of the time zero would not be a good
> initial value.
>
> >Is this a bug ?
>
> I believe it is not a bug. Explicit initialisation is a must.
On page 219 of the C Programing Language - Second Edition (ANSI C) it is
written:
A static object not explicitly initialized is initialized as if it
(or its members) were assigned the constant 0. The initial value of an
automatic object not explicitly initialized is undefined.
>
>
> > -- Jih-Shin Ho
> >
>
> Department of Computer Science Tapio Lehtonen FAX 708 4441
> P.O. Box 26 (Teollisuuskatu 23) TELEX 122785 TSK SF
> SF-00014 UNIVERSITY OF HELSINKI PHONE + 358 0 7084185 room D320
> FINLAND Tapio DOT Lehtonen AT Helsinki DOT FI
>
>
>
--
-- Sincerely,
Gal Shalif, R&D group
/-----------------------------------------------------------------------\
| Gal Shalif | gal AT matis DOT ingr DOT COM (or ingr!matis!gal) |
| Software Engineer | Voice: +972 9-584684, ext. 110 |
| SEE Technologies Ltd. | Fax: +972 9-543917 |
\-----------------------------------------------------------------------/
- Raw text -