Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #142782

Re: memcpy or assign data to uint64 on little endian(linux) system

From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.c
Subject Re: memcpy or assign data to uint64 on little endian(linux) system
Date 2019-04-03 16:06 +0100
Organization A noiseless patient Spider
Message-ID <87v9zvjfhj.fsf@bsb.me.uk> (permalink)
References <3b06fd96-348b-423c-af57-e44e1f79b40c@googlegroups.com> <e7i8ae1tc2d5n01e6gsgahck4dinccsh1j@4ax.com> <slrn3t4oqa8jpn.j6n.ike@iceland.freeshell.org> <877ecbl7uz.fsf@bsb.me.uk> <slrnqa9bcr.4jo.grahn+nntp@frailea.sa.invalid>

Show all headers | View raw


Jorgen Grahn <grahn+nntp@snipabacken.se> writes:

> On Wed, 2019-04-03, Ben Bacarisse wrote:
>> Ike Naar <ike@iceland.freeshell.org> writes:
>>
>>> On 2019-04-03, Geoff <geoff@invalid.invalid> wrote:
>>>> On Tue, 2 Apr 2019 18:14:31 -0700 (PDT), WalkeR Park
>>>>>=================================================
>>>>>        uint64 a;
>>>>>        char b[8] = {0x38, 0x12, 0x12, 0x12, 0x81, 0x28, 0x28, 0x28};
>>>>>        memcpy(&a, b, 8);
>>>>>        printf("TEST [%lu]\n", a);
>>>>>=================================================
> ...
>
>> It looks like a thorough and careful isolation of all the parts the assume
>> byte order is needed.
>
> Yes.  It can be a long and painful procedure, and you learn to hate
> the people who wrote the original, broken code.
>
> My primary recommendation would be to normalize the data close to the
> I/O, at the edge.  Don't end up in the situation where the main
> program logic deals with a mix or native and foreign numbers, and you
> need to keep track of which int is a real integer and which isn't.

That's a good point.  It can be tempting, in the name of efficiency, to
leave some data alone as it comes into the program because you can see
that it's going out again pretty soon, but avoiding the two conversions
can be a false economy.

The I/O boundary is usually easy to identify so it is a good idea to try
to sort the problem our there.

-- 
Ben.

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

memcpy or assign data to uint64 on little endian(linux) system WalkeR Park <walker.ykpark@gmail.com> - 2019-04-02 18:14 -0700
  Re: memcpy or assign data to uint64 on little endian(linux) system Geoff <geoff@invalid.invalid> - 2019-04-02 22:49 -0700
    Re: memcpy or assign data to uint64 on little endian(linux) system Ike Naar <ike@iceland.freeshell.org> - 2019-04-03 06:14 +0000
      Re: memcpy or assign data to uint64 on little endian(linux) system Geoff <geoff@invalid.invalid> - 2019-04-02 23:22 -0700
      Re: memcpy or assign data to uint64 on little endian(linux) system Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-04-03 11:07 +0100
        Re: memcpy or assign data to uint64 on little endian(linux) system Jorgen Grahn <grahn+nntp@snipabacken.se> - 2019-04-03 12:56 +0000
          Re: memcpy or assign data to uint64 on little endian(linux) system fir <profesor.fir@gmail.com> - 2019-04-03 06:52 -0700
          Re: memcpy or assign data to uint64 on little endian(linux) system Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-04-03 16:06 +0100
  Re: memcpy or assign data to uint64 on little endian(linux) system fir <profesor.fir@gmail.com> - 2019-04-03 04:03 -0700
    Re: memcpy or assign data to uint64 on little endian(linux) system fir <profesor.fir@gmail.com> - 2019-04-03 04:13 -0700
  Re: memcpy or assign data to uint64 on little endian(linux) system Jorgen Grahn <grahn+nntp@snipabacken.se> - 2019-04-03 12:37 +0000
  Re: memcpy or assign data to uint64 on little endian(linux) system Ike Naar <ike@iceland.freeshell.org> - 2019-04-03 16:10 +0000
    Re: memcpy or assign data to uint64 on little endian(linux) system Keith Thompson <kst-u@mib.org> - 2019-04-03 12:50 -0700

csiph-web