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


Groups > comp.lang.c > #107696

Re: Interpret this C code

From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.c
Subject Re: Interpret this C code
Date 2017-04-03 21:04 +0100
Organization A noiseless patient Spider
Message-ID <877f31xnox.fsf@bsb.me.uk> (permalink)
References <ee7d53aa-9688-46e5-9dcb-d2a68cb5f31f@googlegroups.com> <87poh0v2cl.fsf@bsb.me.uk> <MPG.334b939561f58a63136@news.eternal-september.org>

Show all headers | View raw


Philip Lantz <prl@canterey.us> writes:

> Ben Bacarisse wrote:
>
>> > # define c2ln(c,l1,l2,n) { \
>> >                         c+=n; \
>> >                         l1=l2=0; \
>> >                         switch (n) { \
>> >                         case 8: l2 =((unsigned long)(*(--(c))))<<24; \
>> >                         case 7: l2|=((unsigned long)(*(--(c))))<<16; \
>> >                         case 6: l2|=((unsigned long)(*(--(c))))<< 8; \
>> >                         case 5: l2|=((unsigned long)(*(--(c))));     \
>> >                         case 4: l1 =((unsigned long)(*(--(c))))<<24; \
>> >                         case 3: l1|=((unsigned long)(*(--(c))))<<16; \
>> >                         case 2: l1|=((unsigned long)(*(--(c))))<< 8; \
>> >                         case 1: l1|=((unsigned long)(*(--(c))));     \
>> >                                 } \
>> >                         }
>> 
>> A thing to note is that, in C, the switch statement "falls through", so
>> here the switch simply determines where to start.  It can, in effect,
>> read a big-endian integer of any size from 1 to 8 bytes.  (It has a
>> small technical flaw, in that it is not permitted to decrement a pointer
>> that points to the start of an object, and this this macro may do that.
>> ...)
>
> Might it? It appears to me that c always ends up pointing to the same place
> that it started.* Am I missing something?

No, you are right.  I was jumping to conclusions.  The prefix operator
is the correct way here.

<snip>
-- 
Ben.

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


Thread

Interpret this C code blackhat401@gmail.com - 2017-03-28 17:50 -0700
  Re: Interpret this C code Jorgen Grahn <grahn+nntp@snipabacken.se> - 2017-03-29 05:43 +0000
  Re: Interpret this C code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-03-29 10:50 +0100
    Re: Interpret this C code Philip Lantz <prl@canterey.us> - 2017-04-03 00:03 -0700
      Re: Interpret this C code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-04-03 21:04 +0100
  Re: Interpret this C code praveen.bochetty@gmail.com - 2017-03-29 17:24 -0700

csiph-web