Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | cri@tiac.net (Richard Harter) |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: What is the right way to do this simple thing |
| Date | 2012-03-13 21:51 +0000 |
| Message-ID | <4f5fc066.2213810094@text.giganews.com> (permalink) |
| References | <4f5ba2ed.1944110152@text.giganews.com> <d4eb653e-30b3-4393-92fc-17b7732575ec@fk28g2000vbb.googlegroups.com> <4f5bde4b.1959309002@text.giganews.com> <a64fa57d-1cf9-486c-bdf2-be3f0a1f7cab@k6g2000vbz.googlegroups.com> |
On Mon, 12 Mar 2012 07:28:32 -0700 (PDT), ImpalerCore
<jadill33@gmail.com> wrote:
>On Mar 10, 7:31=A0pm, c...@tiac.net (Richard Harter) wrote:
>> On Sat, 10 Mar 2012 14:12:17 -0800 (PST), ImpalerCore
>>
>> <jadil...@gmail.com> wrote:
>> >On Mar 10, 2:26 pm, c...@tiac.net (Richard Harter) wrote:
>> >> Suppose that I have some data that is pointer free. =3DA0It isn't
>> >> necessarily serialized in some format such as JSON but I would like to
>> >> be able to copy it from one from one machine to another compatible
>> >> machine and use it without trouble. Also I don't want to pass around
>> >> a collection of items and I want everything to be properly aligned.
>>
>> [snip remainder of statement, and comments on an approach]
>>
>> I thought of doing an align_max kind of thing but it seems to me that
>> there are problems with that. =A0One is that align_max is not a C89
>> thing and that is one of the constraints. =A0A second is that it gets a
>> bit cumbersome.
>
>The union and offsetof approach works well enough to use on C89. It's
>just that the value of ALIGN_MAX is not guaranteed as it would be in
>C11. I don't have C11, and in my limited experience, I haven't run
>into issues using this construct on C89 compilers.
>
>> I thought of using a bit of anti-social casting. =A0Start out with
>>
>> =A0 =A0 struct load_package {
>> =A0 =A0 =A0 =A0 data_type type;
>> =A0 =A0 =A0 =A0 size_t =A0 =A0total_len;
>> =A0 =A0 =A0 =A0 size_t =A0 =A0data_len;
>> =A0 =A0 =A0 =A0 int =A0 =A0 =A0 offset;
>> =A0 =A0 =A0 =A0 T =A0 =A0 =A0 =A0 data;
>> =A0 =A0 };
>>
>> Then the package struct is the same as the load_package struct except
>> for the final char[] hack. =A0Compute the offset of the data, stuff it
>> in the struct, and blithely set
>>
>> =A0 =A0 =A0 =A0 pkg =3D (struct package *)&load_pkg;
>>
>> I think that works, modulo typoes, but it's a bit of a crock because
>> you need a separate struct for every data type.
>
>One option is to prepackage the data through an API that automatically
>places the package header as a prefix to the data pointer.
[snip code]
One of the things I wanted to avoid is the whole ALIGN_MAX schtick.
Its definition and usage changes across C versions; the values change
across implementations. I like my code to be as free of special case
code as possible. Just a superstition, you know.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
What is the right way to do this simple thing cri@tiac.net (Richard Harter) - 2012-03-10 19:26 +0000
Re: What is the right way to do this simple thing Don Y <this@isnotme.com> - 2012-03-10 12:57 -0700
Re: What is the right way to do this simple thing ImpalerCore <jadill33@gmail.com> - 2012-03-10 14:12 -0800
Re: What is the right way to do this simple thing cri@tiac.net (Richard Harter) - 2012-03-10 23:31 +0000
Re: What is the right way to do this simple thing Ian Collins <ian-news@hotmail.com> - 2012-03-11 13:06 +1300
Re: What is the right way to do this simple thing cri@tiac.net (Richard Harter) - 2012-03-11 00:44 +0000
Re: What is the right way to do this simple thing Ian Collins <ian-news@hotmail.com> - 2012-03-11 14:15 +1300
Re: What is the right way to do this simple thing cri@tiac.net (Richard Harter) - 2012-03-11 04:46 +0000
Re: What is the right way to do this simple thing Ian Collins <ian-news@hotmail.com> - 2012-03-11 21:27 +1300
Re: What is the right way to do this simple thing cri@tiac.net (Richard Harter) - 2012-03-11 17:23 +0000
Re: What is the right way to do this simple thing Ian Collins <ian-news@hotmail.com> - 2012-03-12 10:01 +1300
Re: What is the right way to do this simple thing cri@tiac.net (Richard Harter) - 2012-03-13 21:18 +0000
Re: What is the right way to do this simple thing Ian Collins <ian-news@hotmail.com> - 2012-03-14 10:23 +1300
Re: What is the right way to do this simple thing Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-03-11 11:59 +0000
Re: What is the right way to do this simple thing cri@tiac.net (Richard Harter) - 2012-03-11 16:51 +0000
Re: What is the right way to do this simple thing Gene <gene.ressler@gmail.com> - 2012-03-13 07:32 -0700
Re: What is the right way to do this simple thing cri@tiac.net (Richard Harter) - 2012-03-13 21:46 +0000
Re: What is the right way to do this simple thing ImpalerCore <jadill33@gmail.com> - 2012-03-12 07:28 -0700
Re: What is the right way to do this simple thing ImpalerCore <jadill33@gmail.com> - 2012-03-12 08:13 -0700
Re: What is the right way to do this simple thing cri@tiac.net (Richard Harter) - 2012-03-13 21:51 +0000
Re: What is the right way to do this simple thing Tim Rentsch <txr@alumni.caltech.edu> - 2012-03-10 14:21 -0800
Re: What is the right way to do this simple thing cri@tiac.net (Richard Harter) - 2012-03-11 01:40 +0000
Re: What is the right way to do this simple thing Tim Rentsch <txr@alumni.caltech.edu> - 2012-03-11 14:11 -0700
Re: What is the right way to do this simple thing cri@tiac.net (Richard Harter) - 2012-03-13 21:56 +0000
Re: What is the right way to do this simple thing Tim Rentsch <txr@alumni.caltech.edu> - 2012-03-14 14:55 -0700
Re: What is the right way to do this simple thing cri@tiac.net (Richard Harter) - 2012-03-15 21:55 +0000
Re: What is the right way to do this simple thing Tim Rentsch <txr@alumni.caltech.edu> - 2012-03-19 13:33 -0700
Re: What is the right way to do this simple thing Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-03-10 15:21 -0800
Re: What is the right way to do this simple thing cri@tiac.net (Richard Harter) - 2012-03-11 00:47 +0000
Re: What is the right way to do this simple thing Philip Lantz <prl@canterey.us> - 2012-03-11 01:07 -0800
Re: What is the right way to do this simple thing cri@tiac.net (Richard Harter) - 2012-03-11 16:14 +0000
Re: What is the right way to do this simple thing Markus Wichmann <nullplan@gmx.net> - 2012-03-11 13:47 +0100
Re: What is the right way to do this simple thing cri@tiac.net (Richard Harter) - 2012-03-11 16:24 +0000
Re: What is the right way to do this simple thing cri@tiac.net (Richard Harter) - 2012-03-11 21:01 +0000
Re: What is the right way to do this simple thing Anders Wegge Keller <wegge@wegge.dk> - 2012-03-12 00:05 +0100
Re: What is the right way to do this simple thing cri@tiac.net (Richard Harter) - 2012-03-13 21:57 +0000
Re: What is the right way to do this simple thing cri@tiac.net (Richard Harter) - 2012-03-11 23:06 +0000
Re: What is the right way to do this simple thing Geoff <geoff@invalid.invalid> - 2012-03-11 17:34 -0700
Re: What is the right way to do this simple thing cri@tiac.net (Richard Harter) - 2012-03-13 22:00 +0000
Re: What is the right way to do this simple thing Geoff <geoff@invalid.invalid> - 2012-03-13 18:12 -0700
Re: What is the right way to do this simple thing cri@tiac.net (Richard Harter) - 2012-03-14 03:38 +0000
Re: What is the right way to do this simple thing Geoff <geoff@invalid.invalid> - 2012-03-14 00:49 -0700
csiph-web