AD1

Tuesday, 24 January 2017

Pointers and bitfields

what will be the output of the following code

#include <stdio.h>
struct test
{
unsigned int x;
long int y: 33;
unsigned int z;
};
int main()
{
struct test t;
unsigned int *ptr1 = &t.y;
unsigned int *ptr2 = &t.z;
printf("%d", ptr2 - ptr1);
return 0;
}
view raw bitfields.c hosted with ❤ by GitHub
the code creates compilation error , as you can not create a pointer to bit fields , simply because bit fields may not start at byte boundry

No comments:

Post a Comment