c-preprocessor

Mono for Android preprocessor macros

夙愿已清 提交于 2019-12-04 08:08:53
Is there an Android preprocessor macros that Mono for Android defines? I mean very useful things for cross-platform development like: #if WINDOWS...#endif and #if WINDOWS_PHONE...#endif __ANDROID__ and additionally for each Android API Level: __ANDROID_4__;__ANDROID_7__;__ANDROID_8__;etc 来源: https://stackoverflow.com/questions/7917859/mono-for-android-preprocessor-macros

C block becomes expression: ( {int a = 1; int b = 2; a+b;} ) equals 3

人走茶凉 提交于 2019-12-04 08:05:48
While reading http://en.wikipedia.org/wiki/C_preprocessor#Multiple_evaluation_of_side_effects , I came across this example: \#define max(a,b) \ ({ typeof (a) _a = (a); \ typeof (b) _b = (b); \ _a > _b ? _a : _b; }) // WHY DOES THIS LINE WORK? Which you can use exactly like a function, i.e. max(1,2) is an expression evaluating to 2. My QUESTION is, How does ({ statment-list last-expression; }) construct evaluate to the value of last-expression? Specifically, what does a parse tree of this construct look like? I thought { } always meant a compound-statement, and statements have no values. I

How can I generate a list of #define values from C code?

爷,独闯天下 提交于 2019-12-04 07:57:53
I have code that has a lot of complicated #define error codes that are not easy to decode since they are nested through several levels. Is there any elegant way I can get a list of #defines with their final numerical values (or whatever else they may be)? As an example: <header1.h> #define CREATE_ERROR_CODE(class, sc, code) ((class << 16) & (sc << 8) & code) #define EMI_MAX 16 <header2.h> #define MI_1 EMI_MAX <header3.h> #define MODULE_ERROR_CLASS MI_1 #define MODULE_ERROR_SUBCLASS 1 #define ERROR_FOO CREATE_ERROR_CODE(MODULE_ERROR_CLASS, MODULE_ERROR_SUBCLASS, 1) I would have a large number

Partially processing a file with the preprocessor [duplicate]

99封情书 提交于 2019-12-04 07:51:16
This question already has an answer here: Is there a C pre-processor which eliminates #ifdef blocks based on values defined/undefined? 5 answers We have inherited a very convolved project (500kloc) with a lot of preprocessor conditional logic, most of which is no longer relevant, and I want to clean it up. Can I use the preprocessor¹ to expand only some of the conditional logic, and leave all other preprocessor macros, defines, and includes alone in the output? ¹ Here, by "the preprocessor", I really mean "any tool", either a standard C preprocessor, something I can install, or even a hacked

Macro without definition in C

假如想象 提交于 2019-12-04 07:37:13
What is the use/applicability of macro function without definition: #ifndef __SYSCALL #define __SYSCALL(a, b) #endif One can find this macro in Linux system in header file /usr/include/asm/msr.h I also notice macro of following kind. #define _M(x) x And only reason to defined this kind of macro that I can think to make code uniform. like in #define SOMETHING (1 << 0) . Is there any other hidden(better) use of this kind of macros? An answer with example will be very helpful. Also can someone provide me a text/link to read about this. One of the most common case of a macro of this form: #define

The most useful user-made C-macros (in GCC, also C99)? [closed]

删除回忆录丶 提交于 2019-12-04 07:31:34
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . What C macro is in your opinion is the most useful? I have found the following one, which I use to do vector arithmetic in C : #define

Detect presence or absence of arguments in a C macro

本秂侑毒 提交于 2019-12-04 07:21:18
How can one define a C macro IFARGS(YES, NO, ...) such that invoking IFARGS with no additional arguments produces NO , and invoking IFARGS with one or more arguments produces YES ? I have an answer using GCC (see below), but I'd prefer one for C99 if possible (or a proof of its impossibility). In C99 it is possible to detect if a macro argument is empty, but making that robust against all odds that may appear in that argument (arguments that are themselves expanding, contain () and stuff like that) is difficult. My macro package P99 implements such a thing, so you wouldn't have to worry too

Change member-typedef depending on template parameter?

耗尽温柔 提交于 2019-12-04 06:42:08
I have this problem here that I can’t figure out how to solve. I want a template class that takes an integer as template parameter and sets the template parameters for another class accordingly: template <int T> class Solver { public: #if T <= 24 typedef MyMatrix<float> Matrix; #else if T <= 53 typedef MyMatrix<double> Matrix; #else typedef MyMatrix<mpreal> Matrix; #endif Matrix create(); }; And then calling it like this: Solver<53>::Matrix m = Solver<53>::create(); How can I do something like this? At the moment with the code above, the compiler complaints that it doesn't know "Matrix", so I

#define vs. enums for addressing peripherals

末鹿安然 提交于 2019-12-04 06:24:37
I have to program peripheral registers in an ARM9-based microcontroller. For instance, for the USART, I store the relevant memory addresses in an enum : enum USART { US_BASE = (int) 0xFFFC4000, US_BRGR = US_BASE + 0x16, //... }; Then, I use pointers in a function to initialize the registers: void init_usart (void) { vuint* pBRGR = (vuint*) US_BRGR; *pBRGR = 0x030C; //... } But my teacher says I'd better use #define s, such as: #define US_BASE (0xFFFC4000) #define US_BRGR (US_BASE + 0x16) #define pBRGR ((vuint*) US_BRGR) void init_usart (void) { *pBRGR = 0x030C; } Like so, he says, you don't

Is there a way to apply an action to N C++ class members in a loop over member names (probably via pre-processor)?

ぐ巨炮叔叔 提交于 2019-12-04 06:00:01
The problem: I have a C++ class with gajillion (>100) members that behave nearly identically: same type in a function, each member has the same exact code done to it as other members, e.g. assignment from a map in a constructor where map key is same as member key This identicality of behavior is repeated across many-many functions (>20), of course the behavior in each function is different so there's no way to factor things out. The list of members is very fluid, with constant additions and sometimes deletions, some ( but not all ) driven by changing columns in a DB table. As you can imagine,