c - What actually is going on when we do structure type casting? -
here (how cast 1 type in c) have same question without explanation how structure type casting works.
#include <stdio.h> #include <ctype.h> typedef struct { int type; int type2; }foo; typedef struct { char cdata[40]; }bar; int main() { bar b1; strcpy(b1.cdata,"11"); (struct foo *) &b1; // going on here? have changed @ point? return 0; }
we have different sizes - sizeof (foo) > sizeof (bar). happened after casting?
you cannot cast 1 structure type another. can cast pointer 1 structure type point another, in case nothing happens it--it's memory address, , re-interpreted pointing different kind of thing.
Comments
Post a Comment