RE: [Dev-C++] #DEFINE versus cont variables in array inicializations
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ioannis V. <iv...@em...> - 2003-05-29 20:12:39
|
At first the const reference can't be used for the size of the array, my
mistake.
For the rest, I do not get your point:
int main()
{
int array[17];
}
g++ -pedantic-errors -Wall -fexpensive-optimizations -O3 -ffloat-store
-mcpu=pentiumpro temp.cpp -o temp
29/05/2003 11:09 ?? 23.036 temp.exe
For the code:
int main()
{
const int SIZE=17;
int array[SIZE];
}
29/05/2003 11:10 ?? 23.036 temp.exe
So the compiler optimises out the const int thing.
Ioannis Vranos
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL 1: http://run.to/noicys
* Alternative URL 2: http://www.noicys.cjb.net
> -----Original Message-----
> From: Per Westermark [mailto:pw...@ia...]
> Sent: Friday, May 30, 2003 2:00 AM
> To: Ioannis Vranos
> Cc: Dev-C++ Mailing List
> Subject: RE: [Dev-C++] #DEFINE versus cont variables in array
> inicializations
>
>
> I guess you don't think of gcc as a decent compiler then.
>
> try gcc -O3 -S on the code below and look at the output.
> 4 byte for the value 7
> 4 byte for the SIZE reference.
> access loads SIZE and pushes [SIZE] (4 byte addr info + extra instr)
>
> with const int SIZE = 7
> zero byte for value
> every access pushes 7 directly. (4 byte value)
>
> Most compilers treat 'const int v = <value>' identical to #define XX
> <value>, i.e. optimal code is generated.
>
> /Per W
>
> On Thu, 29 May 2003, Ioannis Vranos wrote:
>
> > A third way that guarantees no space occupation by a decent
> compiler is:
> >
> >
> > const int &SIZE = 7;
> >
> >
> >
> >
> >
> >
> > 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
> >
>
>
|