***** OR &&&&

Started by
10 comments, last by GameDev.net 19 years, 4 months ago
Quote:Original post by smr
Quote:Original post by MaulingMonkey
Neither. They're both the exact same thing, internally. Just different syntax used.

Heck, I wouldn't be suprised if this worked on many compilers:

*** Source Snippet Removed ***


I'm not going to try it, but it shouldn't work. Every time the compiler accesses a reference it should always dereference before any casts are applied. So you will end up trying to make a pointer of first sizeof(ofstream*) bytes actual data within the object, which the compiler shouldn't let you do.


I'm not following what you're saying. But the fact of the matter is that the function does NOT take the object by value - it is a REFERENCE! Since this is not the actual data - just an under the hood pointer - there is no data truncation occuring here.

Quote:Well I did try it, and although I certainly don't recommend doing this in any shape or form it seems to work fine under both BCB and GCC. I even tried passing a derived class by pointer/reference to base and calling a virtual method and it worked fine.

Enigma


Scary.

Quote:IIRC, it is possible to create a 'null' reference, but the result is undefined.


Correct. And we all know, undefined is programmer-speak for "STEP AWAY FROM THE BUTTON BEFORE YOU RELEASE THE HOARDS OF GIANT BLUE MONKEYS!!!".
Advertisement
A reference gives the compiler slightly more opportunity for optimization than a non-const pointer, since it knows that a reference cannot be reassigned to refer to a different object. A const pointer (not to be confused with a pointer to const data) gives performance equivalent to a reference in all cases.

Regards,

This topic is closed to new replies.

Advertisement