Do not panic. Ask here before giving up.
Hi, please tell me what does ',' mean in this line: lfnt.lfWeight = font.GetWidth(), angle, angle, font.IsBold() ? FW_BOLD : FW_NORMAL; Thanks
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.
Maybe "," operator is overloaded .
cbpporter wrote on Wed, 02 April 2008 12:04 Maybe "," operator is overloaded . Why not have a look at the code? You can find it in ".../upp/uppsrc/Draw/DrawTextWin32.cpp" at line 299. Werner
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.
cbpporter wrote on Wed, 02 April 2008 12:04 Maybe "," operator is overloaded . 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 ). But that would be problem of original poster, that he didn't post enough of code to see the comma is overloaded. 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/).
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 << . 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 .
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.
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(?). (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 )
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 ) Thanks for the answer. Yes i will
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 << . 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
really nice the usage of operator, in boost...I wonder if it can be implemented in upp to fill arrays and so. Max
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.
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.