-3

How do I write a macro to do the following RESOURCEPATH(image, menu.png) and get the string "image/menu.png"

More advanced question: I would like to write a macro to do the above but output different strings depending on conditional def (#ifdef IOS, #elif ANDROID #endif), so if its on an iOS output to "image/menu.png", and if its on android automatically output to "assets/image/menu.png" (automatically appends "assets/" to the front), all in one single macro.

I hope I have explained my problem clearly, thanks guys

james bond
  • 31
  • 3
  • 1
    No, not a duplicate of that, that question doesn't involve any stringising. –  May 02 '14 at 12:54

1 Answers1

3
#ifdef IOS
#  define RESOURCEPATH(DIR, FILE) #DIR "/" #FILE
#else
#  define RESOURCEPATH(DIR, FILE) "assets/" #DIR "/" #FILE
#endif

The idea is to stringize the two arguments, so image becomes "image", and then rely on the automatic concatenation of C string literals to insert the slash.

John Zwinck
  • 239,568
  • 38
  • 324
  • 436