1

I have

#define STRING "string"

I want to add L prefix to STRING macro later in my code (I can't do it in definition). How to do it?

alk
  • 69,737
  • 10
  • 105
  • 255
gaminn
  • 13
  • 3

2 Answers2

5

This should do:

#include <stdio.h>


#define CONCATENATE(e1, e2) e1 ## e2
#define PREFIX_L(s) CONCATENATE(L, s)

#define STRING "string"

int main(void)
{
    printf("%ls\n", PREFIX_L(STRING));
}

These standard C pre-processor's concatenation capabilities are also covered by the documentation coming with GCC: https://gcc.gnu.org/onlinedocs/cpp/Concatenation.html

alk
  • 69,737
  • 10
  • 105
  • 255
0

This should work.

#define STRING(x) x"string"

char * l_pString = STRING("");
wchar_t * l_pWideString = STRING(L);
Iverelo
  • 146
  • 1
  • 8