Static constant class members

Eljay Love-Jensen eljay@adobe.com
Sun Feb 29 17:13:00 GMT 2004


Hi Vova,

 >This construction works fine in gcc 3.3 ...

A "static int const" is a special exemption.

A pointer (even a static const one)  is not exempted.

 >This is true, but actual value of the constant wouldn't be available in 
files which includes "TxtVideo.h", so compiler wouldn't insert it as 
immediate operand, instead it will insert memory reference. Am I wrong ?

You are correct.  If you really want it to be an immediate operand in C++, 
do this:

class TxtVideo
{
public:
   static unsigned int* const getVBase() { return (unsigned int* 
const)0x0C00B8000L; }
...

That will be inserted as an inline function (since it's body is defined in 
the class), and the inline will optimize down to an immediate.

HTH,
--Eljay



More information about the Gcc-help mailing list