Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
What these C macros get expanded to ?
#define PERIPH_BASE ((uint32_t)0x40000000)
#define AHB2PERIPH_BASE (PERIPH_BASE + 0x08000000)
#define GPIOA_BASE (AHB2PERIPH_BASE + 0x0000)
#define GPIOB_BASE (AHB2PERIPH_BASE + 0x0400)
#define BLINK_GPIOx(_N) (GPIO_TypeDef *)(GPIO_BASE +(GPIOB_BASE-GPIOA_BASE)*(_N)))
#define BLINK_PORT_NUMBER(4)
the call to this is
GPIO_SetBits(BLINK_GPIOx(BLINK_PORT_NUMBER), BLINK_PIN_MASK(8));
Use -E option of gcc compiler to see the preprocessor output.
example: gcc -E program.c -o preprocessOutput.p
Then view the contents of the file preprocessOutput.p
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 days ago.
Improve this question
#define LPF(Y,X,Fb,Fs) Y=Y*exp(-PI2*Fb/Fs)+X*(1.-exp(-PI2*Fb/Fs))
#define LPF_Gamma(Y,X,Gamma) Y=Y*Gamma+X*(1.-Gamma)
#define Gamma_Cal(Gamma,Fb,Ts) Gamma=exp(-PI2*Fb*Ts)
#define LPF_Gamma(Y,X,Gamma) Y=Y*Gamma+X*(1.-Gamma)
What is dot operator in C++ macro function?
1.-Gamma
#define F(x) std::cout << 1.-x << '\n'
Result: F(10) = -9
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I want to write code like this MAKE var=NUMBER: 21, which can be translated to
auto var=21;.
I have defined the following macros: #define MAKE auto and
#define NUMBER (1==0)? , but they did not work well.
To put it simple, I would like to add the semicolon at the end of the definition automatically.
Thanks.
It is not achievable with C++ macro syntax. You have only macro before 21 and not after. Though you can achieve that if you change your syntax slightly:
MAKE var=NUMBER(21)
instead of
MAKE var=NUMBER: 21
and define NUMBER as:
#define NUMBER(x) (x);
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Example:
#include <iostream>
int main() {
return 0;
}
I want to know total number of LOC, including everything included from iostream.
You could use GCC's -E-option, which does preprocessor only compilation, so all makros and includes will be expanded and the resulting code is sent to console output. Feeding this into a word count / line count should give the desired result:
gcc -E main.cpp | wc -l
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
It's laborious to put an include guard in every header file. Most other language don't need it anyway. Python doesn't have 'import' guard.
C/C++ including is a textual thing. It can be used multiple times successfully.
#define STUFF EXPANSION1
#include "mydataset.h"
#undef STUFF
#define STUFF EXPANSION2
#include "mydataset.h"
Allows a macro data set to be filled out with differing behavior.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I don't understand why my program segfault after #define with that :
if(QProcess::systemEnvironment().filter("toto").size() == 1 )
if(!QProcess::systemEnvironment().filter("toto").at(0).contains("13"))
#define tata
I using this code in another class and he run like a boss :P
The program segfault when the if is false...
I know #define is a precompiler directive and I understand the segfault but why this same code run in my another class with no problem and if my environment variable is changed the program accept the modification.. and I specified that the code has not been recompiled..
#define is a precompiler directive, it is parsed and used by the compiler, not at runtime. So it does not obey your if conditions. Thus, your if is actually conditioning the execution of whatever goes after this code... whatever it is.
Solution: use a boolean variable, not a macro.
bool tata = false;
if(QProcess::systemEnvironment().filter("toto").size() == 1 )
if(!QProcess::systemEnvironment().filter("toto").at(0).contains("13"))
tata = true;
But the details will depend on what you are doing with tata in the first place.