Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: determines if it is a signed type |
| Date | 2015-05-19 17:08 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <877fs4k0si.fsf@bsb.me.uk> (permalink) |
| References | (12 earlier) <mjdurg$2qu$1@dont-email.me> <mjf09m$v63$1@dont-email.me> <ec76f4dc-48df-4003-b045-23dbd7c5cec5@googlegroups.com> <87d21wk6k4.fsf@bsb.me.uk> <c82653e9-61b8-4591-9d81-dba647009d3b@googlegroups.com> |
jadill33@gmail.com writes: > On Tuesday, May 19, 2015 at 10:04:08 AM UTC-4, Ben Bacarisse wrote: >> jadill..@gmail.com writes: >> >> > On Tuesday, May 19, 2015 at 5:39:13 AM UTC-4, jacobnavia wrote: >> >> Le 19/05/2015 02:08, Richard Heathfield a écrit : >> >> > unsigned long will do fine >> >> >> >> In most versions of linux that will be 64 bits. If yu need to be able to >> >> index just 10000 records you are wasting 4 bytes. If you need binary >> >> compatibility of the output of a program then you can't do that. >> >> >> >> But I do not want to convince you. >> >> You want to stay in C89? Fine with me. >> > >> > Yeah, one of the strongest motivations to use stdint.h is reading/writing >> > binary protocols in files/sockets. You'll be hard pressed to avoid >> > problems on multiple platforms without using some mechanism for >> > defining fixed width types, and stdint.h is well, the standard way >> > of defining the names of those types. >> >> The exact-width types from stdint.h barely scratch the surface of this >> problem. There are representation issues (endianness being the most >> common) and packing/alignment issues if you hope to use exact-width >> types to define a struct you can just fread. > > I very rarely do any kind of serialization at the struct level. More > often it is interpreted as a sequence of fields that are read one element > at a time into a struct. Most of the time, these fields are fixed-width > 2's complement integers, strings, and the occasional IEEE-754 floats. So how does stdint.h help you with this? >> And when you have to deal with these issues the simplest solution is >> very often to store the result in native types (or to use the >> u?int_leastN_t types from stdint.h), quite possibly in a structure that >> does not map onto the protocol bytes at all. > > So, if you wanted to write an interface to write a 32-bit signed integer > and a 32-bit unsigned integers to a file stream, how would you accomplish > that without some typedef similar to those used in stdint.h? > > read_int32 > write_int32 read_int32 would return an unsigned long and write_int32 would have an unsigned long parameter. It's possible we are talking at cross purposes here. > I can't depend on the width of int, long, and friends, but maybe I'm > missing something that you see from your perspective. > > The binary format doesn't care what native type it's stored in. It cares > that the value is a 32-bit signed or unsigned 2's complement value. You > can ignore any endianness/representation issue. What do mean I can ignore it? My point was that since you almost always have to take the representation into account, having the exact size to fread or fwrite is very much less of an advantage. You're cutting my argument out from under me! >> > I feel that C90 without some kind of stdint.h wrapper is not well poised >> > to handle this problem space. >> >> That's not been my experience, unless you interpret the wrapper as being >> very thin indeed. About the only really useful typedef is for something >> a bit like int_least32_t since you can't assume int can store 32 bits >> and you may not be prepared to pay the cost of using long. > > I'm not trying to propose a solution for serialization. I'm trying to > offer motivation to use a stdint.h defined type. And in my experience, > that motivation is often enough to desire a stdint.h wrapper when limited > to C90. You mentioned protocols in files/sockets. Maybe you could give an example that motivates of the use of stdint.h for doing that? -- Ben.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
determines if it is a signed type asetofsymbols@gmail.com - 2015-05-17 10:07 -0700
Re: determines if it is a signed type Richard Heathfield <rjh@cpax.org.uk> - 2015-05-17 18:12 +0100
Re: determines if it is a signed type asetofsymbols@gmail.com - 2015-05-17 10:34 -0700
Re: determines if it is a signed type asetofsymbols@gmail.com - 2015-05-17 11:09 -0700
Re: determines if it is a signed type Kusalananda <kusalananda@example.com> - 2015-05-17 18:22 +0000
Re: determines if it is a signed type asetofsymbols@gmail.com - 2015-05-17 11:31 -0700
Re: determines if it is a signed type Kusalananda <kusalananda@example.com> - 2015-05-17 19:59 +0000
Re: determines if it is a signed type Keith Thompson <kst-u@mib.org> - 2015-05-17 13:12 -0700
Re: determines if it is a signed type Morris Dovey <mrdovey@iedu.com> - 2015-05-17 19:08 -0500
Re: determines if it is a signed type Morris Dovey <mrdovey@iedu.com> - 2015-05-17 19:46 -0500
Re: determines if it is a signed type Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-18 01:59 +0100
Re: determines if it is a signed type Morris Dovey <mrdovey@iedu.com> - 2015-05-17 20:10 -0500
Re: determines if it is a signed type Keith Thompson <kst-u@mib.org> - 2015-05-18 00:37 -0700
Re: determines if it is a signed type Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-18 21:15 +0100
Re: determines if it is a signed type Keith Thompson <kst-u@mib.org> - 2015-05-18 15:15 -0700
Re: determines if it is a signed type glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-05-18 21:51 +0000
Re: determines if it is a signed type James Kuyper <jameskuyper@verizon.net> - 2015-05-18 18:00 -0400
Re: determines if it is a signed type glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-05-18 14:37 +0000
Re: determines if it is a signed type jacobnavia <jacob@jacob.remcomp.fr> - 2015-05-18 17:09 +0200
Re: determines if it is a signed type glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-05-18 18:14 +0000
Re: determines if it is a signed type Richard Heathfield <rjh@cpax.org.uk> - 2015-05-18 06:34 +0100
Re: determines if it is a signed type Keith Thompson <kst-u@mib.org> - 2015-05-18 00:43 -0700
Re: determines if it is a signed type Richard Heathfield <rjh@cpax.org.uk> - 2015-05-18 13:56 +0100
Re: determines if it is a signed type Keith Thompson <kst-u@mib.org> - 2015-05-18 08:00 -0700
Re: determines if it is a signed type Richard Heathfield <rjh@cpax.org.uk> - 2015-05-18 20:35 +0100
Re: determines if it is a signed type jacobnavia <jacob@jacob.remcomp.fr> - 2015-05-18 23:08 +0200
Re: determines if it is a signed type Richard Heathfield <rjh@cpax.org.uk> - 2015-05-18 22:32 +0100
Re: determines if it is a signed type jacobnavia <jacob@jacob.remcomp.fr> - 2015-05-19 00:44 +0200
Re: determines if it is a signed type Richard Heathfield <rjh@cpax.org.uk> - 2015-05-19 00:05 +0100
Re: determines if it is a signed type jacobnavia <jacob@jacob.remcomp.fr> - 2015-05-19 01:43 +0200
Re: determines if it is a signed type Richard Heathfield <rjh@cpax.org.uk> - 2015-05-19 01:08 +0100
Re: determines if it is a signed type "Bartc" <bartc@freeuk.com> - 2015-05-19 11:33 +0100
Re: determines if it is a signed type Keith Thompson <kst-u@mib.org> - 2015-05-19 08:15 -0700
Re: determines if it is a signed type "Bartc" <bartc@freeuk.com> - 2015-05-19 19:36 +0100
Re: determines if it is a signed type Keith Thompson <kst-u@mib.org> - 2015-05-19 11:55 -0700
Re: determines if it is a signed type jacobnavia <jacob@jacob.remcomp.fr> - 2015-05-19 11:39 +0200
Re: determines if it is a signed type "Bartc" <bartc@freeuk.com> - 2015-05-19 11:44 +0100
Re: determines if it is a signed type jacobnavia <jacob@jacob.remcomp.fr> - 2015-05-19 12:11 +0200
Re: determines if it is a signed type jadill33@gmail.com - 2015-05-19 05:45 -0700
Re: determines if it is a signed type Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-19 15:03 +0100
Re: determines if it is a signed type jadill33@gmail.com - 2015-05-19 08:46 -0700
Re: determines if it is a signed type Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-19 17:08 +0100
Re: determines if it is a signed type jadill33@gmail.com - 2015-05-19 09:52 -0700
Re: determines if it is a signed type Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-19 20:36 +0100
Re: determines if it is a signed type jadill33@gmail.com - 2015-05-20 07:40 -0700
Re: determines if it is a signed type Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-20 23:12 +0100
Re: determines if it is a signed type jadill33@gmail.com - 2015-05-21 13:52 -0700
Re: determines if it is a signed type Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-21 22:48 +0100
Re: determines if it is a signed type jadill33@gmail.com - 2015-05-22 05:50 -0700
Re: determines if it is a signed type Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-22 23:14 +0100
Re: determines if it is a signed type jadill33@gmail.com - 2015-05-26 14:31 -0700
Re: determines if it is a signed type Tim Rentsch <txr@alumni.caltech.edu> - 2015-05-22 23:32 -0700
Re: determines if it is a signed type David Brown <david.brown@hesbynett.no> - 2015-05-20 12:26 +0200
Re: determines if it is a signed type Richard Heathfield <rjh@cpax.org.uk> - 2015-05-19 15:28 +0100
Re: determines if it is a signed type raltbos@xs4all.nl (Richard Bos) - 2015-05-23 10:37 +0000
Re: determines if it is a signed type Keith Thompson <kst-u@mib.org> - 2015-05-18 15:21 -0700
Re: determines if it is a signed type Richard Heathfield <rjh@cpax.org.uk> - 2015-05-19 00:04 +0100
Re: determines if it is a signed type Keith Thompson <kst-u@mib.org> - 2015-05-19 08:03 -0700
Re: determines if it is a signed type David Brown <david.brown@hesbynett.no> - 2015-05-19 08:47 +0200
Re: determines if it is a signed type Keith Thompson <kst-u@mib.org> - 2015-05-19 08:07 -0700
Re: determines if it is a signed type James Kuyper <jameskuyper@verizon.net> - 2015-05-18 11:28 -0400
Re: determines if it is a signed type Keith Thompson <kst-u@mib.org> - 2015-05-18 00:40 -0700
csiph-web