C++: Should I use a reference member here?

Started by
20 comments, last by grekster 14 years, 1 month ago
Quote:Original post by CodeCriminal
One question though, which pragma directive are you refering to?
I assume it's
#pragma pack(1)class Vector3  {public:        ...(lots of member functions)...	float i;	float j;	float k;};#pragma pack()
or the push/pop variants. Unfortunately, #pragmas are compiler dependent. The above is known from M$ compilers.

The way GCC suggests is different; something like
class Vector3  {public:        ...(lots of member functions)...	float i;	float j;	float k;} __attribute__((packed));
for packing the entire structure. However, at least older versions of GCC supported the #pragma way for compatibility reasons as well.
Advertisement
Quote:Original post by karwosts
Quote:
If it were me, I would just go ahead and return &i for your float*. Appropriate use of pragma should control the structure layout appropriately


I wasn't aware that those floats are guaranteed to be contiguous in memory


If they weren't then the union/struct solution wouldn't work either, given that it also relies on the floats being contiguous.

Quote:Original post by BosskIn Soviet Russia, you STFU WITH THOSE LAME JOKES!

This topic is closed to new replies.

Advertisement