Static global arrays

B

Billy Mays

Quick question: Are static global arrays initialized to all 0's like
static ints? If my static global array was of all doubles, would they
be initialized to 0.0?
 
M

mohangupta13

Quick question:  Are static global arrays initialized to all 0's like
static ints?  If my static global array was of all doubles, would they
be initialized to 0.0? Yes
 
M

Malcolm McLean

Quick question:  Are static global arrays initialized to all 0's like
static ints?  If my static global array was of all doubles, would they
be initialized to 0.0?
All bits zero doesn't necessarily represent double 0.0, though it does
on all common architectures.

There might be some wiggle room in the standard to allow compilers for
these unusual platforms to not initalise static doubles to zero.
 
R

Ralf Damaschke

Malcolm said:
Yes.

All bits zero doesn't necessarily represent double 0.0, though it does
on all common architectures.

Which was not the question.
There might be some wiggle room in the standard to allow compilers for
these unusual platforms to not initalise static doubles to zero.

No (unless you explicitly initialized them with a different value).

-- Ralf
 
M

Morris Keesan

All bits zero doesn't necessarily represent double 0.0, though it does
on all common architectures.

There might be some wiggle room in the standard to allow compilers for
these unusual platforms to not initalise static doubles to zero.

Nope. The standard doesn't say anything about static objects being
initialized to all bits zero.
C99 6.7.8 paragraph 10 says,

If an object that has static storage duration is not initialized
explicitly, then:

- if it has pointer type, it is initialized to a null pointer;

- if it has arithmetic type, it is initialized to
(positive or unsigned) zero;

- if it is an aggregate, every member is initialized
(recursively) according to these rules;

The last clause I've quoted covers the case of arrays and their members,
and the clause before it covers the case of doubles. Implementations for
platforms where floating-point zero, or null pointers, are not all-bits
zero may have to do some extra work to properly initialize pointers and
doubles.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top