B
bluejack
Hit a super weird bug, which baffled me for some time. Here's the
setup:
struct thing {
unsigned char byte1;
unsigned char byte2;
unsigned char byte3;
unsigned long long big_number;
char* string_ptr;
};
void set_default_values(struct thing* t)
{
t->byte1 = 0;
t->byte2 = 1;
t->byte3 = 2;
t->big_number = 0;
t->string_ptr = strdup("This is a string.");
}
Ok? What am I doing wrong?
After calling set_default values, my struct is:
byte1 = 0, byte2 = 1, byte3 = 2, big_number =
157823974298375928572234, string_ptr = "his is a string."
The big_number there is not exact. I can try to work up a functioning
microprogram if this is at all worth pursuing.
Eventually, after the byte3 member, I added an 'unsigned char unusued'
member, and my problems went away. My understanding was that the
compiler was supposed to align bytes and optionally pad if required by
the os. Is my understanding wrong? I'm using an ordinary gdb on an
ordinary linux. This *can't* be a broken compiler problem, can it? (I
realize it's almost certainly a broken programmer problem; and I
thought I'd call for smacks on the head before pursuing any further.)
-Bluejack
setup:
struct thing {
unsigned char byte1;
unsigned char byte2;
unsigned char byte3;
unsigned long long big_number;
char* string_ptr;
};
void set_default_values(struct thing* t)
{
t->byte1 = 0;
t->byte2 = 1;
t->byte3 = 2;
t->big_number = 0;
t->string_ptr = strdup("This is a string.");
}
Ok? What am I doing wrong?
After calling set_default values, my struct is:
byte1 = 0, byte2 = 1, byte3 = 2, big_number =
157823974298375928572234, string_ptr = "his is a string."
The big_number there is not exact. I can try to work up a functioning
microprogram if this is at all worth pursuing.
Eventually, after the byte3 member, I added an 'unsigned char unusued'
member, and my problems went away. My understanding was that the
compiler was supposed to align bytes and optionally pad if required by
the os. Is my understanding wrong? I'm using an ordinary gdb on an
ordinary linux. This *can't* be a broken compiler problem, can it? (I
realize it's almost certainly a broken programmer problem; and I
thought I'd call for smacks on the head before pursuing any further.)
-Bluejack