Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | James Kuyper <jameskuyper@verizon.net> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Structure with unsigned chars and internal alignment |
| Date | 2011-09-12 15:32 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <4E6E5E40.2020703@verizon.net> (permalink) |
| References | <j3jmrn$cae$1@nnrp.ngi.it> <j3k3e6$a1h$1@dont-email.me> <7206ef0d-357c-4859-bc42-0c0b8362d0ff@z26g2000pre.googlegroups.com> |
On 09/12/2011 03:09 PM, NicStevens wrote:
> On Aug 30, 6:39 pm, Eric Sosman <esos...@ieee-dot-org.invalid> wrote:
>> On 8/30/2011 6:05 PM, pozz wrote:
>>
>>> I have a struct composed by two arrays of unsigned char.
>>
>>> struct myStruct {
>>> unsigned char field1[2];
>>> unsigned char field2[30];
>>> };
...
>>> field2_size = struct_size - offsetof(struct myStruct, field2)
>>
>> Same problem: It could be right or wrong (or "not even wrong"),
>> because what you need to care about is who wrote the file and how.
...
> may I ask what compiler offsetof works on? I tried gcc and msc and
> both complain about offsetof(struct foo, bar)
The following code should compile without complaint on any hosted
implementation of C which fully conforms to any version of the C
standard. I can't test it on msc, but it does compile without any
complaints with gcc, gcc -std=c89, and gcc -std=c99. I'd be surprised
at anything that dares to call itself a C compiler which would complain
about it:
#include <stddef.h>
struct foo { int bar; };
int main(void)
{
return offsetof(struct foo, bar);
}
If you're running into problems with offsetof(struct foo, bar), it's
probably not due to the offsetof() expression itself, but it's
connection with the rest of your program. For instance, did you remember
to #include <stddef.h>?
If that's not the problem, can you provide an complete, short, program
that demonstrates the problem, along with the command line that you used
to compile it, and the message that was generated complaining about it?
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Structure with unsigned chars and internal alignment pozz <pozzugno@gmail.com> - 2011-08-31 00:05 +0200
Re: Structure with unsigned chars and internal alignment "Scott Fluhrer" <sfluhrer@ix.netcom.com> - 2011-08-30 18:46 -0400
Re: Structure with unsigned chars and internal alignment pozz <pozzugno@gmail.com> - 2011-08-31 08:53 +0200
Re: Structure with unsigned chars and internal alignment James Kuyper <jameskuyper@verizon.net> - 2011-08-31 07:42 -0400
Re: Structure with unsigned chars and internal alignment lawrence.jones@siemens.com - 2011-08-31 12:56 -0400
Re: Structure with unsigned chars and internal alignment Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-08-30 21:39 -0400
Re: Structure with unsigned chars and internal alignment pozz <pozzugno@gmail.com> - 2011-08-31 09:07 +0200
Re: Structure with unsigned chars and internal alignment Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-08-31 21:26 -0400
Re: Structure with unsigned chars and internal alignment pozz <pozzugno@gmail.com> - 2011-09-01 07:59 +0200
Re: Structure with unsigned chars and internal alignment "BartC" <bc@freeuk.com> - 2011-09-01 10:34 +0100
Re: Structure with unsigned chars and internal alignment pozz <pozzugno@gmail.com> - 2011-09-01 13:07 +0200
Re: Structure with unsigned chars and internal alignment Keith Thompson <kst-u@mib.org> - 2011-09-01 08:34 -0700
Re: Structure with unsigned chars and internal alignment Keith Thompson <kst-u@mib.org> - 2011-09-01 08:46 -0700
Re: Structure with unsigned chars and internal alignment NicStevens <nic.stevens@gmail.com> - 2011-09-12 12:09 -0700
Re: Structure with unsigned chars and internal alignment "J. J. Farrell" <jjf@bcs.org.uk> - 2011-09-12 20:30 +0100
Re: Structure with unsigned chars and internal alignment James Kuyper <jameskuyper@verizon.net> - 2011-09-12 15:32 -0400
Re: Structure with unsigned chars and internal alignment NicStevens <nic.stevens@gmail.com> - 2011-09-14 13:28 -0700
Re: Structure with unsigned chars and internal alignment "BartC" <bc@freeuk.com> - 2011-08-31 11:50 +0100
Re: Structure with unsigned chars and internal alignment David Resnick <lndresnick@gmail.com> - 2011-08-31 06:31 -0700
csiph-web