qt-interest@trolltech.com
[Top] [All Lists]

RE: Global const in C++

Subject: RE: Global const in C++
From: Hadas Sandor
Date: Thu, 9 Nov 2006 12:43:56 +0100

I do not think that we will have a conclusion here. Preprocessor is part of the compiler, is not it?

#defines are especially handy if there is one value which needs to be compared to signed and unsigned variables for example. So, if you would like to avoid comparison between signed and unsigned warnings and still use the same "fixed value", you need to use defines. Otherwise you use two consts or one const and casting. I disagree if you say that for example (int)variable is a nicer way to do it that use a #define. So, this is how it becomes handy (do not tell me that it never happens, if you say so you never maintained a 25+ years old mixed C/C++ code for sure).

#define "hello"
can be std::string, char*, QString, CString, etc. You can have 4+ consts if you like to type.

And this is, again, religion.

Sandor



-----Original Message-----
From: qt-interest-request@xxxxxxxxxxxxx
[mailto:qt-interest-request@xxxxxxxxxxxxx]On Behalf Of Malte Witt
Sent: 09/11/2006 13:31
To: Qt Interest List
Subject: RE: Global const in C++


> S: You misunderstand. And yes, #defines (interpreted by compiler,
> even as char or long) are more handy than consts IMO. It seems like
> religion. :)

Not really ... #defines are handled by the preprocessor and they are
typeless => REALLY BAD!
To veryfiy your own code, _const_ is much better.
I cannot see why #defines should be more handy???

I think _#define_ is for people who learnd C and try to do stuff in C++.

_const_ if for people who like to do efficient and structured programming
in an OO-language ;-)

Regards,
Malte

--
To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
List archive and information: http://lists.trolltech.com/qt-interest/

<Prev in Thread] Current Thread [Next in Thread>