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 20:29:59
|
Give a declaration:
const int SIZE = 7;
If you don't take the address of it, the compiler will generate code
looking like:
pushl $7
If you take the address of it, the compiler will notice and generate code
like:
pushl $_SIZE
...
_SIZE:
.long 7
where the second case will store _SIZE in .text and not in .data.
You will be able to take the address of SIZE from one object file. If you
declare 'const int SIZE = 7;' in another file to and try to take the
address of it, you will correctly get a linker error. If you in the other
file declares 'extern const int SIZE', that file will always reference the
variable SIZE, since it can't do any inlining.
/Per W
On Fri, 30 May 2003, Ioannis Vranos wrote:
> > -----Original Message-----
> > From: Per Westermark [mailto:pw...@ia...]
> > Sent: Saturday, May 31, 2003 2:04 AM
> > To: Ioannis Vranos
> > Cc: Dev-C++ Mailing List
> > Subject: RE: [Dev-C++] #DEFINE versus cont variables in array
> > inicializations
> >
> >
> > Oops, goofed a bit. See below.
> >
> > But then again
> > > - 'a const &int = <value>' is a complicated declaration
> > just to get a
> >
> > Should of course be 'const int SIZE = <value>'
> >
> > > "magic" address to compare against.
>
>
> I still do not understand what you mean by the above. The language rules are
> language rules. A global const variable has an address (at least it behaves
> as it has, when we want to use this address).
>
> Only references do not have their own address.
>
>
>
>
> 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
>
|