C Preprocessor woes

Discussion in 'Mac Programming' started by Madd the Sane, Nov 17, 2011.

  1. Madd the Sane macrumors 6502

    Madd the Sane

    Joined:
    Nov 8, 2010
    Location:
    Utah
    #1
    This is what I'm trying to do: I want to set a function name based on a preprocessor definition. This is my current code:
    Code:
    #define PLUGLOC PCSXRPLUG ## _locale_text
    extern char* PLUGLOC(char* toloc);
    
    I want PLUGLOC to be defined based on the preprocessor definition PCSXRPLUG, set at the command line. But what I'm getting is PCSXRPLUG_locale_text regardless of what PCSXRPLUG is. If I'm doing it wrong, how do I do it right?
     
  2. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #2
    You have to go through couple of levels of indirection to get PCSXRPLUG to be expanded and not used literally.

    Code:
    #define PLUGLOC_x(x,y) x ## y
    #define PLUGLOC_y(x,y) PLUGLOC_x(x,y)
    #define PLUGLOC PLUGLOC_y(PCSXRPLUG,_locale_text)
    
     

Share This Page