delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1993/06/06/07:55:46

From: gt8741b AT prism DOT gatech DOT edu
Subject: Re: static variable initialization
To: djgpp AT sun DOT soe DOT clarkson DOT edu (djgpp mailing list)
Date: Sun, 6 Jun 1993 07:32:45 -0400 (EDT)

> 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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019