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


Groups > comp.lang.c > #95766

Re: A postfix pointer deference

From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.c
Subject Re: A postfix pointer deference
Date 2016-11-04 16:44 +0000
Organization A noiseless patient Spider
Message-ID <87shr7gppk.fsf@bsb.me.uk> (permalink)
References <75137756-7d3c-440a-9749-c8ffdb228193@googlegroups.com> <877f8jilb2.fsf@bsb.me.uk> <4eb1b0a9-a1f2-43c0-8508-252638d26a30@googlegroups.com>

Show all headers | View raw


luser droog <luser.droog@gmail.com> writes:

> On Friday, November 4, 2016 at 5:36:31 AM UTC-5, Ben Bacarisse wrote:
>> luser droog <luser.droog@gmail.com> writes:
>> 
>> > #define REF [0]
>> >
>> > char *s = "hello";
>> > for(int i=0,n=strlen(s); i<n; i++)
>> >     putchar(s++ REF);
>> 
>> Why?  The usual idiom is *s++ and the whole loop would, most likely, not
>> be written using a counter:
>> 
>>   while (*s) putchar(*s++);
>> 
>> (I'm sure the putchar is just an example otherwise I'd suggest
>> fputs(s, stdout);)
>> 
>> Also, I'm not sure how the macro is helping.  Is the whole thing
>> intended to be a bit mysterious?
>
> In another thread there was a lot of talk about needing a postfix 
> deref operator like Pascal. I just wanted to point out (without 
> directly engaging anyone in that thread) that we already have one.

Ah, I see.  Yes, C almost has one, but since BartC dislikes the fact
that, in some situations, * needs ()s he's unlikely to want to use [0].

I say "almost" because there is a corner case where *E is permitted but
E[0] is not: &*E is a no-op (other than checking the type of E) but
&E[0] requires that E+0 is permitted, and that fails for incomplete
types even though the result is surely obvious.

-- 
Ben.

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


Thread

A postfix pointer deference luser droog <luser.droog@gmail.com> - 2016-11-03 22:43 -0700
  Re: A postfix pointer deference fir <profesor.fir@gmail.com> - 2016-11-04 02:09 -0700
    Re: A postfix pointer deference fir <profesor.fir@gmail.com> - 2016-11-04 02:22 -0700
  Re: A postfix pointer deference Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-11-04 10:36 +0000
    Re: A postfix pointer deference luser droog <luser.droog@gmail.com> - 2016-11-04 08:53 -0700
      Re: A postfix pointer deference Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-11-04 16:44 +0000

csiph-web