LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with pragma

Below you will find a very short code using pragma pack(8). It seems it does 'nt work and I realy can't figure out. Basically I try to align a Point struct containing 3 floats. Then I decalre 3 point and look at the adr of each variable. At the end I divede the value of the adr with 8 and the rest should be 0 (if I'm right). Please, let me know, any advise will be welcome.

By the way I would like to know if there is any plan for supporting pragam pack(16) like in MSVC 6. Indeed this may be usefull for those of us dealing with SSE set of instructions.

Regards, Philippe
Feel free to visit www.baucour.com

//----------------------------
#include

#pragma pack(push, 😎
typedef struct Point_tag{
float X;
float Y;
float Z;

//float T;
}Point;
#pragma pack(pop)

int main(int argc, char *argv[]){

static Point P1, P2, P3;
int Dummy;

argc = argc; // avoid W4 compile warning with MSVC
argv = argv;

P1.X = 1.2f;
P1.Y = 2.3f;
P1.Z = 3.4f;
//P1.T = 0.0f;

P2.X = 0.8f;
P2.Y = 0.7f;
P2.Z = 0.6f;
//P2.T = 0.0f;

printf("The size of one float is : %d\n", sizeof(float));
printf("Size of a Point is : %d\n", sizeof(Point));

printf("\n");

Dummy = (int)&P1;
printf("Adr of P1 is %X (div per 8 = %f)\n", &P1, Dummy/8.0);

Dummy = (int)&P2;
printf("Adr of P2 is %X (div per 8 = %f)\n", &P2, Dummy/8.0);

Dummy = (int)&P3;
printf("Adr of P3 is %X (div per 8 = %f)\n", &P3, Dummy/8.0);

printf("\nIf all the digit after the dot are not equal to 0 then I'm in trouble");
getchar();
return(0);
}
0 Kudos
Message 1 of 2
(2,860 Views)
As I recall, a float is 4 bytes and a double is 8 bytes.
0 Kudos
Message 2 of 2
(2,860 Views)