Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > sizeof a struct

Reply
Thread Tools

sizeof a struct

 
 
Phui Hock
Guest
Posts: n/a
 
      11-06-2003
I've found this article "What should sizeof (struct xyzzy) return?" at
http://www.delorie.com/djgpp/v2faq/faq22_11.html. Just thought of
sharing it with anyone who came across the same problem.

Thanks for the clues, guys
 
Reply With Quote
 
 
 
 
Richard Bos
Guest
Posts: n/a
 
      11-06-2003
http://www.velocityreviews.com/forums/(E-Mail Removed) (Phui Hock) wrote:

> I've found this article "What should sizeof (struct xyzzy) return?" at
> http://www.delorie.com/djgpp/v2faq/faq22_11.html. Just thought of
> sharing it with anyone who came across the same problem.


While the solutions on that page are (for obvious reasons) partly
system-specific, in particular the attribute-packed one, its explanation
of the problem is good, IMO.

Richard
 
Reply With Quote
 
 
 
 
Villy Kruse
Guest
Posts: n/a
 
      11-06-2003
On Thu, 06 Nov 2003 11:17:39 GMT,
Richard Bos <(E-Mail Removed)> wrote:


>(E-Mail Removed) (Phui Hock) wrote:
>
>> I've found this article "What should sizeof (struct xyzzy) return?" at
>> http://www.delorie.com/djgpp/v2faq/faq22_11.html. Just thought of
>> sharing it with anyone who came across the same problem.

>
>While the solutions on that page are (for obvious reasons) partly
>system-specific, in particular the attribute-packed one, its explanation
>of the problem is good, IMO.
>


Just need to note that some processors don't tolerate unaligned access
at all. You get a program crash rather than some performance penalty.

Of course, djgpp is limited to Intel x86 only so this doesn't apply.

Villy
 
Reply With Quote
 
Darrell Grainger
Guest
Posts: n/a
 
      11-06-2003
On Thu, 6 Nov 2003, Phui Hock wrote:

> I've found this article "What should sizeof (struct xyzzy) return?" at
> http://www.delorie.com/djgpp/v2faq/faq22_11.html. Just thought of
> sharing it with anyone who came across the same problem.
>
> Thanks for the clues, guys


This is in the FAQ.

http://www.eskimo.com/~scs/C-faq/q2.13.html

There is also a reference to q2.12 as well.

--
Send e-mail to: darrell at cs dot toronto dot edu
Don't send e-mail to (E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can *common* struct-members of 2 different struct-types, that are thesame for the first common members, be accessed via pointer cast to either struct-type? John Reye C Programming 28 05-08-2012 12:24 AM
#define ARR_SIZE sizeof(arr)/sizeof(arr[0]) Vinu C Programming 13 05-12-2005 06:00 PM
sizeof(enum) == sizeof(int) ??? Derek C++ 7 10-14-2004 05:11 PM
struct my_struct *p = (struct my_struct *)malloc(sizeof(struct my_struct)); Chris Fogelklou C Programming 36 04-20-2004 08:27 AM
sizeof(str) or sizeof(str) - 1 ? Trevor C Programming 9 04-10-2004 05:07 PM



Advertisments