cast odd boundary?

D

Devrobcom

Hi

I have read somwhere that this problem is handled by the
Intel cpu's (firmware), but what will happen on other types of cpu's.

struct
{
char aa; // even boundary 0xaa00
char bb[4]; // assume on odd boundary 0xaa01
} mstr;

long ll;
ll = *((long*)mstr.bb); // no: 1 do i get an exception?

*((long*)mstr.bb) = ll; // no: 2 do i get an exception?

/dev
 
C

Clark Cox

"Devrobcom said:
Hi

I have read somwhere that this problem is handled by the
Intel cpu's (firmware), but what will happen on other types of cpu's.

struct
{
char aa; // even boundary 0xaa00
char bb[4]; // assume on odd boundary 0xaa01
} mstr;

Assuming that that is the case (i.e. there is no padding between aa
and bb, and sizeof(long) == 4).
long ll;
ll = *((long*)mstr.bb); // no: 1 do i get an exception?

You could get an exception, or you app could simply crash, or monkeys
could spring forth from your gut :), as that is undefined behavior. Many
platforms require special alignment for particular types.
*((long*)mstr.bb) = ll; // no: 2 do i get an exception?

Same answer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,141
Messages
2,570,815
Members
47,361
Latest member
RogerDuabe

Latest Threads

Top