Parenthesis
Kristian Kilpi
kjkilpi at gmail.com
Sat Dec 23 03:22:40 PST 2006
On Sat, 23 Dec 2006 12:44:16 +0200, Wolven <rma at wolven.net> wrote:
[snip]
>> if a == b return c; // errm - well...
> This one seems perfectly clear to me. Maybe I'm reading it wrong. To
> me, it
> says; if a equals b then return and pass back c. Is that not correct?
It's correct.
>> if a == b *c++; // aaarrrggghhh!!!
> Likewise, this one says; if a is equal to b, add one to... pointer c?
> Although
> I'm not positive of the meaning of the *, everything else seems crystal
> clear.
> Again, am I not reading it correctly? Other than my uncertainty over
> the *, I
> don't see any ambiguity in those statements... or any reason why C(++)
> programmers don't like them. But since I'm not a C(++) programmer,
> perhaps
> there's something unclear about those statements that I'm just not
> recognizing.
The problem is how * is treaded: is it unary or binary?
I read the statement as:
if(a == b)
*c++;
, but using arithetic precedence it will be:
if(a == b * c++);
Of course, in D you have to use {} to create an empty statement, so the
compiler should thread it as "if(a == b) *c++;" too. (But that would add
complexity to the compiler.)
Anyway, I think that *optional* parenthesis can make the code a bit harder
to read. For example:
if(a && b) || c
a = 1;
At first glance it could seem that "(a && b)" is the condition of the
if-statement. Of course one can write unreadable code with any given
syntax.
More information about the Digitalmars-d
mailing list