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 08:30:27
|
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. If the global was declared static, then file-level global optimization would be able to notice if no part of the the file used it as an address and might then convert it back to just a 'const int', but then again: why not declare it as 'const int' from the beginning, since that is the optimal form if we don't want to play with the address of it. /Per W On Fri, 30 May 2003, Ioannis Vranos wrote: > > -----Original Message----- > > From: dev...@li... > > [mailto:dev...@li...] On Behalf > > Of Per Westermark > > Sent: Friday, May 30, 2003 4:23 AM > > To: Ioannis Vranos > > Cc: Dev-C++ Mailing List > > Subject: RE: [Dev-C++] #DEFINE versus cont variables in array > > inicializations > > > > > > Yes, we agree that 'const int x = <value>' is efficient. > > We don't agree that 'const int &x = <value>' is efficient. > > > The reference can't be used to provide the size of a built in array, so my > mistake for that. > > > On the other hand regarding reference, a compiler would be able to optimise > out and make it occupy no more space. > > > const int &x=7; > > > Can you tell me why that wouldn't be able to be equivalent to #define x 7 > when used just as a value and not accessed in any other way? > > As I can think of it, a const reference should be more eaiser to optimise > out than a const variable. > > > > 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 > |