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...@te...> - 2003-05-30 23:24:25
|
> -----Original Message----- > From: Per Westermark [mailto:pw...@ia...] > Sent: Saturday, May 31, 2003 3:18 AM > To: Ioannis Vranos > Cc: Dev-C++ Mailing List > Subject: RE: [Dev-C++] #DEFINE versus cont variables in array > inicializations > > > Give a declaration: > > const int SIZE = 7; > > If you don't take the address of it, the compiler will generate code > looking like: It is difficult for the compiler to know if I use its address in another file. Usually the linker notices the uses in other files. > > 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. I can't understand the above very much but I do not think the compiler cn check every file for this, only the linker. Also what if I make obj files and then add some code in a cpp file that uses the address, make a new obj annd then link all objs together? > 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. This is a bit difficult. You know, extern const int SIZE; is a *definition* in the absense of another definition and takes the default value 0. Ioannis Vranos * Programming pages: http://www.noicys.freeurl.com * Alternative URL 1: http://run.to/noicys * Alternative URL 2: http://www.noicys.cjb.net |