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-31 00:21:40
|
> -----Original Message-----
> From: Per Westermark [mailto:pw...@ia...]
> Sent: Saturday, May 31, 2003 6:38 AM
> To: Ioannis Vranos
> Cc: Dev-C++ Mailing List
> Subject: RE: [Dev-C++] #DEFINE versus cont variables in array
> inicializations
>
>
> See below
>
>
> If you know that you need to take the address in another file, then
> declare it as:
> extern const int SIZE = 7;
I am sorry to tell you this, but this is *nonsense*. The C++ standard
doesn't require to define it like this.
I can define a const object in the global namespace:
const int x=7;
and in another file I can do this:
#include <iostream>
extern const int x;
// ...
void f()
{
const unsigned char *p=reinterpret_cast<const unsigned char *>(&x);
// Shows SIZE representation in memory in byte values
// including padding bits
for(unsigned long i=0; i<sizeof(x); ++i)
std::cout<<static_cast<short>(p[i])<<" ";
}
> It doesn't. Either make sure that the file that declares SIZE
> takes it's
> address, or declare it as 'extern const int SIZE = 7;'
Please direct me in the C++ standard where it mentions such a requirement.
Ioannis Vranos
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL 1: http://run.to/noicys
* Alternative URL 2: http://www.noicys.cjb.net
|