stringification

Stringify Endpoint for Xcode LLVM Processor Macros

蹲街弑〆低调 提交于 2020-01-06 14:35:51
问题 In the "Apple LLVM 7.0 - Preprocessing" section under the "Build Settings" tab, I've defined a Preprocessor Macros as: STR(arg)=#arg HUBNAME=STR("myhub") HUBLISTENACCESS=STR("Endpoint=sb://abc-xyz.servicebus.windows.net/;SharedAccessKeyName=DefaultListenSharedAccessSignature;SharedAccessKey=JKLMNOP=") In my code, I'm trying to refer to the value of HUBLISTENACCESS as a string: SBNotificationHub* hub = [[SBNotificationHub alloc] initWithConnectionString:@HUBLISTENACCESS notificationHubPath:

How do you perform macro expansion within #ifdef?

喜你入骨 提交于 2020-01-03 11:29:42
问题 I have some fairly generic code which uses preprocessor macros to add a certain prefix onto other macros. This is a much simplified example of what happens: #define MY_VAR(x) prefix_##x "prefix_" is actually defined elsewhere, so it will be different each time the file is included. It works well, but now I have some code I would like to skip if one of the tokens doesn't exist, but this doesn't work: #if defined MY_VAR(hello) What I want it to expand to is this: #ifdef prefix_hello But I can't

How do you perform macro expansion within #ifdef?

白昼怎懂夜的黑 提交于 2020-01-03 11:29:32
问题 I have some fairly generic code which uses preprocessor macros to add a certain prefix onto other macros. This is a much simplified example of what happens: #define MY_VAR(x) prefix_##x "prefix_" is actually defined elsewhere, so it will be different each time the file is included. It works well, but now I have some code I would like to skip if one of the tokens doesn't exist, but this doesn't work: #if defined MY_VAR(hello) What I want it to expand to is this: #ifdef prefix_hello But I can't

Stringify macro with GNU gfortran

≡放荡痞女 提交于 2020-01-02 06:32:07
问题 How can I stringify a preprocessor macro with GNU gfortran? I would like to pass a macro definition to GNU gfortran which will then be used as a string in the code. Effectively I would like to do this: program test implicit none character (len=:), allocatable :: astring astring = MYMACRO write (*, *) astring end program test and then build with: gfortran -DMYMACRO=hello test.F90 I tried creating various macro, for example: #define STRINGIFY_(x) #x #define STRINGIFY(x) STRINGIFY_(x) ...

C Programming: Preprocessor, macros as tokens

橙三吉。 提交于 2019-12-24 02:06:09
问题 I'm trying to do something that is conceptually similar to this, but can't seem to get it to work (error shown at end) any ideas? #include <stdio.h> int main( int argc , char const *argv[] ) { int abc_def_ghi = 42; #define SUFFIX ghi #define VAR(prefix) prefix##_def_##SUFFIX printf( "%d\n" , VAR(abc) ); return 0; } // untitled:8: error: ‘abc_def_SUFFIX’ undeclared (first use in this function) 回答1: You just need additional indirection: #include <stdio.h> int main( int argc , char const *argv[]

JSONValue to Indented String

坚强是说给别人听的谎言 提交于 2019-12-24 01:55:07
问题 In Delphi XE2, I need to make a function that receives a JSONValue and returns an indented String , much like JSONLint. This JSONValue could be any type of JSON, could be an array, an object, even just a string, so I have to make sure to cover all types with this function. I have no idea where to start. 回答1: You'll have to do it recursively. Something like this: const INDENT_SIZE = 2; procedure PrettyPrintJSON(value: TJSONValue; output: TStrings; indent: integer = 0); forward; procedure

JSONValue to Indented String

喜你入骨 提交于 2019-12-24 01:55:03
问题 In Delphi XE2, I need to make a function that receives a JSONValue and returns an indented String , much like JSONLint. This JSONValue could be any type of JSON, could be an array, an object, even just a string, so I have to make sure to cover all types with this function. I have no idea where to start. 回答1: You'll have to do it recursively. Something like this: const INDENT_SIZE = 2; procedure PrettyPrintJSON(value: TJSONValue; output: TStrings; indent: integer = 0); forward; procedure

Stringify first level macro expansion C

瘦欲@ 提交于 2019-12-23 07:52:39
问题 Is it possible to stringify this C macro: #define GPIO_INT_PIN (GPIO_PORT_D|GPIO_PIN_IRQ_RISING|GPIO_PIN5) using something like MY_STRINGFY(GPIO_INT_PIN) to get "(GPIO_PORT_D|GPIO_PIN_IRQ_RISING|GPIO_PIN5)" ? 回答1: Yes it is possible. Read about stringizing in GCC cpp documentation. #define STRINGIFY(It) #It #define MY_STRINGIFY(It) STRINGIFY(It) I corrected my answer thanks to Wojtek Surowka's one then use MY_STRINGIFY(GPIO_PORT_D|GPIO_PIN_IRQ_RISING|GPIO_PIN5) which would work much better if

Token pasting in C

爱⌒轻易说出口 提交于 2019-12-22 05:15:21
问题 After reading about VA_NARG I tried to implement function overloading depending on number of arguments in C using macros. Now the problem is: void hello1(char *s) { ... } void hello2(char *s, char *t) { ... } // PP_NARG(...) macro returns number of arguments :ref to link above // does not work #define hello(...) hello ## PP_NARG(__VA_ARGS__) int main(void) { hello("hi"); // call hello1("hi"); hello("foo","bar"); // call hello2("foo","bar"); return 0; } I've read this from C-faq. But still

How to single-quote an argument in a macro?

依然范特西╮ 提交于 2019-12-18 04:42:42
问题 I would like to create a C pre-processor macro that will single-quote the argument. Just like the common used #X . I want Q(A) to be expanded to 'A' . I am using gcc on Linux. Does any one have an idea? I know # double-quotes. I am looking for a similar mechanism for single-quoting. 回答1: The best you can do is #define Q(x) ((#x)[0]) or #define SINGLEQUOTED_A 'A' #define SINGLEQUOTED_B 'B' ... #define SINGLEQUOTED_z 'z' #define Q(x) SINGLEQUOTED_##x This only works for a - z , A - Z , 0 - 9