Re: Origins of == in C

jmccarty@spdmail.spd.dsccc.com (Mike McCarty)
Tue, 1 Aug 1995 18:14:13 GMT

          From comp.compilers

Related articles
Origins of == in C jpowers@ti.com (1995-07-20)
Re: Origins of == in C D.Chappell@biochem.usyd.edu.au (Doug CHAPPELL) (1995-07-25)
Re: Origins of == in C Brendan.Gowing@cs.tcd.ie (Brendan Gowing) (1995-07-26)
Re: Origins of == in C peter.schurek@banyan.siemens.co.at (1995-07-28)
Re: Origins of == in C schrod@iti.informatik.th-darmstadt.de (1995-07-31)
Re: Origins of == in C jmccarty@spdmail.spd.dsccc.com (1995-08-01)
Re: Origins of == in C det@sw.stratus.com (David Toland) (1995-08-03)
Re: Origins of == in C bas@phys.uva.nl (Bas V._de Bakker) (1995-08-09)
| List of all articles for this month |

Newsgroups: comp.compilers
From: jmccarty@spdmail.spd.dsccc.com (Mike McCarty)
Keywords: C, design
Organization: DSC Communications Corporation, Plano, Texas USA
References: 95-07-135 95-07-158
Date: Tue, 1 Aug 1995 18:14:13 GMT

Brendan Gowing <Brendan.Gowing@cs.tcd.ie> wrote:


[stuff about = vs == vs := cut]


)expression. If this were not the case and "=" was constrained to use
)in a statement, then C compilers could spot a lot of the problems that
)you are encountering.
)
)But if this was the case, code like the following wouldn't work:
)
)ptrType* aFunction (void);
)ptrType* myVariable = NULL;
)...
){
) if (myVariable = aFunction())
) /* ^^^ assignment =>
) * myVariable is not NULL, so do
) * something.
) */
) printf ("Address returned by aFunction() is: %x\n", myVariable);
) else
) printf ("myVariable is NULL!\n");
)}


I used a language which allowed this, but also protected against it. I
think that the best languages protect against likely errors, but allow
it with overrides. It went like this:


a := b; assignment statement ( := is not an operator )
a = b relational test expression ( = is an operator )


(a := b) assignment expression




So the syntax is:


IF boolean_expression THEN statement [ELSE statement]


Example:


if x = 6 then y := 5;


This is a syntax error:


if x := y then z := 6;


There is no expression at all here. HOWEVER -


if (x := y) then z := 6;


is acceptable.


Mike
----
char *p="char *p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
--


Post a followup to this message

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