c-preprocessor

Does the C preprocessor remove instances of “&*”?

空扰寡人 提交于 2019-12-03 14:42:47
问题 I was playing around with gcc and tried the following bit of code: int A = 42; int *B = &A; int *C = &*B; And C == &A , as expected. But when I try: int *B = NULL; int *C = &*B; Turns out C == NULL , and no segfault. So &*B is not actually dereferencing B before taking its address. My guess is that the preprocessor is stripping out instances of &* and *& before they even get to the compiler since they negate each other, but I can't find any documentation to verify whether this is standard C

Abstruse #define macro encountered in Linux kernel source

雨燕双飞 提交于 2019-12-03 13:25:28
问题 The get_cpu_var marcro which is defined as below 29 #define get_cpu_var(var) (*({ \ 30 extern int simple_identifier_##var(void); \ 31 preempt_disable(); \ 32 &__get_cpu_var(var); })) seems incomprehensible to be.I am supposing it was one kind of function macro which return a variable pointer(based on the asterisk) or is it some kind of function pointer.Am I even close to it?Could anyone enlighten me? 回答1: What you see between the opening ({ and closing }) is a statement expression - a non

Size of #define values

旧城冷巷雨未停 提交于 2019-12-03 12:16:21
If a value is defined as #define M_40 40 Is the size the same as a short (2 bytes) or is it as a char (1 byte) or int (4 bytes)? Is the size dependent on whether you are 32-bit or 64-bit? #define has no size as it's not a type but a plain text substitution into your C++ code. #define is a preprocessing directive and it runs before your code even begins to be compiled . The size in C++ code after substitution is whatever the size is of what C++ expression or code you have there. For example if you suffix with L like 102L then it is seen a long, otherwise with no suffix, just an int. So 4 bytes

What are the differences between the C and C++ preprocessors? [duplicate]

久未见 提交于 2019-12-03 12:07:06
This question already has an answer here: Is a C++ preprocessor identical to a C preprocessor? 3 answers Are there any differences in behaviour between the C and C++ preprocessors? They are defined by different passages of standards text (section 6.10 of the C standard and section 16 of the C++ standard ). My motivation for asking this is that a proposal for making the single quote a digit separator that was recently accepted into C++14 extends the C++ preprocessor grammar to accomodate this change (specifically, it extends the definition of a pp-number ), and I'm wondering whether this

How to force Visual Studio preprocessor case sensitivity with #includes?

好久不见. 提交于 2019-12-03 11:49:54
If you have a header file named ThisIsAHeaderFile.h, the following will still locate the file in Visual Studio: #include <ThisIsAheaderFile.h> Is there a way to enforce case sensitivity so that the #include will result in an error? You can't, because the Windows file system is itself case-insensitive. If you could get into a situation where you had both RICHIE.h and richie.h, it might make sense to control case sensitivity, but you can't. It is (used to be?) possible to create files with the same name but case differences on NTFS. Maybe someone with cygwin can verify this. MSDN Even then,

Do I need to #undef a local #define? Is there such a thing as a local define?

邮差的信 提交于 2019-12-03 11:44:54
问题 Sometimes to make things easier to write and read, I write some local #define macros within functions (for example, #define O_REAL Ogre::Real) . Do I need to #undef the local #define to ensure that it stays within a certain block of code? Or does it automatically #undef when it goes out of scope ? Does it even have a concept of scope ? I am unsure on how #define works in this case. Now, I have of course experimented with the code and reached certain conclusions but since I am unsure, I would

Is it possible to use a if statement inside #define?

亡梦爱人 提交于 2019-12-03 11:43:23
问题 I'm trying to make a macro with the following formula: (a^2/(a+b))*b , and I want to make sure that the there will be no dividing by zero. #define SUM_A( x, y ) if( x == 0 || y == 0) { 0 } else { ( ( ( x * x ) / ( ( x ) + ( y ) ) ) * ( y ) )} and then I call the macro inside main: float a = 40, b = 10, result; result = SUM_A(a, b); printf("%f", result); I've tried using brackets around the if function but I keep getting syntax errors before the if statement. I've also tried using return, but

Run a “light” preprocessor for GCC

徘徊边缘 提交于 2019-12-03 11:42:05
Is there a way to run the GCC preprocessor, but only for user-defined macros? I have a few one-liners and some #ifdef , etc. conditionals, and I want to see what my code looks like when just those are expanded. As it is, the includes get expanded, my fprintf(stderr) s turn into fprintf(((__getreeent())->_stderr) , etc. Call cpp directly, e.g. $ cat >foo.c <<EOF #define FOO #ifdef FOO foo is defined #else foo is not defined #endif EOF $ cpp foo.c # 1 "foo.c" # 1 "<built-in>" # 1 "<command-line>" # 1 "foo.c" foo is defined Of course, if you include any headers then those will be included in the

iOS Writing Macro detect 3.5 inch or 4 inch display [duplicate]

Deadly 提交于 2019-12-03 11:36:01
问题 This question already has answers here : How to detect iPhone 5 (widescreen devices)? (24 answers) Closed 6 years ago . I am trying to write a macro to determine the device is 3.5 inch or 4 inch. Some thing similar below. #define IOS_OLDER_THAN_6 ( [ [ [ UIDevice currentDevice ] systemVersion ] floatValue ] < 6.0 ) #define IOS_NEWER_OR_EQUAL_TO_6 ( [ [ [ UIDevice currentDevice ] systemVersion ] floatValue ] >= 6.0 ) Can someone help me. Please 回答1: you can detect iphopne 3.5 inch or 4 inch

Does gcc define anything when -g is specified?

拟墨画扇 提交于 2019-12-03 11:27:04
问题 Shortly, I want to know if gcc (or g++. I need it in C , but also am curious about c++) defines any special symbols if -g is enabled. Does it? If so, what symbols? In the search process I found out that: _DEBUG is defined manually (by manually I mean -D_DEBUG ) and is a habit taken from Visual C programmers (because VC defines _DEBUG when compiling in debug mode) NDEBUG is defined if NOT in debug mode. Although I found a few places saying this, I tried with my gcc and g++ in .c and .cpp files