C++ Preprocessor semicolon [closed] - c++

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);

Related

C++ define function [closed]

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.
The community reviewed whether to reopen this question 1 year ago and left it closed:
Original close reason(s) were not resolved
Improve this question
I would like to ask if there is a way to use define to create a function in C++ like that:
#define RequiredDamage(%1) ( (%1+1)*500 )
Could somebody help me to find better understanding of how #define actually works. What's the actual syntax to actually create a function like that, where could it be applied, is it a good idea to use it and why would I prefer it over a normal function?
Thanks in advance!
Yes, you need to provide an argument in your macro definition:
#define RequiredDamage(x) ( (x+1)*500 )

define BOOST_PP_NODE_13(p) BOOST_PP_IIF(p##(13), 13, 14) [closed]

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 6 years ago.
Improve this question
boost
auto_rec.hpp
What does mean p##(13) here:
define BOOST_PP_NODE_13(p) BOOST_PP_IIF(p##(13), 13, 14)
In what it translates?
The '##' preprocessing operator is used to do concatenation. See Macros.
What it does is take tokens from both side of the operator and produce a single token with them.
Here's a classic usage:
#define foo(x, y) x ## y
foo(aa, bb) // expands to 'aabb'
In your case, there is no use to ## since p and (13) don't need to be concatenated to expand into a valid expression.
It's interesting to see that ## disappeared in newest versions of boost.
Moreover, it seems clang doesn't like ## with parenthesis as it tries to paste 'p(' as an invalid token on its own, which result in a compiler error.

c++ evaluating string expression with variables [closed]

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 6 years ago.
Improve this question
I want to do evaluate for example something like:
int x=10, y=2;
x=eval('x+(y*10)');
i can give you the code which i made, but would like you to try yourself. Here are the steps :
replace all the unknowns with their values
convert the expression to postfix
try to evaluate postfix expression using stacks

Why don't C/C++ have the include guard feature built-in? [closed]

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.

Why a segfault on #define? [closed]

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.