B
Bun Head
Does anyone see a problem with..
#include <stdio.h>
typedef struct {
float x;
float y;
float z;
} _XYZ_;
typedef union {
float arr[3];
_XYZ_ xyz;
} XYZ;
int main(int argc, char** argv)
{
XYZ vec;
printf("union test\n");
printf("setting array to get _XYZ_\n");
vec.arr[0] = 1.0F;
vec.arr[1] = 2.0F;
vec.arr[2] = 3.0F;
printf("vec.xyz is %f, %f, %f\n", vec.xyz.x,vec.xyz.y,vec.xyz.z);
printf("setting _XYZ_ to get arr\n");
vec.xyz.x = 4.0F;
vec.xyz.y = 5.0F;
vec.xyz.z = 6.0F;
printf("vec.arr[] is %f, %f, %f\n",
vec.arr[0],vec.arr[1],vec.arr[2]);
return 0;
}
... On a side note ..
#include <stdio.h>
int main(int argc, char** argv)
{
printf("%15s %s\n", "TYPE", "SIZE");
printf("%15s %s\n", "---------------", "----");
printf("%15s: %02d %02d\n", "char", sizeof(char),sizeof(char)*8);
printf("%15s: %02d %02d\n", "short", sizeof(short),sizeof(short)*8);
printf("%15s: %02d %02d\n", "int", sizeof(int),sizeof(int)*8);
printf("%15s: %02d %02d\n", "long", sizeof(long),sizeof(long)*8);
printf("%15s: %02d %02d\n", "float", sizeof(float),sizeof(float)*8);
printf("%15s: %02d %02d\n", "double",
sizeof(double),sizeof(double)*8);
printf("%15s: %02d %02d\n", "long int", sizeof(long int),sizeof(long
int)*8);
printf("%15s: %02d %02d\n", "long double", sizeof(long
double),sizeof(long double)*8);
return 0;
}
... produces ..
char: 01 08
short: 02 16
int: 02 16
long: 04 32
float: 04 32
double: 08 64
long int: 04 32
long double: 10 80
(This was compiled and executed on WinXP)
I thought that "int" type was 32-bit native;
and, "long int" was 64-bit native. In every
variety of UNIX that I try this on my thought
is correct. But, when going to a windoze
environment I get these results. Is there a
way to detect the native type sizes that are
available?
Anyway, if I do a union on UNIX such as..
typedef union {
int val;
char bytes[4];
}
... it will be invalid on WinXP.. sheesh!!!
#include <stdio.h>
typedef struct {
float x;
float y;
float z;
} _XYZ_;
typedef union {
float arr[3];
_XYZ_ xyz;
} XYZ;
int main(int argc, char** argv)
{
XYZ vec;
printf("union test\n");
printf("setting array to get _XYZ_\n");
vec.arr[0] = 1.0F;
vec.arr[1] = 2.0F;
vec.arr[2] = 3.0F;
printf("vec.xyz is %f, %f, %f\n", vec.xyz.x,vec.xyz.y,vec.xyz.z);
printf("setting _XYZ_ to get arr\n");
vec.xyz.x = 4.0F;
vec.xyz.y = 5.0F;
vec.xyz.z = 6.0F;
printf("vec.arr[] is %f, %f, %f\n",
vec.arr[0],vec.arr[1],vec.arr[2]);
return 0;
}
... On a side note ..
#include <stdio.h>
int main(int argc, char** argv)
{
printf("%15s %s\n", "TYPE", "SIZE");
printf("%15s %s\n", "---------------", "----");
printf("%15s: %02d %02d\n", "char", sizeof(char),sizeof(char)*8);
printf("%15s: %02d %02d\n", "short", sizeof(short),sizeof(short)*8);
printf("%15s: %02d %02d\n", "int", sizeof(int),sizeof(int)*8);
printf("%15s: %02d %02d\n", "long", sizeof(long),sizeof(long)*8);
printf("%15s: %02d %02d\n", "float", sizeof(float),sizeof(float)*8);
printf("%15s: %02d %02d\n", "double",
sizeof(double),sizeof(double)*8);
printf("%15s: %02d %02d\n", "long int", sizeof(long int),sizeof(long
int)*8);
printf("%15s: %02d %02d\n", "long double", sizeof(long
double),sizeof(long double)*8);
return 0;
}
... produces ..
char: 01 08
short: 02 16
int: 02 16
long: 04 32
float: 04 32
double: 08 64
long int: 04 32
long double: 10 80
(This was compiled and executed on WinXP)
I thought that "int" type was 32-bit native;
and, "long int" was 64-bit native. In every
variety of UNIX that I try this on my thought
is correct. But, when going to a windoze
environment I get these results. Is there a
way to detect the native type sizes that are
available?
Anyway, if I do a union on UNIX such as..
typedef union {
int val;
char bytes[4];
}
... it will be invalid on WinXP.. sheesh!!!