A 'head scratcher' problem
-
I just found a bug that is beyond strange (unless I am missing something obvious) :
float CStat::GetTotal() const
{
return m_fValue1 + m_fValue2 + m_fValue3 + m_fValue4, + m_fValue5;
}Note the ',' comma before the
, + m_fValue5;
Visual C++ 2015 compiles this without errors. The return value is always 0 because m_fValue5 100% is zero but m_fValue1 through m_fValue3 are populated. This function returns 0 always. Does this returns m_fValue5 always? Apparently the syntax is legal
You will find the answer here: Comma operator - Wikipedia[^] ... and it is a programming question which should not be asked in the lounge as far I understand ;) [Edit] I only know this beast because of a typo I made once :laugh:
It does not solve my Problem, but it answers my question
-
You will find the answer here: Comma operator - Wikipedia[^] ... and it is a programming question which should not be asked in the lounge as far I understand ;) [Edit] I only know this beast because of a typo I made once :laugh:
It does not solve my Problem, but it answers my question
-
The syntax is commonly used in for loops where you want to, say, increment two variables typically two indexes, or stepping two linked lists) before the next iteration.
Quote:
The syntax is commonly used in for loops where you want to, say, increment two variables typically two indexes, or stepping two linked lists) before the next iteration.
For me the syntax is used to make the code unreadable :)
It does not solve my Problem, but it answers my question
-
Quote:
The syntax is commonly used in for loops where you want to, say, increment two variables typically two indexes, or stepping two linked lists) before the next iteration.
For me the syntax is used to make the code unreadable :)
It does not solve my Problem, but it answers my question
0x01AA wrote:
For me the syntax is used to make the code unreadable :)
it's called newbie proofing.
pestilence [ pes-tl-uh ns ] noun 1. a deadly or virulent epidemic disease. especially bubonic plague. 2. something that is considered harmful, destructive, or evil. Synonyms: pest, plague, CCP
-
The syntax is commonly used in for loops where you want to, say, increment two variables typically two indexes, or stepping two linked lists) before the next iteration.
Member 7989122 wrote:
The syntax is commonly used in for loops where you want to, say, increment two variables typically two indexes, or stepping two linked lists) before the next iteration.
Yeah, can also remember using it to save that extra effort of typing "curlies" after say an if () or while () or ... - do everything in a single statement - save wear and tear on the keys - readability phhht, that's only for other people anyway. (Me: I can read my own mind!) ... Anyway I write code correct & bug-free first time, why does it need to be [re]readable?
pestilence [ pes-tl-uh ns ] noun 1. a deadly or virulent epidemic disease. especially bubonic plague. 2. something that is considered harmful, destructive, or evil. Synonyms: pest, plague, CCP
-
Member 7989122 wrote:
The syntax is commonly used in for loops where you want to, say, increment two variables typically two indexes, or stepping two linked lists) before the next iteration.
Yeah, can also remember using it to save that extra effort of typing "curlies" after say an if () or while () or ... - do everything in a single statement - save wear and tear on the keys - readability phhht, that's only for other people anyway. (Me: I can read my own mind!) ... Anyway I write code correct & bug-free first time, why does it need to be [re]readable?
pestilence [ pes-tl-uh ns ] noun 1. a deadly or virulent epidemic disease. especially bubonic plague. 2. something that is considered harmful, destructive, or evil. Synonyms: pest, plague, CCP
-
Member 7989122 wrote:
The syntax is commonly used in for loops where you want to, say, increment two variables typically two indexes, or stepping two linked lists) before the next iteration.
Yeah, can also remember using it to save that extra effort of typing "curlies" after say an if () or while () or ... - do everything in a single statement - save wear and tear on the keys - readability phhht, that's only for other people anyway. (Me: I can read my own mind!) ... Anyway I write code correct & bug-free first time, why does it need to be [re]readable?
pestilence [ pes-tl-uh ns ] noun 1. a deadly or virulent epidemic disease. especially bubonic plague. 2. something that is considered harmful, destructive, or evil. Synonyms: pest, plague, CCP
:thumbsup: For me all this goes (in a similar way) in the direction of dialects existing for natural languages. But for programming I prefer there is only one _defined_ language and no dialects ... more or less... of course now and then I also see the incentive of syntactic sugar. But it should stop at least after the first'?', what I remember in c# it is meanwhile '??' :( [Edit] Now and then I feel like we're moving back to assembler 'a?. (x => acc_A{...})' :laugh:
It does not solve my Problem, but it answers my question
-
Quote:
The syntax is commonly used in for loops where you want to, say, increment two variables typically two indexes, or stepping two linked lists) before the next iteration.
For me the syntax is used to make the code unreadable :)
It does not solve my Problem, but it answers my question
LOL, i'm guilty of using it in for loops sometimes.
Real programmers use butterflies
-
LOL, i'm guilty of using it in for loops sometimes.
Real programmers use butterflies
-
Ah, write-only code. That makes me think of Forth.
"They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"
It brings APL to mind. AFAIK, the first write-only language by design.
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.
-
I just found a bug that is beyond strange (unless I am missing something obvious) :
float CStat::GetTotal() const
{
return m_fValue1 + m_fValue2 + m_fValue3 + m_fValue4, + m_fValue5;
}Note the ',' comma before the
, + m_fValue5;
Visual C++ 2015 compiles this without errors. The return value is always 0 because m_fValue5 100% is zero but m_fValue1 through m_fValue3 are populated. This function returns 0 always. Does this returns m_fValue5 always? Apparently the syntax is legal
Possibly why C# has altered the behavior of
comma
. (Sadly.) -
It brings APL to mind. AFAIK, the first write-only language by design.
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.
-
It brings APL to mind. AFAIK, the first write-only language by design.
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.
One of my friends from high school taught himself to read it. He could also read brainf***. Useless talents, but talents nonetheless. It was quite impressive.
What do you get when you cross a joke with a rhetorical question? The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism. Do questions with multiple question marks annoy you???
-
You'll be burned anyway, so what's the point? ;P And yes of course, I do not know / use the syntax and therefore most probably my negative attitude for it ...
It does not solve my Problem, but it answers my question
It lets you declare multiple variables of the same type in a single statement.
int i=0,ic=10;
It's useful primarily for
for()
loops when you need multiple variable initsReal programmers use butterflies
-
I just found a bug that is beyond strange (unless I am missing something obvious) :
float CStat::GetTotal() const
{
return m_fValue1 + m_fValue2 + m_fValue3 + m_fValue4, + m_fValue5;
}Note the ',' comma before the
, + m_fValue5;
Visual C++ 2015 compiles this without errors. The return value is always 0 because m_fValue5 100% is zero but m_fValue1 through m_fValue3 are populated. This function returns 0 always. Does this returns m_fValue5 always? Apparently the syntax is legal
The good ol' comma operator. Designed specifically to trap young players. I grew up, many moons ago, in the era of 80 x 25 character screens for programming and so squeezing as much code as you could into as few lines as possible saved the ESCCtrl + F / B keys from wearing out. The ++/-- operators, dense conditionals in loops and single character variable names were what kept you productive (sorta). Those days are long, long gone now. The comma operator now just gives me 'Nam flashbacks
cheers Chris Maunder
-
It brings APL to mind. AFAIK, the first write-only language by design.
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.
Daniel Pfeffer wrote:
It brings APL to mind. AFAIK, the first write-only language by design.
Actually, it was developed for blackboard use. Kenneth Iverson was teaching matrix math at Harvard, as an extension of the classical math operators, as a notation for math expressions involving matrices. He was using it as a lecturing tool for several years, until someone at IBM suggested that just like a computer program could process plus and minus, it could handle matrix inversion and stuff like that - all those special symbols Iverson had been using on the letcuring hall blackboards. APL is like user friendly Unix: Unix is user friendly - it is just somewhat picky in who its friends are.