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 18:33:13
|
> -----Original Message-----
> From: Per Westermark [mailto:pw...@ia...]
> Sent: Saturday, May 31, 2003 12:19 AM
> To: Ioannis Vranos
> Cc: Dev-C++ Mailing List
> Subject: RE: [Dev-C++] #DEFINE versus cont variables in array
> inicializations
>
>
> At least for scalar data types, it doesn't matter if a global const xx
> variable is used in other modules.
Why? Imagine in another unit:
extern const int SIZE;
void f()
{
cout<<&SIZE;
}
> 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.
What if we use its address in another unit? What about this:
#include <cstring>
extern const int SIZE;
// in a function ...
using std::memcpy;
// ...
int *p=new int;
memcpy(p, &SIZE, sizeof(*p));
Ioannis Vranos
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL 1: http://run.to/noicys
* Alternative URL 2: http://www.noicys.cjb.net
|