macros

This is a discussion on macros within the C Programming forums, part of the General Programming Boards category; Hi all, A quick question on macros. I dont think we came have a same macro defined twice with the ...

  1. #1
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682

    macros

    Hi all,

    A quick question on macros. I dont think we came have a same macro defined twice with the an argument different between them. Like for example

    Code:
    #define DBG( FunPtr, MSG ) dbg(FunPtr, __FUNCTION__, MSG )
    #define DBGvARG( FunPtr, MSG, ARG ) dbg(FunPtr, __FUNCTION__, MSG, ARG )
    As you could see, if had to define with two different identifiers. It would be good to have a same name and the compiler to decide which one to resolve. Like function overloading in C++.

    Something like follow
    Code:
    #define DBG( FunPtr, MSG ) dbg(FunPtr, __FUNCTION__, MSG )
    #define DBG( FunPtr, MSG, ARG ) dbg(FunPtr, __FUNCTION__, MSG, ARG )
    Is it possible in C?

    Thanks guys!

    Regards,
    ~ssharish
    Life is like riding a bicycle. To keep your balance you must keep moving - Einstein

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    Is it possible in C?
    Nope, can't overload macros. You can make macros that take a variable number of arguments though.
    bit∙hub [bit-huhb] n. A source and destination for information.

  3. #3
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    Quote Originally Posted by bithub View Post
    Nope, can't overload macros. You can make macros that take a variable number of arguments though.

    ooo cool! how would you do that?
    I guess that would solve my problem tho :P

    ~ssharish
    Life is like riding a bicycle. To keep your balance you must keep moving - Einstein

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    Read this page for the different ways of doing it.
    bit∙hub [bit-huhb] n. A source and destination for information.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. loops and macros
    By ginom71 in forum C Programming
    Replies: 13
    Last Post: 07-18-2009, 02:04 PM
  2. Order of execution of preprocessor macros
    By DL1 in forum C Programming
    Replies: 2
    Last Post: 04-02-2009, 07:52 PM
  3. function definition with macros
    By toshog in forum C++ Programming
    Replies: 2
    Last Post: 03-08-2009, 10:22 PM
  4. Macros inside of macros
    By Chewie8 in forum C Programming
    Replies: 2
    Last Post: 02-24-2008, 03:51 AM
  5. Question on predefine macros
    By Kaminaga in forum C++ Programming
    Replies: 6
    Last Post: 08-07-2005, 01:03 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21