C++ strange line

Started by
4 comments, last by tont 18 years, 4 months ago
I tought i knew C++ well, but after what ive seen and can just admit i'm wrong. I've followed a tutorial on collision (the collision part is not really revelent), and some line got me a headache. First, ive never seen such a syntax in C++, and this is from where comes my question. First, look a the code : //In the defines typedef unsigned int uint32; #define in(a) ((uint32&)a); //Somewhere in a bool function return (( in(z)& ~(in(x)|in(y)) ) & 0x80000000); Now, ok, is it C++ ? Because my compiler (VC++ 6) does not seem to undertsand anything about that. Is it a compiler specific syntax ? If it is not C++ or the syntaz is not correct, what do you undertsand of that and what should i do to make it work in VC++ 6 ? Thnaks
"Do, or do not. There is no try." - Yoda
Advertisement
Here are a couple things that will help you understand that snippet:

~ Bitwise Compliment (search down the page for tilde)
& operator
| inclusive or operator

#define in(a) ((uint32&)a);

really does this:

in(z) turns into
((uint32&)z)

before compile time and that in itself is simply defined as

((unsigned int)&)z)

so the line turns into this:

return (((unsigned int&)z)&~((unsigned int&)x)|((unsigned int&)y)&0x80000000);

[Edited by - M2tM on January 12, 2006 7:51:13 PM]
_______________________"You're using a screwdriver to nail some glue to a ming vase. " -ToohrVyk
But why my compiler does not seems do understand that ? I recieve many errors like this :

"& on constant" (the & from the macro defined)
many waning on conversion
many "missing ')' before ';'" or "syntax error ')'"

Ive verified it, the macro is recognized (i got different errors if a just remve the define lines), so ?

EDIT: Dammit, im so stupid. Like many of the errors i got and that i cannot solve, the fault was stupid and had no direct link with the command. It is mroe about base syntax. Look more precisely at the code ive putted, this is an exact copy-paste from my code.

#define in(a) ((uint32&)a);

You dont see ? One more time

#define.. ok
in(a) ((uint32&)a)...ok
;... wtf !?!

SOmeone can tell me why ive put a semicolon ? No really ! Thanks for you help, and sorry to had make you lose your time.
"Do, or do not. There is no try." - Yoda
Try replacing the line with:

return (((unsigned int&)z)&~((unsigned int&)x)|((unsigned int&)y)&0x80000000);

and see if that returns the intended results. I got that line to compile, but not the subbed in macro one.

*edit: Ah, I gotcha. I totally missed that semicolon myself.
_______________________"You're using a screwdriver to nail some glue to a ming vase. " -ToohrVyk
This is just painful to look at code. You could clean it up a lot and make it a lot more readable.

"Those who would give up essential liberty to purchase a little temporary safety deserve neither liberty nor safety." --Benjamin Franklin

Quote:Original post by Mike2343
This is just painful to look at code. You could clean it up a lot and make it a lot more readable.


i think he should take that code out to the back and shoot it. :P

This topic is closed to new replies.

Advertisement