c-preprocessor

Macro definition error in C?

五迷三道 提交于 2019-12-02 00:49:21
问题 #define SOUND_SPEED 0.034; int rtt; //round trip time in microsecond double distance; distance = (double)(rtt*SOUND_SPEED)/2; It complains error: expected expression before '/' token. Was is it bacause I can't use macro to define decimals or what? 回答1: Drop the semicolon: #define SOUND_SPEED 0.034; ^ If you keep it the generated code will look like this: distance = (double)(rtt*SOUND_SPEED;)/2; ^ 回答2: #define SOUND_SPEED 0.034; ^ Do not use the trailing ; Actually you should never terminate a

What does ## mean in the #define directive in the code here

笑着哭i 提交于 2019-12-02 00:48:39
Please tell me the answer with explanation: #define f(g,h) g##h main(){ printf("%d",f(100,10)); } ## is used to concatenate whatever is before the ## with whatever is after it. It is used for concatenation. You can check the reference for details A ## operator between any two successive identifiers in the replacement-list runs parameter replacement on the two identifiers (which are not macro-expanded first) and then concatenates the result. This operation is called "concatenation" or "token pasting". 来源: https://stackoverflow.com/questions/29577775/what-does-mean-in-the-define-directive-in-the

How do I turn off the gcc preprocessor on linux?

早过忘川 提交于 2019-12-02 00:08:29
问题 I have googled turning off the gcc preprocessor on linux for a good while now (using that exact phrase) and everything has been irrelevant. For example I want to turn off everything except the preprocessor (the opposite of what I want) or pressurising warnings. Does anyone know of a way to disable the preprocessor? I found one that Facebook developed and claimed is faster, and I would like to test it out. 回答1: I tested what lornix said in a comment, and it works: Name the other/newer

Macro definition error in C?

╄→гoц情女王★ 提交于 2019-12-02 00:01:18
#define SOUND_SPEED 0.034; int rtt; //round trip time in microsecond double distance; distance = (double)(rtt*SOUND_SPEED)/2; It complains error: expected expression before '/' token. Was is it bacause I can't use macro to define decimals or what? Drop the semicolon: #define SOUND_SPEED 0.034; ^ If you keep it the generated code will look like this: distance = (double)(rtt*SOUND_SPEED;)/2; ^ #define SOUND_SPEED 0.034; ^ Do not use the trailing ; Actually you should never terminate a macro with a ; : PRE11-C. Do not conclude macro definitions with a semicolon https://www.securecoding.cert.org

Confusing MACRO and enum definition

血红的双手。 提交于 2019-12-01 23:21:54
问题 I was browsing some Route netlink source code. I wanted to figure out what was the value of RTNLGRP_NEIGH Source: http://lxr.free-electrons.com/source/include/linux/rtnetlink.h?v=2.6.35#L550 541 /* RTnetlink multicast groups */ 542 enum rtnetlink_groups { 543 RTNLGRP_NONE, 544 #define RTNLGRP_NONE RTNLGRP_NONE 545 RTNLGRP_LINK, 546 #define RTNLGRP_LINK RTNLGRP_LINK 547 RTNLGRP_NOTIFY, 548 #define RTNLGRP_NOTIFY RTNLGRP_NOTIFY 549 RTNLGRP_NEIGH, 550 #define RTNLGRP_NEIGH RTNLGRP_NEIGH 551

How do I turn off the gcc preprocessor on linux?

孤人 提交于 2019-12-01 22:43:24
I have googled turning off the gcc preprocessor on linux for a good while now (using that exact phrase) and everything has been irrelevant. For example I want to turn off everything except the preprocessor (the opposite of what I want) or pressurising warnings. Does anyone know of a way to disable the preprocessor? I found one that Facebook developed and claimed is faster, and I would like to test it out. I tested what lornix said in a comment, and it works: Name the other/newer preprocessor "cpp" and put it in your path, and rename the original cpp to cpp-other or cpp-orig. It'll work great

Macros as arguments to preprocessor directives

旧街凉风 提交于 2019-12-01 22:40:42
Being faced with the question whether it's possible to choose #include s in the preprocessor I immediately thought not possible . .. Only to later find out that it is indeed possible and you only need to watch out for argument expansions (which e.g. Boost.Preprocessor can take care of). While I'd avoid actually doing that for includes if possible, I'd like to know why this works. At the moment I fail to get a useful understanding in the C++ or C standard. Are parameterized macros allowed for any preprocessor-directive? (except #define / #undef ) Can someone reference where this is allowed and

Statement in C++ macro

别来无恙 提交于 2019-12-01 22:37:46
问题 Reading chromium code, found helpful macro for handling EINTR errno of system calls on POSIX compliant systems. Here are the code(base/posix/eintr_wrapper.h): #define HANDLE_EINTR(x) ({ \ decltype(x) eintr_wrapper_result; \ do { \ eintr_wrapper_result = (x); \ } while (eintr_wrapper_result == -1 && errno == EINTR); \ eintr_wrapper_result; \ }) The question is what is the role of last statement in macro eintr_wrapper_result; ? If we use commas instead of semicolons - it will be clear - to

Wrapping #includes in #ifndef's - adds any value?

送分小仙女□ 提交于 2019-12-01 22:29:47
问题 I have inherited C /C++ code base, and in a number of .cpp files the #include directives are wrapped in #ifndef's with the headers internal single include #define . for example #ifndef _INC_WINDOWS #include <windows.h> #endif and windows.h looks like #ifndef _INC_WINDOWS #define _INC_WINDOWS ...header file stuff.... #endif // _INC_WINDOWS I assume this was done to speed up the compile/preprocess of the code. I think it's ugly and a premature optimisation, but as the project has a 5 minute

Run GCC preprocessor non-C files

风流意气都作罢 提交于 2019-12-01 22:29:16
I'm using a proprietary development environment that compiles code written in C , as well as the IEC 61131 languages. For the C compilation, it uses GCC 4.1.2 with these build options: -fPIC -O0 -g -nostartfiles -Wall -trigraphs -fno-asm The compilation is done by a program running on windows utilizing Cygwin. My issue is, IEC language preprocessor is not that useful (doesn't support #define at all) and I want to use macros! I don't see why the GCC preprocessor would really care what language it is processing (my target language is Structured Text), so I'm looking to see if anyone might know a