Page 2 of 2

Re: Weird Problem

Posted: Sat Dec 17, 2005 12:00 am
by carbonBased
mrd wrote: you don't need all that..

Code: Select all

unsigned char cpu_sign[13] = {0};
this will initialize the entire array to zero.
If I recall the C standard correctly, this is only true for static arrays. Since cpu_sign isn't static, the remainder of the array (1 to 12) is undefined.

--Jeff

Re: Weird Problem

Posted: Sat Dec 17, 2005 12:00 am
by mrd
carbonBased wrote: If I recall the C standard correctly, this is only true for static arrays. Since cpu_sign isn't static, the remainder of the array (1 to 12) is undefined.
According to both of my references, K&R C and C99, if there are fewer initializers than members of an aggregate (which includes arrays), then remaining members are implicity initialized to zero, the same as static aggregate members are.

Re: Weird Problem

Posted: Sun Dec 18, 2005 12:00 am
by carbonBased
Well I'd, of course, trust K&R over my memory :)

A lot of compilers don't fully support C99 yet (unfortunately), but if it's listed in K&R... and empirical evidence shows that GCC certainly behaves this way.

Cheers,
Jeff

Re: Weird Problem

Posted: Sun Dec 18, 2005 12:00 am
by Da_Maestro
The size increase you get when you initialise variables is small compared to the benefit you get from maintainability. Of course I wouldn't recommend intialising entire arrays (like page tables), but for small arrays like this a little benefit goes a long way in the future.

I say that succession planning holds the key to producing a stable and robust OS. If your current kernel *only just* manages to run, then what hope do future versions of your OS have?

We don't want to re-invent M$Win here.