Alistair George 0 Posted December 14, 2009 Report Share Posted December 14, 2009 Hi according to previous C I've used, char variables at declaration were default value 0. It seems that this is not so with BoostC? If not, whats the preferred method to initialise a bunch of variables at same time. eg must one do v1=0;v2=0;v3=0; not v1=v2=v3=0; Cheers, Al PS understood that assigning variables at start can use memory, but only if some of the variables are not being used correct? Quote Link to post Share on other sites
Reynard 0 Posted December 14, 2009 Report Share Posted December 14, 2009 If you declare a variable at 'static' it will be initialised to zero unless you tell the compiler otherwise (BoostC manual page 22). If you wish to zero a bunch of variables to zero use the v1=0, v2=0 etc method. The other method does not zero all your variables, only the last one. Cheers Reynard Quote Link to post Share on other sites
Ian Harris 0 Posted December 14, 2009 Report Share Posted December 14, 2009 No, it's the other way around. SourceBoost will initialise your variables to 0 unless you have -Su ( disable initialization of uninitialized static variables) on the BoostC command line. Quote Link to post Share on other sites
Reynard 0 Posted December 14, 2009 Report Share Posted December 14, 2009 Isn't that what I said Ian ? Quote Link to post Share on other sites
Ian Harris 0 Posted December 14, 2009 Report Share Posted December 14, 2009 Isn't that what I said Ian ? :-) Okay to be clear: if you don't explicitly initialise a variable, eg, int my_variable; it *will* be initialised to 0 unless you use the command line switch. In a lot of cases it really doesn't matter what the initial value is, you can save memory by not forcing everything to zero. cheers Ian. Quote Link to post Share on other sites
Reynard 0 Posted December 14, 2009 Report Share Posted December 14, 2009 I think only uninitialised static variables will be zeroed. Cheers Reynard Quote Link to post Share on other sites
Alistair George 0 Posted December 14, 2009 Author Report Share Posted December 14, 2009 Isn't that what I said Ian ? :-) Okay to be clear: if you don't explicitly initialise a variable, eg, int my_variable; it *will* be initialised to 0 unless you use the command line switch. In a lot of cases it really doesn't matter what the initial value is, you can save memory by not forcing everything to zero. cheers Ian. Actually, I could stand to be corrected on this, but the reason I was initializing was due to some startup numbers not being at zero. Could always be me of course! Cheers, Al. Quote Link to post Share on other sites
davidb 0 Posted December 14, 2009 Report Share Posted December 14, 2009 Sorry Ian I agree with Reynard and Al. A variable is only initialised to zero if it is declared static AND the -Su switch is not invoked. All other variables are left uninitialised. Regards davidb Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.