0

I need an ability to create some string identifiers from inside the local scope of C functions, which will be placed by a linker to some not loadable section, or to a dedicated section that I could strip out without causing any failure to my program.

I have tried #pragma ident “string” or #ident “string”, both do the work, but my “string” parameter is generated by a macro and in fact after expansion it looks like #pragma ident “string1” “string2” and therefore only “string1” is being dumped into .comment section.

So what I need is a way to concatenate strings in pre-processing time to make it look like #pragma ident “string1 string2” or some other approach to preserve unreferenced strings in a dedicated section without generating extra code.

pigeek
  • 67
  • 9
  • You can't use curly quotes in C code, they need to be `"`. Anyway, it sounds like you need to use the `##` string concatenation operator. See http://stackoverflow.com/questions/216875/in-macros – Barmar Mar 07 '15 at 01:59
  • 1
    ## - doesn't concatenate strings, it concatenate parameters of a macro. "string1"##"string2" will cause a failure of pre-processor. – pigeek Mar 07 '15 at 02:03
  • You said you need a way to concatenate strings in pre-processing time. – Barmar Mar 07 '15 at 02:03
  • Correct, but at least one parameter of my macro will be inside quotes from the beginning, say CONCAT("string1", 5) – pigeek Mar 07 '15 at 02:08
  • 1
    @pigeek: Is that unavoidable? Could you make it unquoted and stringify it when you need it quoted? Otherwise, I can't see any solution, although I don't want to say that it's impossible. – rici Mar 07 '15 at 02:24
  • Please show more code, so we can see how you're trying to use this. – Barmar Mar 07 '15 at 13:08

0 Answers0