The holy comma operator [modified]
-
happened to me today: (in C++)
if (condA ||
condB ||
condC ||
condD,
condE)
{
...
}Of course I wanted to "or" all conditions, but at some point I must have figured to be in a list or something. For anyone not familiar with the comma operator, its worth looking at. I didn't make use of it except e.g.
int x=3, y=5;
until now (and thats a couple of years). -- modified at 11:52 Monday 26th November, 2007 -
happened to me today: (in C++)
if (condA ||
condB ||
condC ||
condD,
condE)
{
...
}Of course I wanted to "or" all conditions, but at some point I must have figured to be in a list or something. For anyone not familiar with the comma operator, its worth looking at. I didn't make use of it except e.g.
int x=3, y=5;
until now (and thats a couple of years). -- modified at 11:52 Monday 26th November, 2007So what's the result? In C# it just says that the comma is invalid there.
-
So what's the result? In C# it just says that the comma is invalid there.
"Consider the expression e1 , e2 The type and value of the expression are the type and value of e2; the result of evaluating e1 is discarded." From MSDN[^] Information at you fingertip.
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all.
Douglas Adams, "Dirk Gently's Holistic Detective Agency" -
happened to me today: (in C++)
if (condA ||
condB ||
condC ||
condD,
condE)
{
...
}Of course I wanted to "or" all conditions, but at some point I must have figured to be in a list or something. For anyone not familiar with the comma operator, its worth looking at. I didn't make use of it except e.g.
int x=3, y=5;
until now (and thats a couple of years). -- modified at 11:52 Monday 26th November, 2007Unless there are side effects of the other conditions, your example is the equaivant of this:
if (condE)
{
...
} -
Unless there are side effects of the other conditions, your example is the equaivant of this:
if (condE)
{
...
}Right. One can probably do awful things using commas given the right modulation of commas and semicolons - even outside variable declarations and for-statements.
-
Right. One can probably do awful things using commas given the right modulation of commas and semicolons - even outside variable declarations and for-statements.
Doc Lobster wrote:
One can probably do awful things using commas
... such as implementing an assignment library[^] :)
-
Doc Lobster wrote:
One can probably do awful things using commas
... such as implementing an assignment library[^] :)
-
Right. One can probably do awful things using commas given the right modulation of commas and semicolons - even outside variable declarations and for-statements.
So, next time you quit a job because you hate it, don't forget to throw in a few commas here and there ;)
My current favourite word is: PIE! I have changed my name to my regular internet alias. But don't let the 'Genius' part fool you, you don't know what 'SK' stands for. -
The Undefeated
-
So, next time you quit a job because you hate it, don't forget to throw in a few commas here and there ;)
My current favourite word is: PIE! I have changed my name to my regular internet alias. But don't let the 'Genius' part fool you, you don't know what 'SK' stands for. -
The Undefeated
hehe.. I like your style :)
Michael Davey biproject.com rss and blog news in a more palatable format mobile edition now available!
-
Doc Lobster wrote:
One can probably do awful things using commas
... such as implementing an assignment library[^] :)
I :love: how the docs page starts with that quote from Stroustrup.
--Mike-- Visual C++ MVP :cool: LINKS~! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ "That's what's great about doing user interface work. No matter what you do, people will say that what you did was idiotic." -- Raymond Chen
-
So what's the result? In C# it just says that the comma is invalid there.
Steve Hansen wrote:
In C# it just says that the comma is invalid there.
yah :sigh:
-
happened to me today: (in C++)
if (condA ||
condB ||
condC ||
condD,
condE)
{
...
}Of course I wanted to "or" all conditions, but at some point I must have figured to be in a list or something. For anyone not familiar with the comma operator, its worth looking at. I didn't make use of it except e.g.
int x=3, y=5;
until now (and thats a couple of years). -- modified at 11:52 Monday 26th November, 2007Comma operator generates right operand value so condE for this example.
-
happened to me today: (in C++)
if (condA ||
condB ||
condC ||
condD,
condE)
{
...
}Of course I wanted to "or" all conditions, but at some point I must have figured to be in a list or something. For anyone not familiar with the comma operator, its worth looking at. I didn't make use of it except e.g.
int x=3, y=5;
until now (and thats a couple of years). -- modified at 11:52 Monday 26th November, 2007 -
happened to me today: (in C++)
if (condA ||
condB ||
condC ||
condD,
condE)
{
...
}Of course I wanted to "or" all conditions, but at some point I must have figured to be in a list or something. For anyone not familiar with the comma operator, its worth looking at. I didn't make use of it except e.g.
int x=3, y=5;
until now (and thats a couple of years). -- modified at 11:52 Monday 26th November, 2007