Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Uses for an exchange instruction?

Received: by 10.180.86.97 with SMTP id o1mr1346181wiz.2.1351391175068;
        Sat, 27 Oct 2012 19:26:15 -0700 (PDT)
MIME-Version: 1.0
Path: q13ni70624wii.0!nntp.google.com!feeder3.cambriumusenet.nl!feed.tweaknews.nl!85.12.40.130.MISMATCH!xlned.com!feeder1.xlned.com!border2.nntp.ams.giganews.com!nntp.giganews.com!news.panservice.it!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!rt.uk.eu.org!nntp-feed.chiark.greenend.org.uk!ewrotcd!.POSTED!not-for-mail
From: n...@cam.ac.uk
Newsgroups: comp.arch
Subject: Re: Uses for an exchange instruction?
Date: Mon, 22 Oct 2012 09:03:08 +0100 (BST)
Organization: Department of Deniable Assertions
Lines: 68
Sender: n...@needham.csi.cam.ac.uk
Message-ID: <k62ujs$ut9$1@needham.csi.cam.ac.uk>
References: <1396c202-b405-4a7f-ad0a-8d73a43ebdea@googlegroups.com> <50841750.E55B9A60@bytecraft.com> <k616s1$mq7$1@needham.csi.cam.ac.uk> <k61j3g$3n8$1@dont-email.me>
Reply-To: n...@cam.ac.uk
NNTP-Posting-Host: chiark.greenend.org.uk
X-Trace: chiark.greenend.org.uk 1350893031 30404 212.13.197.229 (22 Oct 2012 08:03:51 GMT)
X-Complaints-To: abuse@chiark.greenend.org.uk
NNTP-Posting-Date: Mon, 22 Oct 2012 08:03:51 +0000 (UTC)
Originator: @needham.csi.cam.ac.uk ([131.111.10.113])
Bytes: 3744

In article <k61j3g$3n...@dont-email.me>,
Stephen Sprunk  <step...@sprunk.org> wrote:
>
>That's why I disregarded the (more obvious, to me) parenthesis syntax;
>the following already has a defined meaning:
>
>(quotient, remainder) = divmod6432(dividend, divisor);
>
>which, AFAICT, would parse as this:
>
>remainder = divmod6432(dividend, divisor);
>
>except that I'm not sure the LHS would be an lvalue, and even if it were
>there would be an obvious type mismatch and the quotient would get lost.

It isn't, and there could be yet another syntactic kludge, just as
there was for the comma operator and function calls in an early version
of the C90 standard.  But, yes, that was and is one reason.

>> But my point stands.  Pascal does not have the same syntactic
>> horrors - for example, assignment is a statement (like in
>> Fortran) - but the real problem is in the semantic horrors,
>> which are made worse by allowing this.  For example
>> 
>>     int * a, * b;
>>     {a[5],b[10]} = ({a[10],b[5]} += {3,2});
>> 
>> And, of course, that's a simple case.
>
>Well, I would never think of writing such a monstrosity, but its meaning
>is obviously (to me) equivalent to this:
>
>a[5] = a[10] += 3,
>b[10] = b[5] += 2;
>
>except that there is no sequence point between the two, so it would be
>undefined if a==b or a and b overlapped in certain ways.

Er, that's only C90 and (to a great extent) C99.  C11 has changed
all that, in ways which are completely unclear.  Inter alia, shared
memory parallelism exposes issues that can be ignored in sequential
code.

>OTOH, using braces results in something that is not a compound statement
>because there is no internal ";", so the only logical way to parse it is
>as an anonymous struct.

Er, no.  I would need to study the various standards, but braces are
seriously overused even in C99, and words fail me about the ways that
they can cause chaos in C++.  However, even in the simple case, you
are delaying the classification of the contents of the braces until
you reach the closing brace (and possibly the following operator),
which is a new and alien concept to the C syntactic model.  It is
still a one-pass parsing model, even if C99 broke that for such
things as whether functions are external or not.

>> The only simple resolution would be to create the concept of an
>> assignment statement, but I am pretty sure that wouldn't solve the
>> issues in C11 or be acceptable to C++.
>
>Why would you need an assignment statement to make anonymous structs work?

Because an assignment expression delivers an lvalue.  Such a nonce
struct of references is not and cannot be an lvalue.


Regards,
Nick Maclaren.