Thread: Using #define's in C++. Your opinion...

  1. #1
    Registered User biosx's Avatar
    Join Date
    Aug 2001

    Using #define's in C++. Your opinion...

    I have recently come across a situation where it will be beneficial to use a #define macro inside my code. This addition will make the code much easier to understand and a little easier to edit later.

    The problem is that the #define's are considered legacy and are supposed to be replaced with inline functions, const variables and the like. These serve no use for me in my current situation. So the question is..

    What are everybody's opinions on using the legacy macro definition inside C++ code?

  2. #2
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Post a quick example of the macro. You're most likely best off using inline functions with templating, but it all depends on what you are using the macro for.

  3. #3
    Registered User biosx's Avatar
    Join Date
    Aug 2001
    Well it seems silly. I probably won't use it in the long run (just for the time being). I have a function that takes 6 arguments and I #define a small macro for expanding a ton of arguments. Here is an example (not actually from my program):

    #define SETA(x) 2, 4, 3, 5, x, 7
    #define SETB(x) 7, 2, 3, 5, x, 9
    #define SETC(x) 10, 2, 1, 6, x, 0
    int func(int i1, int i2, int i3, int i4, int i5, int i6);
    int someotherfunc(int iVar)
        func( SETA(iVar) );
        func( SETB(iVar) );
        func( SETC(iVar) );
    So I'm basically just taking advantage of the expansion capability of the macros.

  4. #4
    Registered User biosx's Avatar
    Join Date
    Aug 2001
    Well I do use them in different places, however I think later on in the development of this I am going to have some other way of dealing with it.

    I just wanted to know what people's opinion's were on the idea of, like vVv said, violating "good C++ style".

  5. #5
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Heard about default values? Seems like they could help here to me.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :-

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. defines take up less space
    By Stan100 in forum Game Programming
    Replies: 5
    Last Post: 10-21-2003, 01:42 AM
  2. Her opinion, your opinion
    By RoD in forum C++ Programming
    Replies: 4
    Last Post: 12-22-2002, 10:50 AM
  3. A matter of opinion
    By pepperblue255 in forum C++ Programming
    Replies: 2
    Last Post: 10-05-2002, 09:51 PM
  4. Freedom of opinion
    By Shiro in forum A Brief History of
    Replies: 1
    Last Post: 02-10-2002, 07:06 AM
  5. opinion about books
    By clement in forum C Programming
    Replies: 7
    Last Post: 09-24-2001, 04:18 PM