Weird Problem

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
User avatar
carbonBased
Member
Member
Posts: 382
Joined: Sat Nov 20, 2004 12:00 am
Location: Wellesley, Ontario, Canada
Contact:

Re: Weird Problem

Post 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
mrd
Posts: 5
Joined: Wed Dec 14, 2005 12:00 am

Re: Weird Problem

Post 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.
User avatar
carbonBased
Member
Member
Posts: 382
Joined: Sat Nov 20, 2004 12:00 am
Location: Wellesley, Ontario, Canada
Contact:

Re: Weird Problem

Post 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
Da_Maestro
Member
Member
Posts: 144
Joined: Tue Oct 26, 2004 11:00 pm
Location: Australia

Re: Weird Problem

Post 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.
Last edited by Da_Maestro on Sun Dec 18, 2005 12:00 am, edited 1 time in total.
Two things are infinite: The universe and human stupidity. But I'm not quite sure about the universe.
--- Albert Einstein
Post Reply