--- In [email protected], "Victor A. Wagner Jr." <[EMAIL PROTECTED]> wrote: > > At 00:47 2007-05-03, Senthil Kumar wrote: > >I think , this may be the suitable way > >main() > >{ > >struct name { > > int a; > > int c; > > char b; > > float d; > > }; > >struct name *name1; > >int a,b,c; > >a = &name1[0]; > >b= &name1[1]; > >c= b-a; > >printf("%d",c); > > > >} > > > >difference b/w these two pointers(name1++,name) are > >size of the structure .. > > correct, BUT > the question was to write a FUNCTION that acts like sizeof <snip>
Another issue to be aware of with this approach is that many compilers will pad the elements of the structure "struct name" with unused bytes in order to accelerate access. It's completely up to the compiler writers to implement such functionality; many offer a special #pragma to switch on (or off) this feature, but you cannot rely on such behaviour as no compiler need to observe #pragma at all. At least that's what I have learnt so far from this group. Maybe I'm wrong. Regards, Nico
