c-preprocessor

Expected unqualified-id before numeric constant for defining a number

自古美人都是妖i 提交于 2019-12-09 07:43:26
问题 I'm new to C++, so I don't know what they mean with this error in a phidget-code example: Main.cpp:8:16: error: expected unqualified-id before numeric constant //verander de volgende informatie naar de informatie voor jouw database #define dserver "oege.ie.hva.nl" #define duser "username" #define dpassword "password" #define ddatabase "databasename" #define homeid 1234 //line 8 Is there a syntax error? Or something else? I use #define instead of int. EDIT: added full error log.. complete

algorithm behind the generation of the reverse bits lookup table(8 bit)

牧云@^-^@ 提交于 2019-12-09 04:28:00
问题 I found the lookup table here. The table is generated as a reverse bits table of 8 bits. I can not figure out why it works. Please explain the theory behind it. Thanks static const unsigned char BitReverseTable256[256] = { # define R2(n) n, n + 2*64, n + 1*64, n + 3*64 # define R4(n) R2(n), R2(n + 2*16), R2(n + 1*16), R2(n + 3*16) # define R6(n) R4(n), R4(n + 2*4 ), R4(n + 1*4 ), R4(n + 3*4 ) R6(0), R6(2), R6(1), R6(3) }; 回答1: First off a comment: This kind of thing is normally only done in

Swift alternative for #pragma clang diagnostic

柔情痞子 提交于 2019-12-09 04:19:30
问题 Problem I recently encountered a warning in a third party utility (WEPopover) in this piece of code: _effectivePopoverContentSize = _contentViewController.contentSizeForViewInPopover; This was generating the following warning: warning: 'contentSizeForViewInPopover' is deprecated: first deprecated in iOS 7.0 - Use UIViewController.preferredContentSize instead. [-Wdeprecated-declarations] _effectivePopoverContentSize = _contentViewController.contentSizeForViewInPopover; One temporary fix for

C++ #define preprocessor

自闭症网瘾萝莉.ら 提交于 2019-12-09 00:34:27
问题 I need to know that does the #define directive in C++ declares global label? By global I mean visible in every file? I'm using Visual Studio 2008, (guess if that matters) 回答1: No, only in the current translation unit. I.e. every file which has #define , or includes a file that has the #define will see the definition. Edit, to respond to your comment: to get a define in every file, either put it in a header which gets included everywhere, or use some compiler option to get defines added. e.g.

Why compiler complain about this macro declaration

让人想犯罪 __ 提交于 2019-12-08 23:42:23
问题 I write the following macro for debug convinience, 1 #ifndef DEF_H 2 #define DEF_H 3 #define DEBUG_MODE 4 #define DEBUG_INFO(message) \ 5 #ifdef DEBUG_MODE \ 6 cout << message << endl; \ 7 #endif \ 8 #endif but gcc complains as the following def.h:4: error: '#' is not followed by a macro parameter def.h:1: error: unterminated #ifndef What's wrong with this piece of code? Do I miss some important points here? 回答1: You cannot have #ifdef s inside a macro definition. You need to turn it inside

Preprocessor facility __COUNTER__ in Visual C++

孤人 提交于 2019-12-08 19:14:06
问题 I need to generate a series of sequential numbers throughout my code at compile time. I tried "__COUNTER__" in a way like this: void test1() { printf("test1(): Counter = %d\n", __COUNTER__); } void test2() { printf("test2(): Counter = %d\n", __COUNTER__); } int main() { test1(); test2(); } And the result was perfect as I expected: test1(): Counter = 0 test2(): Counter = 1 Then I spread "__COUNTER__" out in different .cpp files: In Foo.cpp: Foo::Foo() { printf("Foo::Foo() with counter = %d\n",

How to redefine a macro using its previous definition

送分小仙女□ 提交于 2019-12-08 19:03:59
问题 Suppose I have the following macro: #define xxx(x) printf("%s\n",x); Now in certain files I want to use an "enhanced" version of this macro without changing its name. The new version explores the functionality of the original version and does some more work. #define xxx(x) do { xxx(x); yyy(x); } while(0) This of course gives me redefition warning but why I get 'xxx' was not declared in this scope? How should I define it properly? EDIT: according to this http://gcc.gnu.org/onlinedocs/gcc-3.3.6

macro: string literal from char literal

半世苍凉 提交于 2019-12-08 18:37:54
问题 Is there a way in C to create a string literal from a character literal, using a macro? for example I have 'a' and I want to create the string literal "a" To clarify the question: #define A 'a' write(fd, "x=" CHAR2STRING(A) "\n", 4); My question is how to define the macro CHAR2STRING 回答1: –Summary of the comments to the question– This seems impossible to achieve. As an alternative, the string literal could be defined and a STRING2CHAR macro be written instead: #define A "a" #define

How to make (1 << 9) pass MISRA? [duplicate]

橙三吉。 提交于 2019-12-08 17:37:56
问题 This question already has answers here : MISRA C:2004, error with bit shifting (3 answers) Closed 5 years ago . We are using Parasoft Static Analysis with MISRA C 2004 checker turned on. The software is an embedded system. We like to describe constants as follows: [1] #define MOTOR_ON (1 << 9) This would show that the 9th bit in the register should be a 1 to turn on the motor. The expression is failing MISRA, so we changed it: [2] #define MOTOR_ON (1U << 9U) The changes convert to unsigned

Expand C/C++ function macros without preprocessor

牧云@^-^@ 提交于 2019-12-08 17:32:11
问题 How would I test/expand all the function macros, in a C/C++ file, without running it through a preprocessor? For example, is there a program or method which would change this: #include <iostream> #define AAA(a) cout << "function " << a << endl using namespace std; int main(){ AAA(12); } into this? #include <iostream> using namespace std; int main(){ cout << "function " << 12 << endl; } I don't want to run through preprocessor because all the includes in the files make the "gcc -E <>" output