RE: [Dev-C++] #DEFINE versus cont variables in array inicializations
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ioannis V. <iv...@te...> - 2003-05-29 18:17:14
|
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...] On Behalf Of Avik Ghose
Sent: Thursday, May 29, 2003 8:30 PM
To: Andr?_Macario_Barros; Dev-Cpp-Users
Subject: Re: [Dev-C++] #DEFINE versus cont variables in array
inicializations
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.
There is still a 3rd way that guarantees that no size is occupied but i
shall post it in a separate email after this.
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.
It is standard C++.
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.
I am bored to check the C standard, bu in C++ that is not allowed (g++, not
gcc).
Ioannis Vranos
* Programming pages: http://www.noicys.freeurl.com
<http://www.noicys.freeurl.com/>
* Alternative URL 1: http://run.to/noicys
* Alternative URL 2: http://www.noicys.cjb.net <http://www.noicys.cjb.net/>
|