I have doubts on the following statments
========================================
1. Sometimes comma operators are used as a separator and sometimes as a operator
2. Comma doesn't introduce a sequence point b/w function call arguments but it
does when we give a simple statment like - i=(a,b,c);
Do we have any generalized rules for both of the statments?
James Dow Allen writes:
> The comma operator is often used in for statements:
> for (ix = 0, p = Ibuff; *p; ix++, p++)
> whatever(...);
> Here the sequence-point feature is unnecessary;
> but it is still a common operator. Its use here
> is easily avoided, but why bother?
Every now and then it can be used to fix a broken API:
while (get_data(&somewhere, &errors), !errors) {
...
}
--
Ben.
The comma operator is often used in for statements:
for (ix = 0, p = Ibuff; *p; ix++, p++)
whatever(...);
Here the sequence-point feature is unnecessary;
but it is still a common operator. Its use here
is easily avoided, but why bother?
Nice macros can be fashioned using comma operators
which would otherwise be difficult or impossible.
BTW, there is a simple syntactical check which,
I think, will inform you whether or not a given
comma is the "comma operator": If
... A, B ... or (A, B)
have semantic effects *identical* to, respectively,
... (A, B) or ((A, B))
then the commas ARE the comma operator. If not, they're NOT.
Any exceptions?
James Dow Allen
On 8/28/14 7:43 AM, David Brown wrote:
> On 27/08/14 18:08, Malcolm McLean wrote:
>> On Wednesday, August 27, 2014 4:33:01 PM UTC+1, Richard Heathfield wrote:
>>>
>>> Use a comma operator when you need a comma operator. Use a comma separator
>>> when you need a comma separator.
>>>
>>> I'm sorry. I know this reply sounds banal.
>>>
>> Sounds banal. But accepted wisdom is never ever use a comma operator,
>> even when it's the neatest solution to the problem. Always find a way
>> or rewriting code without it.
>>
>
> You are starting a fight here...
>
> I fully agree with you that the comma operator should never be used -
> but I don't think it is "accepted wisdom" by many. It is accepted
> wisdom by all coding standards that I have seen where there is an
> emphasis on writing clear, safe and reliable code (I've just done a
> quick check of Misra, JSF, PRQA). But as we already know, C programmers
> (in c.l.c. and elsewhere) often write code that they call "idiomatic C",
> while safe programming experts prefer the term "idiotic C".
>
> Misra allows the comma operator in for-loops, as described by James, but
> JSF does not allow that either.
Observation 1: Those who represent themselves as experts in the field of
“Conventional Wisdom” seem to universally lack expertise in others.
Observation 2: Programmers who blame their errors on the programming
language they’re using probably shouldn’t be.
Observation 3: Dartmouth BASIC is still available.
--
Morris Dovey
http://www.iedu.com/Solar/
http://www.facebook.com/MorrisDovey
On 27/08/14 18:08, Malcolm McLean wrote:
> On Wednesday, August 27, 2014 4:33:01 PM UTC+1, Richard Heathfield wrote:
>>
>> Use a comma operator when you need a comma operator. Use a comma separator
>> when you need a comma separator.
>>
>> I'm sorry. I know this reply sounds banal.
>>
> Sounds banal. But accepted wisdom is never ever use a comma operator,
> even when it's the neatest solution to the problem. Always find a way
> or rewriting code without it.
>
You are starting a fight here...
I fully agree with you that the comma operator should never be used -
but I don't think it is "accepted wisdom" by many. It is accepted
wisdom by all coding standards that I have seen where there is an
emphasis on writing clear, safe and reliable code (I've just done a
quick check of Misra, JSF, PRQA). But as we already know, C programmers
(in c.l.c. and elsewhere) often write code that they call "idiomatic C",
while safe programming experts prefer the term "idiotic C".
Misra allows the comma operator in for-loops, as described by James, but
JSF does not allow that either.
glen herrmannsfeldt wrote:
> Just a note, Java doesn't have a comma operator, but the for syntax
> includes commas for the first and third expression of the for statement.
That's like saying English doesn't have a possessive, but the personal
pronoun includes a genitive which functions as one.
English has a possessive and Java has a comma operator - just not one
that can be used as generally as C's.
Richard