Re: [Dev-C++] #DEFINE versus cont variables in array inicializations
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: <a_g...@ya...> - 2003-05-29 17:30:01
|
Hi Andre,
you are right, there's probably no third way out. Now I prefer to use the first one due to two reasons.
1> Being textual subsitution, the #define macro does not use up memory size whereas an integer uses up 32 bytes, though that is negligent for most purposes.
2> The more important being that apart from compiler systems that support C++ along with C, the interpretation of const by the compilers around is a bit non-standard. Like in the Cygwin gcc complier assigment to const variables result only in a warning at compile time and program runs fine, and prints out 20!!!.
#include <stdio.h>
int main()
{
const int i = 10;
i=20;
printf("%d\n",i);
return 0;
}/*main*/
So well although I cannot remember of a third way to do it right now, obviously the first approach is better.
André_Macário_Barros <and...@su...> wrote:
Dear Users,
For the sake of flexibility, I think we only have two ways to iniciatize
a
size of an array:
1) via #define:
#define MAX 10
...
int vect[MAX];
...
2) via cont variable:
const int size=10;
...
int vetc[size];
...
So, in both ways, everytime if I need to change the size of the arrays, it´s
only necessary to change 10 to the other value.
-->My questions:
1) Is there more ways to to this?
2) For theese two ways presented here, when use one and when use the other?
Explaining a little more what I need to know: in a "good programming
technique"
point of view, what of theese two is the preferred of the programmers
(please
don´t answer "pointers" ...lol).
Regards
André
-------------------------------------------------------
This SF.net email is sponsored by: eBay
Get office equipment for less on eBay!
http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
Thanx and Regards
Avik Ghose
Catch all the cricket action. Download Yahoo! Score tracker |