[GRASS-dev] Re: is `initialized' initialized in HTML_Driver ()?

Glynn Clements glynn at gclements.plus.com
Mon Oct 13 16:18:18 EDT 2008


Ivan Shmakov wrote:

>  >>> Doesn't C require an explicit initial value for `initialized' here?
>  >>> Well, as it is a static variable it will be initialised to zero.
> 
>  >> Oh, never knew C has such a feature.  (Still, it may make sense to
>  >> add an explicit initializer for the sake of clarity.)
> 
>  > If you add an explicit initialiser, the variable will be placed in
>  > the data segment.
> 
>  > Variables which are implicitly initialised to "zero" (i.e. any global
>  > variables and "static" local variables lacking an explicit
>  > initialiser) are placed in the BSS segment. As the entire BSS segment
>  > is zero, its contents don't need to be stored in the resulting binary
>  > file.
> 
> 	Is this behavior mandated by some standard?

No.

> 	It seems not a very smart decision to require such things.  At
> 	least, gcc does, in my opinion, the right thing and puts the
> 	static variable initialized to zero (either explicitly or
> 	implicitly) to BSS:

Hmm; so it does. It didn't always; back in 2.x it would always put
initialised variables in the data segment[1].

[1] This was quite important in the early days of the PlayStation, as
there wasn't any run-time loader. It just read the executable directly
into memory, so anything which ended up in the BSS segment would be
left uninitialised. They eventually figured out how to disable the
don't-store-the-contents-of-BSS behaviour, meaning that porting code
from the PC didn't begin with a day spent adding " = 0" everywhere.

> 	Of course, if there are the compilers that produce different
> 	results in these cases, it may make sense to leave the code in
> 	its present state.

I wouldn't recommend adding explicit initialisers everywhere just in
case people are unaware that they're not needed.

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-dev mailing list