Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: comp.programming Subject: Re: gcc-4.x.x and endianess Date: Mon, 15 Sep 2014 11:51:29 +0100 Organization: A noiseless patient Spider Lines: 65 Message-ID: <87sijt40ni.fsf@bsb.me.uk> References: <1szke6pe4wjgd$.wpsri6v7srjm.dlg@40tude.net> <87iokpkj4a.fsf@bsb.me.uk> <1ttpptlnkgub7.1j69kxtbpmeax$.dlg@40tude.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx05.eternal-september.org; posting-host="017616aa25f81ec581c44d76d61ba2f3"; logging-data="21833"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18rvjcE544HQWmWDwtKz/6yaMBI48xZpIQ=" Cancel-Lock: sha1:Sxp2N0g53Q4Uu/F6RU111HSEz24= sha1:0n1fACnOmOnz8SDOpYWrhfT1ikw= X-BSB-Auth: 1.da0742432f1c883a4588.20140915115130BST.87sijt40ni.fsf@bsb.me.uk Xref: csiph.com comp.programming:4771 "Dmitry A. Kazakov" writes: > On Sun, 14 Sep 2014 22:05:57 +0100, Ben Bacarisse wrote: > >> "Dmitry A. Kazakov" writes: >> >>> On Sun, 14 Sep 2014 15:31:31 -0400, Bill Cunningham wrote: >>> >>>> I just write in C. With some >>>> machines you have to re-write code because of the machine's endianess. That >>>> might only be with assembley and old assemblers I don't know. >>> >>> That depends on how the code is written. With C chances are high, because >>> it does not offer any means to handle endianness nor to declare types in a >>> machine-independent way. But I guess people like C mostly for its >>> deficiencies. >> >> What means do other languages offer to handle endianness? > > 1. Types declared in problem space terms, when it is machine-independent > and, thus, endianness-agnostic. You seemed to draw a distinction between machine-independent types and handling endianness. The former I understand, it was the latter I was unclear about. > Like: > > type Salary is range 0..1_000_000; -- I don't care about endianness Are there any languages where the basic types *do* care about endianness? What would that look like from the point of view of the program? > [ which also presumes that the language does not provide means to expose > endianness through legal operations defined on the type. E.g. whatever you > write with the type the result would not depend on the endianness. In C you > have shifts and type casts which expose endinness. That's a common misconception about shifts in C. It is also a common misconception that casts expose endianness. Obviously C *can* reveal the representation of its types (though pointers and unions for example) but casts are defined as value conversions in C. > In a safe language such > things if exist then guarded against unintentional use. ] > > 2. Control over the type representation aspects (endianness is one of them) > when it must really be machine-dependent. E.g. see here > > http://en.wikibooks.org/wiki/Ada_Programming/Attributes/%27Bit_Order I'm not sure which part of that page you are referring to because t does not seem to be directly related to handling endianness. In the end it says: "The 'Bit_Order attribute is not intended to convert data between a big-endian and a little-endian machine (it affects bit numbering, not byte order)." Could you give an example of an endianness problem that is solved using this attribute? -- Ben.