Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!newsfeed.datemas.de!feeder.erje.net!eu.feeder.erje.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Ian Collins Newsgroups: comp.programming Subject: Re: little-endian Date: Sun, 18 Nov 2012 15:17:51 +1300 Lines: 64 Message-ID: References: <2f491c75-8fbc-4dca-9abe-f11e784454a2@googlegroups.com> <87r4ntp4b1.fsf@informatimago.com> <87mwygpolg.fsf@informatimago.com> <7otfa8pfb07sn1ao039nlfc9cr351h2vtr@4ax.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net Xz5xyM3utee23cAvsX8AdA3OIsrdQ2XF5DsPSw87dm06as4Z9BnLZeAOwQWZW12ajV Cancel-Lock: sha1:PohRHJIqJVzuiZbXoicpss8Nhec= User-Agent: Mozilla/5.0 (X11; SunOS i86pc; rv:12.0) Gecko/20120423 Thunderbird/12.0 In-Reply-To: Xref: csiph.com comp.programming:2501 On 11/18/12 11:22, BGB wrote: > On 11/17/2012 2:48 PM, Robert Wessel wrote: >> On Sun, 18 Nov 2012 09:28:16 +1300, Ian Collins >> wrote: >> >>> On 11/18/12 06:30, BGB wrote: >>>> >>>> typically, a person may develop and use functions like: >>>> ReadInt32BE >>>> and WriteInt64LE and similar, and use these for most of the encoding. >>> >>> Typically a programmer will use the utilities their platform provides. >>> > > typically a programmer will do whatever is most convenient at the moment. Which tends not to involve reinventing wheels! >>>> also, a big downside of using htonl and ntohl as a general mechanism is >>>> that it makes all of ones' libraries need to depend on winsock. >>> >>> That's silly on at least three counts: >>> >>> 1) the whole would doesn't revolve around windows. >>> >>> 2) those utility functions are usually implemented in-line (typically as >>> macros), so there isn't a library dependency. >>> >>> 3) if you are sending data over IP, you need the socket libraries one >>> way or another! >> > > you still have to include "winsock.h" or "sys/socket.h" (on Linux), and > all the relevant #ifdef's, ..., or similar, which means that they don't > really make sense except for code dealing with sockets. The headers take care of the relevant defines. > for most "general" file reader/writer code, it doesn't make sense to > have such dependencies. Unless you want to avoid wheel reinventing... >> 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. The signed or unsigned nature of the type isn't relevant for byte ordering. > and they only do direct value -> value mappings... Which is their purpose. > 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). -- Ian Collins