T
Tomás Ó hÉilidhe
I've heard of things called "trap values". From what I understand, if
you set an integer variable to a trap value, then the program crashes.
Is this right?
From what I understand, it seems that unsigned integers shouldn't
have any trap values seeing as how every bit-pattern is a unique number.
Also, from what I understand, the only time you could have a "trap
value" is where you're working with a sign-magnitude machine and the
machine doesn't like negative 0. Presumably, on such a machine, the
following would crash:
int i, j;
i = 0;
i |= 0x800;
j = i; /* Crashes because we've got a trap pattern */
Do I understand this alright? Are there any other trap values?
Also, what happens when you set padding bits within integers. For
instance, let's day we have a machine where:
CHAR_BIT == 8
sizeof(int) == 6 (4 bytes for value, 2 bytes of padding)
On this machine, is it OK to do the following:
unsigned i, j;
memset(&i,0x3f,sizeof(int));
j = i;
Can this cause a crash? If so, what kind of crash is it? Do we call this
a "trap value" also?
you set an integer variable to a trap value, then the program crashes.
Is this right?
From what I understand, it seems that unsigned integers shouldn't
have any trap values seeing as how every bit-pattern is a unique number.
Also, from what I understand, the only time you could have a "trap
value" is where you're working with a sign-magnitude machine and the
machine doesn't like negative 0. Presumably, on such a machine, the
following would crash:
int i, j;
i = 0;
i |= 0x800;
j = i; /* Crashes because we've got a trap pattern */
Do I understand this alright? Are there any other trap values?
Also, what happens when you set padding bits within integers. For
instance, let's day we have a machine where:
CHAR_BIT == 8
sizeof(int) == 6 (4 bytes for value, 2 bytes of padding)
On this machine, is it OK to do the following:
unsigned i, j;
memset(&i,0x3f,sizeof(int));
j = i;
Can this cause a crash? If so, what kind of crash is it? Do we call this
a "trap value" also?