comma operator
-
how come the comma operator isnt used more often i was able to write a whole function using 1 semi color at the end so how come people dont use the commas? is there a performance reason or somethting?
-
how come the comma operator isnt used more often i was able to write a whole function using 1 semi color at the end so how come people dont use the commas? is there a performance reason or somethting?
Mainly because it makes it a lot harder to see what is going if the comma operator is used for anything more complicated than a fairly trivial statement. If you write a complex function in one line using the comma operator, and then come back to it 6 months or a year later, it would be considerably more difficult to understand what is going on, than if it were written clearly in multiple statements. It is mainly useful in contexts where only a single statement is allowed - for example, in the increment statement of a for loop. for ( int i = 0, j = 10 ; i < nCount ; ++i, --j ) { // ... } Dave http://www.cloudsofheaven.org
-
how come the comma operator isnt used more often i was able to write a whole function using 1 semi color at the end so how come people dont use the commas? is there a performance reason or somethting?
:confused: :confused: :confused: Comma is used heavily in our code... while you declaring functions. For example:
void Foo(int iNumber, bool bFlag);
BOOL Move(HWND hWnd, LONG x, LONG y, ULONG cx, ULONG cy);;P;P;P BuggyMax
-
:confused: :confused: :confused: Comma is used heavily in our code... while you declaring functions. For example:
void Foo(int iNumber, bool bFlag);
BOOL Move(HWND hWnd, LONG x, LONG y, ULONG cx, ULONG cy);;P;P;P BuggyMax
im talking about where semi colons are used like this void main() { function(), function2(), function3(); }
-
how come the comma operator isnt used more often i was able to write a whole function using 1 semi color at the end so how come people dont use the commas? is there a performance reason or somethting?
Because commas are used for other things. Semicolons are used for the end of a statement, so why not use them? If you use commas, the code basically looks like one big function call. I'm not sure why you'd want to use commas over semicolons.
Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
-
im talking about where semi colons are used like this void main() { function(), function2(), function3(); }
#include <iostream>
int SetVal_1(int iNum)
{
return iNum +1;
}int SetVal_2(int iNum)
{
return iNum * 2;
}int SetVal_3(int iNum)
{
return iNum * 3 + 4;
}void main()
{
int LuckyNum = SetVal_1(5), SetVal_2(6), SetVal_3(7);printf("Lucky number = %d\\n", LuckyNum);
}
BuggyMax