Re: [Dev-C++] #DEFINE versus cont variables in array inicializations
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Zodiaq <zo...@ac...> - 2003-05-29 14:01:11
|
Hello André and all Dev-C++ users, Thursday, May 29, 2003, 3:08:42 PM, André wrote as follows: AMB> Dear Users, AMB> For the sake of flexibility, I think we only have two ways to iniciatize AMB> a AMB> size of an array: AMB> 1) via #define: AMB> #define MAX 10 AMB> ... AMB> int vect[MAX]; AMB> ... AMB> 2) via cont variable: AMB> const int size=10; AMB> ... AMB> int vetc[size]; AMB> ... AMB> So, in both ways, everytime if I need to change the size of the arrays, it´s AMB> only necessary to change 10 to the other value. -->>My questions: AMB> 1) Is there more ways to to this? enum ?? hehe But what for?? AMB> 2) For theese two ways presented here, when use one and when use the other? AMB> Explaining a little more what I need to know: in a "good programming AMB> technique" AMB> point of view, what of theese two is the preferred of the programmers AMB> (please AMB> don´t answer "pointers" ...lol). AFAIK const is more C++ like, and #define more C like... #define doesn't create 'real' variable, I mean it is only visible in first stage of preprocessing - precompiler raplaces every one of MAX into defined value, program does not see it in runtime... with const it is all different - it is created as variable (which is const), but during runtime you may const_cast it, check for its size, place in memory etc... So I must say I use both ways, but more often the const one... -- regards, Zodiaq |