RE: [Dev-C++] #DEFINE versus cont variables in array inicializations
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2003-05-30 17:47:35
|
At least for scalar data types, it doesn't matter if a global const xx variable is used in other modules. Since the compiler inlines the value of the const variable everytime it is used, there is no need to keep a global reference for use by other source files. Since an address is 4 bytes for normal 32-bit code, any const variable <= 4 byte will consume same space for the inlined value as the address needed to reference a real variable. However, the inlined value will automatically follow in the instruction stream, thereby using the L1/L2 caches optimally, while an address reference to a separate storage would have to use a different cache line in the processor. The net result is that a global 'const int xx = <value>' is just as efficient as if the declararation was written locally within a function. Both alternatives will be inlined, without any global or auto variable whatsoever. /Per W On Fri, 30 May 2003, Ioannis Vranos wrote: > > -----Original Message----- > > From: Per Westermark [mailto:pw...@ia...] > > Sent: Friday, May 30, 2003 2:39 PM > > To: Ioannis Vranos > > Cc: Dev-C++ Mailing List > > Subject: RE: [Dev-C++] #DEFINE versus cont variables in array > > inicializations > > > > > > If the reference is declared auto, the compiler can optimize away the > > reference, but if it's declared as a global, the compiler > > won't optimize > > it away, since by definition, a reference - just like a > > pointer - is an > > address to a value, not the value itself. > > > > Yes I agree. I was talking about local auto const references. Global const > variables are difficult to optimise out too, because the compiler doesn't > know if it is used in another compilation unit (file). > > > > > Ioannis Vranos > > * Programming pages: http://www.noicys.freeurl.com > * Alternative URL 1: http://run.to/noicys > * Alternative URL 2: http://www.noicys.cjb.net > > > > > ------------------------------------------------------- > This SF.net email is sponsored by: eBay > Get office equipment for less on eBay! > http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5 > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |