C89 universal initializer {0}

Requests for features
Post Reply
DarkSchneider
Member
Posts: 71
Joined: Sun Apr 01, 2018 4:02 pm

C89 universal initializer {0}

Post by DarkSchneider »

Hi,

I have a static array of structs, and I'd like to initialize it to 0. On C89 there is the universal initializer {0}, that sets the full array, even if using structs, to 0.

Is there some other way, like some kind of:
REPEAT num_items
{ 0, ... , 0 },
ENDR
That I could use instead? I'd prefer not to have to do an initialize() method for the class only for zeroing that array at beginning.
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Re: C89 universal initializer {0}

Post by dom »

Uninitialised static data is placed in the bss section which is by default initialised to 0.
DarkSchneider
Member
Posts: 71
Joined: Sun Apr 01, 2018 4:02 pm

Re: C89 universal initializer {0}

Post by DarkSchneider »

OK so I remove the init then.

If I specify the section i.e. in code is also initialized to 0 or it gets the data that was already in that memory location?.
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Re: C89 universal initializer {0}

Post by dom »

So somewhat bizarrely, {0} is already supported for auto variables. I'm adding support for static variables at the moment so that should be in the next build as well.
Post Reply