Im trying to define printf("%d",var) to something more easy,but i cant figure out how.
I want it something like printvar(var),but i cant figure out a code to define it like that =\
Thanks
Im trying to define printf("%d",var) to something more easy,but i cant figure out how.
I want it something like printvar(var),but i cant figure out a code to define it like that =\
Thanks
I'm pretty sure that's how macro functions work.Code:#define printvar(var) printf("%d",var)
Originally Posted by The Jargon File
But when var is no longer an int, what are you going to do then?
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
yes,but that means i would have to name the variable "var".
i want something where i can go,
The code you gave me only defines "var".Code:printvar(var); printvar(var2); printvar(anothervar);
Incidentally, it would be good to get into the habit of enclosing macro arguments in parentheses to force the correct order evaluation. It makes no difference in this case, but consider the following:
If you then use it in your code with, say, square(a+5) you will get an unexpected result because it will expand in-line to a+5*a+5 rather than (a+5)*(a+5). This is correct:Code:#define square(x) x*x
Code:#define square(x) (x)*(x)
Code:while(!asleep) { sheep++; }
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.
Yes, but who would want to do something like that?
Code:while(!asleep) { sheep++; }
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.