Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #106806
| Newsgroups | comp.lang.c |
|---|---|
| Date | 2017-03-23 08:29 -0700 |
| References | <ob062g$coi$1@dont-email.me> <ob0ck3$62c$1@dont-email.me> <ob0h7f$m6v$1@dont-email.me> <ob0jot$u5u$1@dont-email.me> <ob0nda$cah$2@dont-email.me> |
| Message-ID | <0ce7b882-7aff-434a-9268-dc151b1eb8ec@googlegroups.com> (permalink) |
| Subject | Re: struct padding question |
| From | supercat@casperkitty.com |
On Thursday, March 23, 2017 at 9:54:26 AM UTC-5, David Brown wrote:
> I use both methods - "-Wpadded" can be convenient for a quick check in
> cases where I know I want the struct to be packed tightly, and I use
> static assertions (typically on the sizeof the struct) to make sure
> sizes match the expected value for data that is transferred in or out of
> the program.
In some kinds of programming, structure types are used to achieve a storage
layout which is used elsewhere; being able to write something like:
someStruct->accessCount++;
rather than something like:
putU32le(&someStruct, ACCESS_COUNT_OFS,
getU32le(&someStruct, ACCESS_COUNT_OFS)+1);
is useful. Code which uses structures for purpose of creating bit-level
layouts can fail badly on compilers that don't process them as expected,
but that doesn't mean the technique *shouldn't* be supported in portable
fashion. The ability to use things like the former syntax is part of the
whole *point* of having a high-level language.
If there were a syntax to say whether a particular structure was
being used for data-overlay purposes, then compilers could squawk in cases
where it couldn't handle the intended layout of a data-overlay struct, but
not squawk if padding is added to a struct that isn't being used for such
a purpose.
I find it ironic that the .NET framework offers better support for such low-
level concepts than a language which was invented to facilitate low-level
programming.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
struct padding question MehdiAmini <atorrses@gmail.com> - 2017-03-23 14:28 +0430
Re: struct padding question David Brown <david.brown@hesbynett.no> - 2017-03-23 11:28 +0100
Re: struct padding question MehdiAmini <atorrses@gmail.com> - 2017-03-23 16:44 +0430
Re: struct padding question jm.bourguet@gmail.com - 2017-03-23 05:30 -0700
Re: struct padding question Keith Thompson <kst-u@mib.org> - 2017-03-23 08:45 -0700
Re: struct padding question Noob <root@127.0.0.1> - 2017-04-01 19:15 +0200
Re: struct padding question tim prince <n8tm@aol.com> - 2017-04-01 14:41 -0400
Re: struct padding question supercat@casperkitty.com - 2017-04-02 09:15 -0700
Re: struct padding question scott@slp53.sl.home (Scott Lurndal) - 2017-04-03 13:51 +0000
Re: struct padding question supercat@casperkitty.com - 2017-04-03 07:48 -0700
Re: struct padding question scott@slp53.sl.home (Scott Lurndal) - 2017-04-03 15:47 +0000
Re: struct padding question supercat@casperkitty.com - 2017-04-03 09:24 -0700
Re: struct padding question Keith Thompson <kst-u@mib.org> - 2017-04-01 11:43 -0700
Re: struct padding question Robert Wessel <robertwessel2@yahoo.com> - 2017-04-01 13:46 -0500
Re: struct padding question Keith Thompson <kst-u@mib.org> - 2017-04-01 12:00 -0700
Re: struct padding question Robert Wessel <robertwessel2@yahoo.com> - 2017-04-01 16:40 -0500
Re: struct padding question Keith Thompson <kst-u@mib.org> - 2017-04-01 15:24 -0700
Re: struct padding question Robert Wessel <robertwessel2@yahoo.com> - 2017-04-03 17:46 -0500
Re: struct padding question BartC <bc@freeuk.com> - 2017-03-23 11:50 +0000
Re: struct padding question David Brown <david.brown@hesbynett.no> - 2017-03-23 14:08 +0100
Re: struct padding question BartC <bc@freeuk.com> - 2017-03-23 13:31 +0000
Re: struct padding question David Brown <david.brown@hesbynett.no> - 2017-03-23 14:46 +0100
Re: struct padding question BartC <bc@freeuk.com> - 2017-03-23 14:07 +0000
Re: struct padding question David Brown <david.brown@hesbynett.no> - 2017-03-23 15:52 +0100
Re: struct padding question scott@slp53.sl.home (Scott Lurndal) - 2017-03-23 17:19 +0000
Re: struct padding question David Brown <david.brown@hesbynett.no> - 2017-03-23 19:57 +0100
Re: struct padding question Ian Pilcher <arequipeno@gmail.com> - 2017-03-23 08:52 -0500
Re: struct padding question David Brown <david.brown@hesbynett.no> - 2017-03-23 15:54 +0100
Re: struct padding question supercat@casperkitty.com - 2017-03-23 08:29 -0700
Re: struct padding question GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-03-23 14:04 +0100
Re: struct padding question MehdiAmini <atorrses@gmail.com> - 2017-03-23 20:32 +0430
Re: struct padding question GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-03-23 18:35 +0100
Re: struct padding question supercat@casperkitty.com - 2017-03-23 12:02 -0700
Re: struct padding question Keith Thompson <kst-u@mib.org> - 2017-03-23 12:21 -0700
Re: struct padding question supercat@casperkitty.com - 2017-03-23 12:55 -0700
Re: struct padding question Les Cargill <lcargill99@comcast.com> - 2017-03-25 15:12 -0500
csiph-web