Re: silly question: prefix vs postfix ops

Tony Finch <dot@dotat.at>
04 Mar 2008 14:20:02 +0000 (GMT)

          From comp.compilers

Related articles
silly question: prefix vs postfix ops rosing@peakfive.com (MattR) (2008-03-03)
Re: silly question: prefix vs postfix ops csaavedra@alumnos.utalca.cl (Claudio Saavedra) (2008-03-03)
Re: silly question: prefix vs postfix ops mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2008-03-03)
Re: silly question: prefix vs postfix ops gah@ugcs.caltech.edu (glen herrmannsfeldt) (2008-03-03)
Re: silly question: prefix vs postfix ops haberg_20080207@math.su.se (Hans Aberg) (2008-03-03)
Re: silly question: prefix vs postfix ops marcov@stack.nl (Marco van de Voort) (2008-03-03)
Re: silly question: prefix vs postfix ops gah@ugcs.caltech.edu (glen herrmannsfeldt) (2008-03-04)
Re: silly question: prefix vs postfix ops dot@dotat.at (Tony Finch) (2008-03-04)
Re: silly question: prefix vs postfix ops rpboland@gmail.com (Ralph Boland) (2008-03-04)
Re: silly question: prefix vs postfix ops alexc@TheWorld.com (Alex Colvin) (2008-03-05)
Re: silly question: prefix vs postfix ops DrDiettrich1@aol.com (Hans-Peter Diettrich) (2008-03-06)
| List of all articles for this month |

From: Tony Finch <dot@dotat.at>
Newsgroups: comp.compilers
Date: 04 Mar 2008 14:20:02 +0000 (GMT)
Organization: dotat labs
References: 08-03-012
Keywords: syntax, design, history
Posted-Date: 04 Mar 2008 09:34:08 EST

MattR <rosing@peakfive.com> wrote:
>
>Anyway, why are there prefix operators that could just as well be
>postfix? Why is it !a and not a!, or *a and not a* ? I can understand
>the increment and decrement operators, and the & op but expressions like
>*a[i] would be a lot clearer if it were a[i]*, just read the operators
>from right to left. Is it a case of, well, it's always been done this way?


Many people have observed that C's syntax could be hugely improved by
replacing prefix * with a postfix dereference operator like Pascal's.
Ben Werther & Damian Conway probably wrote up the most comprehensive
description of an improved syntax for C++. See
http://www.csse.monash.edu.au/~damian/papers/HTML/ModestProposal.html


To answer why C has such bad syntax for pointers, you should look at BCPL.
It had two indirection operators, !ptr and ptr!offset. The former turned
into C's *ptr and the latter split into ptr[offset] and ptr->offset.
The precedence and associativity of ! make most expressions quite
convenient. The only C-like awkward case is dealing with pointers to
functions, as in (ptr!offset)(args). C evolved while it was being used
which made it too hard to replace the residual BCPLisms with something
more usable with C's more typeful features.


Tony.
--
f.a.n.finch <dot@dotat.at> http://dotat.at/
FISHER: NORTHWEST 5 TO 7, PERHAPS GALE 8 LATER. ROUGH OR VERY ROUGH. WINTRY
SHOWERS. MODERATE OR GOOD.


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.