Stupid C question

From: Paul Koning <>
Date: Thu Sep 16 20:00:47 2004

>>>>> "Richard" == Richard A Cini <> writes:

 Richard> Hello, all: OK, here's where my lack of intimate knowledge
 Richard> of C shows. I'm working on a graphics board add-in for the
 Richard> Altair32 Emulator. I have 16 of the following declarations,
 Richard> one for each color supported by the board:

 Richard> const COLORREF colGray = RGB(128,128,128) ; // 8

That declares a variable (a read-only one) whose initial value is that

 Richard> The RGB macro converts an RGB color value to a different
 Richard> datatype (a DWORD) for use with various Windows APIs, such
 Richard> as the one I'm using to draw color boxes. The colors are in
 Richard> order per the video board docs, so I create an array of
 Richard> COLORREFs:

 Richard> static COLORREF colColors[] = {colGray, colMaroon, colNavy,
 Richard> colPurple, colGreen, colOlive, colTeal, colSilver, colBlack,
 Richard> colRed, colBlue, colMagenta, colLime, colYellow, colCyan,
 Richard> colWhite} ;

 Richard> Now, here's the problem. I get compiler error C2099 on the
 Richard> declaration of colColors. C2099 translates to "initializer
 Richard> is not a constant". I'm sure that the solution is something
 Richard> obvious to the trained eye, but I'm not seeing it. Can
 Richard> someone identify what I'm missing?

Sure. You're telling it to initialize the array with variables.

If you want to initialize it with the addresses of those variables,
you have to say &foo. If you want to refer to the colors by name in
an initializer, you can't do it this way -- use #define instead:

#define colGray RGB(128,128,128) // etc.

and the rest of the code then works.

Received on Thu Sep 16 2004 - 20:00:47 BST

This archive was generated by hypermail 2.3.0 : Fri Oct 10 2014 - 23:37:29 BST