Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Extra libraries, Code snippets, applications etc. » C++ language problems and code snippets » What does , means?
What does , means? [message #15130] Wed, 02 April 2008 02:05 Go to next message
mobilehunter is currently offline  mobilehunter
Messages: 87
Registered: November 2006
Member
Hi, please tell me what does ',' mean in this line:
lfnt.lfWeight = font.GetWidth(), angle, angle, font.IsBold() ? FW_BOLD : FW_NORMAL;


Thanks
Re: What does , means? [message #15131 is a reply to message #15130] Wed, 02 April 2008 09:56 Go to previous messageGo to next message
mr_ped is currently offline  mr_ped
Messages: 825
Registered: November 2005
Location: Czech Republic - Praha
Experienced Contributor
http://msdn2.microsoft.com/en-us/library/zs06xbxh.aspx

It works similar to ";", but the whole sequence up to ";" is considered as single expression to compiler.
(handy especially in for statements, where you can do increment of two variables like this for ( ... ; ... ; ++var1, ++var2 ) ... but don't overuse it, it decreases the readability of code)

That said the "angle, angle, font.IsBold() ? FW_BOLD : FW_NORMAL" part looks useless to me, as it will produce 3 values (2x "angle" value, and once FW_BOLD or FW_NORMAL), which are not assigned anywhere, what makes them useless.

So you either put that line out of context and it is in reality parsed differently, or you have some very weird piece of code.
Re: What does , means? [message #15133 is a reply to message #15131] Wed, 02 April 2008 12:04 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1401
Registered: September 2007
Ultimate Contributor
Maybe "," operator is overloaded Razz.
Re: What does , means? [message #15134 is a reply to message #15133] Wed, 02 April 2008 12:39 Go to previous messageGo to next message
Werner is currently offline  Werner
Messages: 234
Registered: May 2006
Location: Cologne / Germany
Experienced Member
cbpporter wrote on Wed, 02 April 2008 12:04

Maybe "," operator is overloaded Razz.


Why not have a look at the code? Twisted Evil

You can find it in ".../upp/uppsrc/Draw/DrawTextWin32.cpp" at line 299. Very Happy

Werner
Re: What does , means? [message #15136 is a reply to message #15134] Wed, 02 April 2008 14:24 Go to previous messageGo to next message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
Its a copy and paste error that luckily doesn't do anything:
	lfnt.lfWeight = font.GetWidth(), angle, angle, font.IsBold() ? FW_BOLD : FW_NORMAL;
	lfnt.lfItalic = font.IsItalic();
	lfnt.lfUnderline = font.IsUnderline();
	lfnt.lfStrikeOut = font.IsStrikeout();
	wcscpy(lfnt.lfFaceName, ToSystemCharset(font.GetFaceName()));
	f->hfont = CreateFontIndirect(&lfnt);
#else
	f->hfont = CreateFont(font.GetHeight() ? -abs(font.GetHeight()) : -12,
		                  font.GetWidth(), angle, angle, font.IsBold() ? FW_BOLD : FW_NORMAL,

You can see where it was copied from.
Re: What does , means? [message #15137 is a reply to message #15136] Wed, 02 April 2008 15:11 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Ops. Fixed.

Mirek
Re: What does , means? [message #15142 is a reply to message #15133] Wed, 02 April 2008 17:30 Go to previous messageGo to next message
mr_ped is currently offline  mr_ped
Messages: 825
Registered: November 2005
Location: Czech Republic - Praha
Experienced Contributor
cbpporter wrote on Wed, 02 April 2008 12:04

Maybe "," operator is overloaded Razz.


Once again I'm not "guru enough" to know whether comma can be overloaded (but why not, looks reasonable ... except it makes me feel sick when I imagine it Very Happy ).

But that would be problem of original poster, that he didn't post enough of code to see the comma is overloaded. Smile
As it is line from UPP sources, he could have easily added file/line location, that would made the context clear and avoid any confusion with preprocessor or operator overloading.

Anyway, I hope Mirek will not try to compete in IOCCC (http://www.ioccc.org/).
Re: What does , means? [message #15144 is a reply to message #15142] Wed, 02 April 2008 17:39 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1401
Registered: September 2007
Ultimate Contributor
Quote:

Once again I'm not "guru enough" to know whether comma can be overloaded (but why not, looks reasonable ... except it makes me feel sick when I imagine it ).

I had to look it up also, and yes, it can be done. But I never did this myself. I couldn't and can't find a good reason to do this, not even as an alternative to cout << Smile. Especially since arguments can be evaluated more than once. But still it is not totally improbable that Mirek used some overloading magic and constructed some font info structure with the help of such a statement. Anyway, without a file or line number, and judging by the fact that it was posted in the general C++ section, I had no way to be sure if it's from U++ and where to find it, so I couldn't look it up to see that it was overloaded or not. And fortunately, It wasn't Smile.
Re: What does , means? [message #15148 is a reply to message #15144] Thu, 03 April 2008 00:01 Go to previous messageGo to next message
mobilehunter is currently offline  mobilehunter
Messages: 87
Registered: November 2006
Member
I asked simply curious for this feature in context of general C/C++ language.

I would be happy if somebody explain interm of UPP context.
Re: What does , means? [message #15149 is a reply to message #15130] Thu, 03 April 2008 00:27 Go to previous messageGo to next message
mr_ped is currently offline  mr_ped
Messages: 825
Registered: November 2005
Location: Czech Republic - Praha
Experienced Contributor
The problem is with your original post.
That line in general C/C++ can mean pretty much anything.
Well, it's not that bad in C, there's only that preprocessor thing, but it's total havoc in C++ where you can also overload comma operator.

Unless you have full C++ source, ideally preprocessed already (-E switch for GCC), it's impossible to tell what exactly some line does and how it will end after compilation.
It can be eventually preceded by end-of-line comment which ends with backslash by accident, which will make it part of that comment! I have seen it all(?). Very Happy (feeling old)

UPP does use overloaded operators aggressively (like <<= for callbacks and generally to assign value) to get "nicer and cleaner" source, but it makes the source somewhat confusing to pure C++ programmer who didn't study UPP basics. (but any C++ source can be confusing even without UPP magic, just check that link to IOCCC if you don't have idea how bad it can be)

So while the simple guess it's just ordinary comma with useless code (common copy/paste bug, luckily harmless this time) was right, it could have been worser, if someone would deliberately tried to obfuscate it with overloaded comma function and some macros for example with name "angle". Than the correct answer would require to see the definitions of those other things.

There's no other special UPP context about this, it was common *sigh* C++ code.

(anyway, it was very good question, keep asking whenever you don't fully understand some piece of UPP code... you will either learn something new, or help Mirek to find new bug Smile )
Re: What does , means? [message #15152 is a reply to message #15149] Thu, 03 April 2008 01:46 Go to previous messageGo to next message
mobilehunter is currently offline  mobilehunter
Messages: 87
Registered: November 2006
Member
mr_ped wrote on Thu, 03 April 2008 07:27

The
There's no other special UPP context about this, it was common *sigh* C++ code.

(anyway, it was very good question, keep asking whenever you don't fully understand some piece of UPP code... you will either learn something new, or help Mirek to find new bug Smile )


Thanks for the answer.
Yes i will Smile
Re: What does , means? [message #15269 is a reply to message #15144] Mon, 14 April 2008 16:50 Go to previous messageGo to next message
tvanriper is currently offline  tvanriper
Messages: 85
Registered: September 2007
Location: Germantown, MD, USA
Member
cbpporter wrote on Wed, 02 April 2008 11:39

Quote:

Once again I'm not "guru enough" to know whether comma can be overloaded (but why not, looks reasonable ... except it makes me feel sick when I imagine it ).

I had to look it up also, and yes, it can be done. But I never did this myself. I couldn't and can't find a good reason to do this, not even as an alternative to cout << Smile. Especially since arguments can be evaluated more than once.


In the boost library, they made use of overloading this operator to help make code more legible in their Assign library.

Give this a read and judge for yourself:

http://boost.org/doc/libs/1_35_0/libs/assign/doc/index.html
Re: What does , means? [message #15272 is a reply to message #15269] Mon, 14 April 2008 23:42 Go to previous messageGo to next message
mdelfede is currently offline  mdelfede
Messages: 1307
Registered: September 2007
Ultimate Contributor
really nice the usage of operator, in boost...I wonder if it can be implemented in upp to fill arrays and so.

Max
Re: What does , means? [message #15274 is a reply to message #15272] Tue, 15 April 2008 00:10 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1401
Registered: September 2007
Ultimate Contributor
mdelfede wrote on Tue, 15 April 2008 00:42

really nice the usage of operator, in boost...I wonder if it can be implemented in upp to fill arrays and so.

Max


I see no good reason why it couldn't. I think the real question is how often do you really need it? These nice little tricks offer to little in the case of normal code, where data structures are most often populated IMO algorithmically, and in general one a one-by-one basis. In the cases a such syntactic sugars do not help that much. The nice part is that += operator, which can be quite expensive performance wise, with default pick semantics could be really nice and efficient.
Re: What does , means? [message #15388 is a reply to message #15130] Fri, 18 April 2008 22:47 Go to previous message
tvanriper is currently offline  tvanriper
Messages: 85
Registered: September 2007
Location: Germantown, MD, USA
Member
For lists filled algorithmically, yeah, this doesn't really provide much utility.

However, for static lists of specialized types, this bit of syntactic sugar can clarify your intentions quite nicely, and avoid having to type in a bunch of arcane-looking nonsense.

Still, after literally years of working with C++ as it is, to see someone use operator,() in this way kind of makes me go 'huh?' on the first mental parse. It's like some weird magical thing happened that doesn't seem immediately obvious, unless I know that the operator is being used.

I'd use it very judiciously, if at all, for that reason alone.
Previous Topic: Optimized memcmp for x86
Next Topic: THISBACK and function-overloading
Goto Forum:
  


Current Time: Thu Mar 28 12:43:57 CET 2024

Total time taken to generate the page: 0.02204 seconds