|
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
It does not solve my Problem, but it answers my question
modified 19-Jan-21 21:04pm.
|
|
|
|
|
Doh! Never mind. Totally legal even though does not make any sense
|
|
|
|
|
Yep, see also my edit above
It does not solve my Problem, but it answers my question
modified 19-Jan-21 21:04pm.
|
|
|
|
|
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
modified 19-Jan-21 21:04pm.
|
|
|
|
|
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
|
|
|
|
|
LOL, i'm guilty of using it in for loops sometimes.
Real programmers use butterflies
|
|
|
|
|
You'll be burned anyway, so what's the point?
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
modified 19-Jan-21 21:04pm.
|
|
|
|
|
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 inits
Real programmers use butterflies
|
|
|
|
|
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 <shift> 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
|
|
|
|
|
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.
|
|
|
|
|
Yes, that's a good example. Thankfully I have never had the misfortune of using it.
"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?"
|
|
|
|
|
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???
|
|
|
|
|
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.
|
|
|
|
|
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{...})'
It does not solve my Problem, but it answers my question
modified 19-Jan-21 21:04pm.
|
|
|
|
|
Actually it makes a lot of sense. I use the comma operator in quite a few places.
|
|
|
|
|
Possibly why C# has altered the behavior of comma . (Sadly.)
|
|
|
|
|
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
|
|
|
|
|
The lowest price in my lifetime for oil was about $3/bbl - until today - when it dropped to $2/bbl, then below $1/bbl and finally went ing negative!
Normally, I'd delighted when oil prices drop - it save a lot of money for virtually everyone, both directly and in manufacturing costs. Apparently the "too much of a good thing" can really be bad.
Ultimately, a lot of the smaller producers will go under - and when all this straightens out, we may unfortunately see the $100-$150/bbl again as the OPEC-ish countries have their day.
Well, I didn't wish for this, but it certainly is a good example of "Be careful what you wish for".
Ravings en masse^ |
---|
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "If you are searching for perfection in others, then you seek disappointment. If you seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|
It complements negative interest rates nicely.
|
|
|
|
|
I cannot help but wonder where it all will end?
Get me coffee and no one gets hurt!
|
|
|
|
|
"Oh Brave New World!"
Ravings en masse^ |
---|
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "If you are searching for perfection in others, then you seek disappointment. If you seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|
Momma!
Get me coffee and no one gets hurt!
|
|
|
|