I was choosing whether or not to use defines or const ints, and I have reached a crossroad: Don't const ints take up space? Sure the size is un-noticeable, but still. Do people not use defines as much just because it isn't standard?
I was choosing whether or not to use defines or const ints, and I have reached a crossroad: Don't const ints take up space? Sure the size is un-noticeable, but still. Do people not use defines as much just because it isn't standard?
Stan The Man. Beatles fan
When I was a child,
I spoke as a child,
I thought as a child,
I reasoned as a child.
When I became a man,
I put childish ways behind me"
(the holy bible, Paul, in his first letter to the Cor. 13:11)
The compiler goes through and replaces occurances of a const int with the actual number, doesn't it?
Away.
>Do people not use defines as much just because it isn't standard?
defines are stanfdard.
>The compiler goes through and replaces occurances of a const int with the actual number, doesn't it?
if im not mistaken this is not guaranteed behavior and is dependant on the compiler, and how smart it is.
ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.
I always use defines. I've never used const variables except in parameters for functions and API's forcing me to.
Unless you take the address of the const int, any good compiler will optimize it away unless you have all optimizations off.Originally posted by Stan100
I was choosing whether or not to use defines or const ints, and I have reached a crossroad: Don't const ints take up space? Sure the size is un-noticeable, but still. Do people not use defines as much just because it isn't standard?
People don't like #define because #define completely ignores any and all scope rules. A const int obeys all the usual laws of scope; a #define obeys none of them. It's thus easy for a #define to shoot your code to hell very quickly. A #define cannot be confined to one class, one function, or one namespace. A const int can. A #define will happily puke anywhere in the code that it can, including other namespaces, etc. You can use a #define and accidently break code that exists in a library far, far away.
Thus, you should ONLY use #defines when they are absolutely needed -- #defines can do things that const ints cannot (example, they can be used for conditional compilation of various sections of code).
Last edited by Cat; 10-20-2003 at 10:59 PM.
You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.
define = good
const = used for other things