Tagged Questions
0
votes
2answers
39 views
Preprocessor not using defined hashed value but definition string for macro
Iam trying to make an easy way of defining my IO. Im trying to do this with macro but I cant solve this problem.
I did this:
// Buzzer PORT and PIN mapping
#define BUZZER_PORT B // PORT
...
4
votes
2answers
72 views
why is macro declared this way? [duplicate]
what is the reason to define macro this way
#define test_errno(msg) do{if (errno) {perror(msg); exit(EXIT_FAILURE);}} while(0)
I mean what is the reason behind do{}while(0)? Ofcourse it will be ...
0
votes
1answer
25 views
error enum has no member when using macro
I want create two enums: DerivedBirdType and BasicBirdType. BasicBirdType has members named like BCT_*. DerivedBirdType has all members in BasicBirdType but with different prefix DCT_*, and it also ...
1
vote
4answers
80 views
Is there a way to both check a macro is defined and it equals a certain value at the same time
I regularly use object-like preprocessor macros as boolean flags in C code to turn on and off sections of code.
For example
#define DEBUG_PRINT 1
And then use it like
#if(DEBUG_PRINT == 1)
...
0
votes
1answer
78 views
How to use #define to assign pins in Arduino?
i am trying to use #define to create a constant and define a pin, check this code
#define PIN_MICROPHONE 13;
void loop()
{
analogRead(PIN_MICROPHONE);
}
But when trying to compile, says this ...
0
votes
1answer
65 views
In C, is there a better way to calculate uncertainty values?
What I've been doing is using a #define UNC (uncertainty) to toggle on and off the functionality for calculating x (the value) and dx (the uncertainty). It works pretty well, but it's not easy to read ...
2
votes
5answers
90 views
Why should or shouldn't we prefer a macro that accepts arguments over a function that does the same job?
Following are two programs that give the area of the circle when the radius is passed as argument.But in the first program, macro.c, I am using a macro for the job ,while in the second,function.c I am ...
2
votes
3answers
238 views
How to create a “C single-line comment” macro
I am trying to create a "single line comment" macro in C, this is used conditionally to comment out lines of codes, according to some global macro definitions. It is the same idea expressed in this ...
2
votes
1answer
90 views
ะก nested macros
Can someone explain why in one case nested macros works while in the other does not?
Case 1:
#define name(val) #val
#define name2(front, back) name(front ## back)
...
printf("%s\n", name2(foo, ...
0
votes
4answers
210 views
Objective c macro that checks the device [duplicate]
I need a macro that determines whether the device is an iPhone 4, or an iPhone 5. I was told that there is a macro that can do this. Does anyone know what it is or where I can find it? Thanks for the ...
0
votes
3answers
108 views
define macro with template as variable
i'm trying to use a macro to create some static variables.
my problem is, how do i do define a macro with 2 parameters, the first is a template and the second a static variable. the template should ...
2
votes
3answers
56 views
Universal macro which can have zero or one parameter
Is there any way to define macro which can have one or zero parameters?
I need something to be used as in this example:
#define MY_RETURN(ret) return ret;
void foo(){
MY_RETURN();
}
int ...
0
votes
1answer
75 views
how can i define KdPrint to DbgPrint?
I am trying to write macros for universal debugging.
How to define KdPrint to DbgPrint?
I am trying like this
#define KdPrint(x) do{DbgPrint x;}while(0)
In driver code
KdPrint(("Driver entry")); ...
1
vote
2answers
189 views
define a macro to replace code
I'm using TestFlight and I've got this macro to replace NSLog the the TestFlight remote logging equivalent.
#define NSLog(__FORMAT__, ...) TFLog((@"%s [Line %d] " __FORMAT__), __PRETTY_FUNCTION__, ...
3
votes
1answer
54 views
How do I define a macro with the same name as its expansion in m4?
I am attempting to replace if with if( using GNU m4 1.4.14 and I am receiving ERROR: end of file in argument list
when trying:
define(`if', `if(')
define(`then', `){')
define(`fi', `}')
if foo then ...