c-preprocessor

How do I check OS with a preprocessor directive?

岁酱吖の 提交于 2020-01-08 09:31:31
问题 I need my code to do different things based on the operating system on which it gets compiled. I'm looking for something like this: #ifdef OSisWindows // do Windows-specific stuff #else // do Unix-specific stuff #endif Is there a way to do this? Is there a better way to do the same thing? 回答1: The Predefined Macros for OS site has a very complete list of checks. Here are a few of them, with links to where they're found: Windows _WIN32 Both 32 bit and 64 bit _WIN64 64 bit only Unix (Linux,

How do I check OS with a preprocessor directive?

笑着哭i 提交于 2020-01-08 09:31:11
问题 I need my code to do different things based on the operating system on which it gets compiled. I'm looking for something like this: #ifdef OSisWindows // do Windows-specific stuff #else // do Unix-specific stuff #endif Is there a way to do this? Is there a better way to do the same thing? 回答1: The Predefined Macros for OS site has a very complete list of checks. Here are a few of them, with links to where they're found: Windows _WIN32 Both 32 bit and 64 bit _WIN64 64 bit only Unix (Linux,

Accessing C macros in Swift

萝らか妹 提交于 2020-01-07 09:34:08
问题 I have a third party C library exporting lots of preprocessor macros with arguments. Problem is when I try to access them in Swift it fails with: Unable to resolve the symbol. What is the way to access such C macros, exported by third party libraries, in Swift? I do not want to workaround by directly calling functions with name starting with __ and make my code look ugly nor do want to edit/hack third party library. 回答1: There is no easy answer. The aforementioned Apple documentation states

Accessing C macros in Swift

≯℡__Kan透↙ 提交于 2020-01-07 09:33:41
问题 I have a third party C library exporting lots of preprocessor macros with arguments. Problem is when I try to access them in Swift it fails with: Unable to resolve the symbol. What is the way to access such C macros, exported by third party libraries, in Swift? I do not want to workaround by directly calling functions with name starting with __ and make my code look ugly nor do want to edit/hack third party library. 回答1: There is no easy answer. The aforementioned Apple documentation states

Accessing C macros in Swift

好久不见. 提交于 2020-01-07 09:33:27
问题 I have a third party C library exporting lots of preprocessor macros with arguments. Problem is when I try to access them in Swift it fails with: Unable to resolve the symbol. What is the way to access such C macros, exported by third party libraries, in Swift? I do not want to workaround by directly calling functions with name starting with __ and make my code look ugly nor do want to edit/hack third party library. 回答1: There is no easy answer. The aforementioned Apple documentation states

concat code with macro in C

风流意气都作罢 提交于 2020-01-07 07:42:48
问题 Here's the thing: Let's say I have two function defined in C: test_1() {}; test_2() {}; I would like to have a macro (e.g. NUM_TEST) that will refer to test number. Best way is to show it in code: #define NUM_TEST 1 test_1() {}; test_2() {}; int main() { test_ ## NUM_TEST ## () } I would appreciate, if someone would help, to find a solution, how to concat name of function with macro. EDIT: To make it more clear. I would like to just by changing of "macro NUM_TEST" change invoked function

#define vs const and linking against frameworks

こ雲淡風輕ζ 提交于 2020-01-07 06:15:27
问题 I have a really small lightweight application which needs to use some constants that are stored in a larger framework. I don't want to duplicate these constants and hardcode them into the lightweight application but I also don't want to have to link against the large framework to just get the constants. The constants are defined using static NSString *const in a header file. Does replacing the static NSString *const with #define prevent me from having to link against the whole framework ? To

#define vs const and linking against frameworks

[亡魂溺海] 提交于 2020-01-07 06:15:03
问题 I have a really small lightweight application which needs to use some constants that are stored in a larger framework. I don't want to duplicate these constants and hardcode them into the lightweight application but I also don't want to have to link against the large framework to just get the constants. The constants are defined using static NSString *const in a header file. Does replacing the static NSString *const with #define prevent me from having to link against the whole framework ? To

Preprocessor: missing binary operator before token

孤者浪人 提交于 2020-01-07 00:36:28
问题 I'm trying to set up the USART module in an XMEGA micro controller and stumble over an error I can not find. For clarity I give you the complete code. So nothing in this header file is missing. ( F_CPU is defined in the main file) #ifndef USART_H_ #define USART_H_ #include <avr/io.h> #define USART_BAUDRATE 4800 #define USART_BSCALE -3 #if USART_BSCALE < 0 #define USART_BSEL F_CPU / (pow(2,USART_BSCALE) * 16 * USART_BAUDRATE) - 1 #define USART_BAUD_REAL F_CPU / (pow(2,USART_BSCALE) * 16 *

Preprocessor: missing binary operator before token

喜欢而已 提交于 2020-01-07 00:35:10
问题 I'm trying to set up the USART module in an XMEGA micro controller and stumble over an error I can not find. For clarity I give you the complete code. So nothing in this header file is missing. ( F_CPU is defined in the main file) #ifndef USART_H_ #define USART_H_ #include <avr/io.h> #define USART_BAUDRATE 4800 #define USART_BSCALE -3 #if USART_BSCALE < 0 #define USART_BSEL F_CPU / (pow(2,USART_BSCALE) * 16 * USART_BAUDRATE) - 1 #define USART_BAUD_REAL F_CPU / (pow(2,USART_BSCALE) * 16 *