Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

discrepancy

Status
Not open for further replies.

joeGrammar

Programmer
Jun 4, 2001
162
CA
How come

#define blah 20

type var[blah];

compiles and

const int blah = 20;

type var[blah];

does not?
 
Ahhh, I've run into this problem a year or so before. Its not a problem. Its the fact that you can't dynamically declare the size of an array in this way. See thread116-107726
 
Both situations compile.

First situation: blah is a define which means it is a preprocesor directive and the preprocessor makes the replacements and at compile time your code will look like type var[20]

Second situation - it compiles as long as you keep the const. Else the compiler will require a const values. Arrays cannot be dinamically redimensioned if they are not on the heap(constructed with new).

Hope this helps,
s-)

Blessed is he who in the name of justice and good will, shepards the week through the valley of darkness...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top