Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming > #2504
| From | BGB <cr88192@hotmail.com> |
|---|---|
| Newsgroups | comp.programming |
| Subject | Re: little-endian |
| Date | 2012-11-18 03:03 -0600 |
| Organization | albasani.net |
| Message-ID | <k8a8fd$epd$1@news.albasani.net> (permalink) |
| References | (7 earlier) <agqab0F2uveU1@mid.individual.net> <7otfa8pfb07sn1ao039nlfc9cr351h2vtr@4ax.com> <k892t5$p77$1@news.albasani.net> <agquqgF2uveU2@mid.individual.net> <1d8xuw93lwnxy.14j0ojrkbbe4e$.dlg@40tude.net> |
On 11/18/2012 2:13 AM, Dmitry A. Kazakov wrote: > On Sun, 18 Nov 2012 15:17:51 +1300, Ian Collins wrote: > >> On 11/18/12 11:22, BGB wrote: >>>> Some more valid criticisms of the hton*/ntoh* functions are that they >>>> only support one byte order on the "network" side, support only a >>>> couple of sizes, and only support unsigned values. >> >> long long version are a simple extension. > > Nope. It could be middle-endian. > >> The signed or unsigned nature >> of the type isn't relevant for byte ordering. > > How so? Byte ordering is about encoding things into a byte stream. Signed > integers must be encoded too. > yeah. signed vs unsigned storage is an issue all to itself. >>> far more common I think is to implement file-readers more like: >>> int MyFile_ReadInt32LE(FILE *fd) >> >> The reason for using the common byte ordering functions is to avoid >> having to care about the ordering on the wire (or in a file). > > There are far more types of objects than unsigned integers. When > implementing an application protocol on top of some octet or bit stream > these must be encoded and decoded (serialized/deserialozed) too. There is > nothing special in unsigned integers. > > Usage of functions like hton* should be depreciated unless the protocol > specification explicitly states that the given unsigned integer object is > in the "network" format as implemented by hton*. > yeah. hton* and ntoh* make sense when dealing with socket-related stuff, but don't make nearly as much sense when dealing with file-formats. typically, the layout of data within a file-format is a fairly important part of the file-format, and not really all that consistent between one file format and the next, and sometimes you are lucky even if all of the members within the same file-format have the same ordering. worse-still is fileformats where the designer thought about being clever and defining the endianess as "whatever was convenient for the writer program", which basically amounts to the reader having to keep track of a flag for which endianess the file was stored in. > It is always cleaner to provide a fair implementation of the protocol, > which could be done in a portable way as BGB described. Which is really the > recommended way. A rare exception might be when you have a library that > already implements the protocol layer of interest completely. > yeah. or when dealing with file-formats. with explicit reader/writer functions, it is also fairly straightforward to write functions to deal with pretty much any types the format may include, including things like variable-length integers, and values of types which don't necessarily start/end on a byte-boundary (common with bitstreams). typically, any structures used are kept purely internal, and the exact layouts and types of data present in a file are not tied to the structs (and how the particular compiler and target has decided that they should be laid out), and it isn't really that much more effort to read/write all of the members directly via function calls, than it is to read/write structs and swizzle the values afterwards. other times (depending on how the format is used), it may make sense to use structs, but simply define all of the members as byte-arrays, and then use functions to read/write the values from the structures (this makes things like type-alignment largely a non-issue).
Back to comp.programming | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
little-endian bob <bob@coolfone.comze.com> - 2012-11-15 13:45 -0800
Re: little-endian JJ <jaejunks@glegooilma-swapit.com> - 2012-11-15 23:33 +0000
Re: little-endian bob <bob@coolfone.comze.com> - 2012-11-16 10:38 -0800
Re: little-endian "Pascal J. Bourguignon" <pjb@informatimago.com> - 2012-11-16 23:32 +0100
Re: little-endian BGB <cr88192@hotmail.com> - 2012-11-16 21:17 -0600
Re: little-endian "Pascal J. Bourguignon" <pjb@informatimago.com> - 2012-11-17 10:26 +0100
Re: little-endian "BartC" <bc@freeuk.com> - 2012-11-17 11:38 +0000
Re: little-endian "Pascal J. Bourguignon" <pjb@informatimago.com> - 2012-11-17 13:56 +0100
Re: little-endian BGB <cr88192@hotmail.com> - 2012-11-17 11:58 -0600
Re: little-endian Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-11-17 19:35 +0000
Re: little-endian "BartC" <bc@freeuk.com> - 2012-11-17 19:50 +0000
Re: little-endian BGB <cr88192@hotmail.com> - 2012-11-17 11:30 -0600
Re: little-endian Ian Collins <ian-news@hotmail.com> - 2012-11-18 09:28 +1300
Re: little-endian Robert Wessel <robertwessel2@yahoo.com> - 2012-11-17 14:48 -0600
Re: little-endian BGB <cr88192@hotmail.com> - 2012-11-17 16:22 -0600
Re: little-endian Ian Collins <ian-news@hotmail.com> - 2012-11-18 15:17 +1300
Re: little-endian "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2012-11-18 09:13 +0100
Re: little-endian Ian Collins <ian-news@hotmail.com> - 2012-11-18 21:33 +1300
Re: little-endian "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2012-11-18 10:15 +0100
Re: little-endian BGB <cr88192@hotmail.com> - 2012-11-18 03:03 -0600
Re: little-endian "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2012-11-18 10:29 +0100
Re: little-endian BGB <cr88192@hotmail.com> - 2012-11-18 12:50 -0600
Re: little-endian Robin Vowels <robin.vowels@gmail.com> - 2012-11-22 04:49 -0800
Re: little-endian Jongware <jongware@no-spam.plz> - 2012-11-23 15:22 +0100
Re: little-endian pacman@kosh.dhis.org (Alan Curry) - 2012-11-25 19:39 +0000
Re: little-endian Jongware <jongware@no-spam.plz> - 2012-11-26 12:01 +0100
Re: little-endian "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2012-11-26 14:02 +0100
Re: little-endian Jongware <jongware@no-spam.plz> - 2012-11-26 15:34 +0100
Re: little-endian "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2012-11-26 17:03 +0100
Re: little-endian Robert Wessel <robertwessel2@yahoo.com> - 2012-11-26 17:44 -0600
Re: little-endian Robin Vowels <robin.vowels@gmail.com> - 2012-11-28 23:43 -0800
Re: little-endian Robert Wessel <robertwessel2@yahoo.com> - 2012-11-29 22:46 -0600
Re: little-endian BGB <cr88192@hotmail.com> - 2012-11-26 08:30 -0600
Re: little-endian Robin Vowels <robin.vowels@gmail.com> - 2012-11-28 23:45 -0800
csiph-web