c-preprocessor

#define with space

爷,独闯天下 提交于 2019-12-18 19:09:14
问题 Is it possible to write define with spaces such as: #define replace to replacement here I want to replace " replace to " with " replacement here ". EDIT: I want to test private members: I did write #define private public but it didn't work for private slots in Qt so my intend was to use something like #define private slots: public slots: anyway I have found another way to test slots and by the way I'm aware of that this is an ugly hack. 回答1: no, you can't #define identifier something what you

C++ Template preprocessor tool

邮差的信 提交于 2019-12-18 16:57:06
问题 Is there a compiler or standalone preprocessor which takes C++ files and runs a template expansion pass, generating new C++ code with expanded template instantiations? I remember such a tool in the mid-90s when templates were still new and experimental, and the preprocessor was a way to do template programming with compilers without native template support. This is a lot more complicated than a macro-processing step since it would likely require parsing and tokenizing the code to understand

Can I append to a preprocessor macro?

↘锁芯ラ 提交于 2019-12-18 16:07:32
问题 Is there any way in standard C—or with GNU extensions—to append stuff to a macro definition? E.g. , given a macro defined as #define List foo bar can I append bas so that it List expands as if I’d defined it #define List foo bar bas ? I was hoping I could do something like this: #define List foo bar bas #define List_ Expand(List) #undef List #define List Expand(List_) quux but I can’t figure out how to define the Expand() macro so it’ll do what I want. Motivation: I’m playing with

Difference between preprocessor directive #if and normal if

删除回忆录丶 提交于 2019-12-18 14:05:43
问题 What is difference between preprocessor directive #if and normal if in C ? I'm new to C . 回答1: Statements with # in front of them are called preprocessor directives. They are processed by a parser before the code is actually compiled. From the first search hit using Google (http://www.cplusplus.com/doc/tutorial/preprocessor/): Preprocessor directives are lines included in the code of our programs that are not program statements but directives for the preprocessor. These lines are always

What do the numbers mean in the preprocessed .i files when compiling C with gcc?

99封情书 提交于 2019-12-18 13:59:35
问题 I am trying to understand the compiling process. We can see the preprocessor intermediate file by using: gcc -E hello.c -o hello.i or cpp hello.c > hello.i I roughly know what the preprocessor does, but I have difficulties understanding the numbers in some of the lines. For example: # 1 "/usr/include/stdc-predef.h" 1 3 4 # 1 "<command-line>" 2 # 1 "hello.c" # 1 "/usr/include/stdio.h" 1 3 4 # 27 "/usr/include/stdio.h" 3 4 # 1 "/usr/include/features.h" 1 3 4 # 374 "/usr/include/features.h" 3 4

List of #pragma warning disable codes and what they mean

别说谁变了你拦得住时间么 提交于 2019-12-18 13:58:45
问题 The syntax for disabling warnings is as follows: #pragma warning disable 414, 3021 Or, expressed more generally: #pragma warning disable [CSV list of numeric codes] Is there a list of these numeric codes and the description of the warning that they're suppressing? Much to my chagrin, I can't seem to locate it via Google. 回答1: You shouldn't need a list. The compiler will tell you. If you get a compiler error that says "warning CS0168", then add 168 to the list (or, better yet, fix the code).

How do I setup visual studio to register some #defines globally?

别来无恙 提交于 2019-12-18 12:45:45
问题 What I mean is, in each of my source files I have to insert #define NOGDI to stop windows.h from including GDI defines (since it's BITMAP define conflicts with mine). e.g. #define NOGDI #include <windows.h> Unfortunately, I have to do this in every seperate source file which includes windows.h, which I do not want to do. I am using Visual Studio 2005, is there any way I can set it to #define something globally? (i.e. in all of the source files). 回答1: Project Settings -> C/C++ -> Preprocessor

What is the point of saying “#define FOO FOO” in C?

好久不见. 提交于 2019-12-18 12:21:30
问题 I came across some C code where the author uses the following idiom all over the place: typedef __int32 FOO_INT32; #define FOO_INT32 FOO_INT32 What is the point of doing this? Shouldn't the typedef be enough? It is a workaround for some wonky C compilers out there? 回答1: With the #define instruction, you'll then be able to test if the typedef has been done somewhere else in the code using : #ifdef FOO_INT32 FOO_INT32 myfoo; #else int myfoo; #endif 回答2: It's a practice that's sometimes done in

How to remove the enclosing parentheses with macro?

旧城冷巷雨未停 提交于 2019-12-18 12:18:50
问题 No comma is allowed in a macro argument because it will be treated as more than one arguments and the preprocessing will be wrong. However, we can parenthesize the argument to let preprocessor treat it as one argument. Is there a macro or other techniques which can remove the enclosing parentheses? For example, if I define a macro like #define MY_MACRO(a, b) ... and use it like MY_MACRO( A<int, double>, text ); will be wrong. use it like MY_MACRO( (A<int, double>), text) with a macro or

Passing array literal as macro argument

浪子不回头ぞ 提交于 2019-12-18 12:18:49
问题 This has been bugging me for some time, for example, if I'm trying to write this code: // find the length of an array #define ARRAY_LENGTH(arr) (sizeof(arr)/sizeof(int)) // declare an array together with a variable containing the array's length #define ARRAY(name, arr) int name[] = arr; size_t name##_length = ARRAY_LENGTH(name); int main() { ARRAY(myarr, {1, 2, 3}); } The code gives this error: <stdin>:8:31: error: macro "ARRAY" passed 4 arguments, but takes just 2 Because it sees ARRAY(myarr