Thread: Is it ok to use #define 's ?

  1. #16
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Originally posted by FillYourBrain
    #define when used for values such as those to be used in a switch is great. I can't imagine that being bad form. For something like NULL,TRUE,FALSE it's perfect

    #define NULL 0
    #define TRUE 1
    #define FALSE 0

    No problems there. but will agree certainly that macros (code hidden behind #defines) is naughty.
    I usually use the following when defining true and false.

    Code:
    #define TRUE ( 5 == 5 )
    #define FALSE (!TRUE)
    That way, 5 == 5 is always true regardless of system. Just how I usually do it.

  2. #17
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    LOL
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  3. #18
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Originally posted by MrWizard
    I like using #define's for flags. Using bitwise operators it is very easy to test and set flags for specific purposes. I think this is pretty handy and not 'poor' code.
    But it's just as easy to declare those flags as const ints. The #define syntax is not needed at all.
    There are very few cases where it is needed, I can only think of one, namely this:
    Code:
    #define Assert(p) if (!(p)) std::cout << "Failed:" << #p << __LINE__ << __FILE__;
    Last edited by Sang-drax; 09-07-2002 at 05:08 AM.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  4. #19
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    use them but dont over use them becuase then you will learn you will have a hard time getting help on c++ becuase your not used to the standard comamnds that everyone uses. I only use defines for commands like fin (ifstream) and fout (ofstream) so I can easily look at it and say, oh fout is like cout. and when yuo would se fou is when you write to other files on the hard drive.
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointer within a Struct
    By Bladactania in forum C Programming
    Replies: 11
    Last Post: 04-03-2009, 10:20 PM
  2. Why?!?
    By p3rry in forum C Programming
    Replies: 3
    Last Post: 01-08-2009, 12:52 PM
  3. size of an integer pointer
    By onebrother in forum C Programming
    Replies: 5
    Last Post: 07-09-2008, 11:49 AM
  4. Please STICKY this- vital to MSVC 6 dev - BASETSD.h
    By VirtualAce in forum Game Programming
    Replies: 11
    Last Post: 03-15-2005, 09:22 AM
  5. float toolbar!
    By c-- in forum Windows Programming
    Replies: 5
    Last Post: 02-04-2003, 09:44 AM