T
Tommy Vercetti
Hi -
Great group!
I have 2 queries about undefined behavior:
1) Is the following code undefined?
float myfunction(float f)
{
if(sizeof(float) & sizeof(int)) {
/* use slow ordinary FP operations */
} else {
int i = *(int *)&f;
/* do clever bit-twiddling floating-point operation */
}
}
It only attempts to access the float as an integer when this makes
sense.
2) I've seen code like the following:
struct s {
int a;
char *b;
float c;
} s;
int *i = (int *) s;
Isn't this undefined? Won't this blow up if the compiler inserts padding
before the first element of the struct?
Cheers!
Great group!
I have 2 queries about undefined behavior:
1) Is the following code undefined?
float myfunction(float f)
{
if(sizeof(float) & sizeof(int)) {
/* use slow ordinary FP operations */
} else {
int i = *(int *)&f;
/* do clever bit-twiddling floating-point operation */
}
}
It only attempts to access the float as an integer when this makes
sense.
2) I've seen code like the following:
struct s {
int a;
char *b;
float c;
} s;
int *i = (int *) s;
Isn't this undefined? Won't this blow up if the compiler inserts padding
before the first element of the struct?
Cheers!