Thread: Defining macros with respect to the source file that calls it

  1. #1
    Registered User
    Join Date
    May 2014
    Posts
    1

    Defining macros with respect to the source file that calls it

    Hi,


    I am using a macro(debug_macro) for logging debug info that is defined in log.h file. I need to map this debug_macro to process specific debug macros. I have explained my expectations in the below example.


    log.h
    =======
    #if callee==process1
    #define debug_macro proc1_debug_macro
    #if callee==process2
    #define debug_macro proc2_debug_macro


    process1.c
    ===========
    #include log.h
    debug_macro <<<<<====== this one should call proc1debug_macro


    process2.c
    ===========
    #include log.h
    debug_macro <<<<==== this one should call proc2_debug_macro


    I am newbie to C programming.Please provide me any suggessions on how to implement this ? Any help would be much appreciated.


    Thanks,

  2. #2
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    O_o

    Put a flag on the command line to select the definition?

    I'm not really sure why you want a "per process" definition in a single header. Why not just define the same name for different applications?

    Soma
    “Salem Was Wrong!” -- Pedant Necromancer
    “Four isn't random!” -- Gibbering Mouther

  3. #3
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    What is the difference between proc1_debug_macro and proc2_debug_macro?

    gg

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,665
    Why not put into your macro something to print the result of getpid(), or whatever other API you have to distinguish separate running instances of your code.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    My preference would be to have a non-macro logging API - with an init function to set process specific stuff. Then use macro's to include __FILE__, __LINE__, and that sort of stuff when calling the log api.

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Header File Macros
    By psukphranee in forum C Programming
    Replies: 3
    Last Post: 06-17-2013, 11:26 PM
  2. defining macros or static variables
    By l2u in forum C++ Programming
    Replies: 15
    Last Post: 08-05-2008, 06:28 AM
  3. Defining File Paths
    By CV3 in forum C++ Programming
    Replies: 4
    Last Post: 10-05-2004, 02:02 PM
  4. Multi file source to single file source
    By anonytmouse in forum Tech Board
    Replies: 4
    Last Post: 12-07-2003, 08:47 AM
  5. Please respect your direct superior
    By Series X4 1.0 in forum A Brief History of Cprogramming.com
    Replies: 61
    Last Post: 10-25-2001, 04:27 PM