#pragma pack (1)
struct s {
char c; // offset 0
int i; // offset 1!
} ss;
#pragma pack ()
void f_improper(int *p)
{
*p = 23; // generates a fault
}
void g_proper(int __unaligned *p) // OK
{
*p = 42;
}
void main ()
{
f_improper(&ss.i);
g_proper(&ss.i);
}
Thursday, June 3, 2010
How to generate Alignment error in C - Padding
Labels:
C C++
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.