Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming > #4772
| From | BGB <cr88192@hotmail.com> |
|---|---|
| Newsgroups | comp.programming |
| Subject | Re: gcc-4.x.x and endianess |
| Date | 2014-09-15 06:18 -0500 |
| Organization | albasani.net |
| Message-ID | <lv6i4c$ujs$1@news.albasani.net> (permalink) |
| References | <lv2rp2$e89$1@speranza.aioe.org> <m9su0868osqi.od5en2j049hq$.dlg@40tude.net> <lv4qee$nra$1@speranza.aioe.org> <1szke6pe4wjgd$.wpsri6v7srjm.dlg@40tude.net> <87iokpkj4a.fsf@bsb.me.uk> |
On 9/14/2014 4:05 PM, Ben Bacarisse wrote: > "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> 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? > in my scripting language, it is possible to use modifiers which declare explicit endianess, which effect storage of the datatypes in some cases, but the VM can ignore it if it will have no effect (typically in function arguments and local variables). I have wanted similar in C a few times. my custom C frontend adds a few modifiers, but isn't really usable at present. otherwise, in C one needs to use wrapper functions, which work but are often less convenient. a wrapper can though be made to work with different compilers. a "safer" way to glue it onto C proper would probably be via compiler intrinsics. how does one do it in functions? load/save in terms of bytes and shifts, which is simple/portable but not particularly efficient; rely on machine-specific load/store behavior in cases where it is applicable (such as x86 and newer ARM having unaligned little-endian loads/stores); use inline ASM, where one can utilize specific CPU instructions to handle the endianess efficiently (for example, on x86 one can use "BSWAP", ...). though, granted, being able to be like: i=*(__bigendian __unaligned __int32 *)cs; would be convinient, even if: i=bgbbtj_gets32be(cs); is both more portable and more compact in this case. more often the modifiers would be used in struct declarations (where the struct can be declared in a way which makes it, theoretically, machine-independent).
Back to comp.programming | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
gcc-4.x.x and endianess "Bill Cunningham" <nospam@nspam.invalid> - 2014-09-13 21:41 -0400
Re: gcc-4.x.x and endianess "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2014-09-14 09:14 +0200
Re: gcc-4.x.x and endianess "Bill Cunningham" <nospam@nspam.invalid> - 2014-09-14 15:31 -0400
Re: gcc-4.x.x and endianess "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2014-09-14 21:38 +0200
Re: gcc-4.x.x and endianess Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-09-14 22:05 +0100
Re: gcc-4.x.x and endianess "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2014-09-15 09:40 +0200
Re: gcc-4.x.x and endianess Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-09-15 11:51 +0100
Re: gcc-4.x.x and endianess "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> - 2014-09-15 13:49 +0100
Re: gcc-4.x.x and endianess "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2014-09-15 17:16 +0200
Re: gcc-4.x.x and endianess Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-09-15 22:23 +0100
Re: gcc-4.x.x and endianess "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2014-09-16 10:44 +0200
Re: gcc-4.x.x and endianess Kaz Kylheku <kaz@kylheku.com> - 2014-09-16 00:18 +0000
Re: gcc-4.x.x and endianess BGB <cr88192@hotmail.com> - 2014-09-15 06:18 -0500
Re: gcc-4.x.x and endianess "Bill Cunningham" <nospam@nspam.invalid> - 2014-09-15 14:23 -0400
Re: gcc-4.x.x and endianess "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2014-09-15 21:08 +0200
Re: gcc-4.x.x and endianess "Bill Cunningham" <nospam@nspam.invalid> - 2014-09-15 19:32 -0400
Re: gcc-4.x.x and endianess Richard Heathfield <invalid@see.sig.invalid> - 2014-09-15 21:07 +0100
Re: gcc-4.x.x and endianess "Bill Cunningham" <nospam@nspam.invalid> - 2014-09-15 21:48 -0400
Re: gcc-4.x.x and endianess Jongware <jongware@no-spam.plz> - 2014-09-15 10:57 +0200
Re: gcc-4.x.x and endianess "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> - 2014-09-15 14:06 +0100
Re: gcc-4.x.x and endianess "Bill Cunningham" <nospam@nspam.invalid> - 2014-09-15 21:50 -0400
Re: gcc-4.x.x and endianess "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> - 2014-09-17 09:54 +0100
Re: gcc-4.x.x and endianess "Bill Cunningham" <nospam@nspam.invalid> - 2014-09-17 22:29 -0400
csiph-web