Thread: defines take up less space

  1. #1
    I am he who is the man! Stan100's Avatar
    Join Date
    Sep 2002
    Posts
    361

    defines take up less space

    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)

  2. #2
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    The compiler goes through and replaces occurances of a const int with the actual number, doesn't it?
    Away.

  3. #3
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    >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.

  4. #4
    I always use defines. I've never used const variables except in parameters for functions and API's forcing me to.

  5. #5
    Registered User
    Join Date
    May 2003
    Posts
    1,619

    Re: defines take up less space

    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?
    Unless you take the address of the const int, any good compiler will optimize it away unless you have all optimizations off.

    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.

  6. #6
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,743
    define = good

    const = used for other things
    My Website

    "Circular logic is good because it is."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Out of space when compiling kernel
    By NuNn in forum Linux Programming
    Replies: 3
    Last Post: 04-01-2009, 02:43 PM
  2. disk space mysteriously gone
    By evader in forum C++ Programming
    Replies: 4
    Last Post: 01-21-2004, 01:30 PM
  3. Replies: 12
    Last Post: 05-17-2003, 05:58 AM
  4. someone who is good at finding and fixing bugs?
    By elfjuice in forum C++ Programming
    Replies: 8
    Last Post: 06-07-2002, 03:59 PM