Googles appar
Huvudmeny

Post a Comment On: cbloom rants

"07-26-10 - Code Issues"

14 Comments -

1 – 14 of 14
Blogger Jeff Roberts said...

> Or should I just provide
> code that builds for SPU
> and let you do your
> management?

We have good stuff for this already (that *everyone* uses - even the hardcore guys like Insomniac and Naughtydog).

I'll get you the sweet action tonight.

->Jeff

July 26, 2010 at 5:24 PM

Blogger IvyMike said...

I know it is not much consolation, but I think the inline behavior falls into (as you guessed) the "correct, but [...] damn annoying" bin.

I'd like to cite Stroustroup, just in case my memory is faulty, but don't have it handy. But... the IBM C++ compiler has almost exactly the example you have above, and describes that the C++ standard makes it so.

http://publib.boulder.ibm.com/infocenter/compbgpl/v9v111/topic/com.ibm.xlcpp9.bg.doc/language_ref/cplr243.htm#cplr243

July 26, 2010 at 5:57 PM

Blogger Carsten Orthbandt said...

The issue with the two functions being merged into one is simply explained by the "one definition rule".
You end up with two functions which both have external linkage and the exact same signature. When asked to resolve the calls, the linker uses the first one it finds.
By marking them as "static" you avoid the external linkage, making them elements that are only visible and linked within that CPP file.

July 26, 2010 at 6:47 PM

Blogger cbloom said...

"You end up with two functions which both have external linkage and the exact same signature."

Well yeah, if you think they have external linkage the problem is obvious.

IMO "inline" should imply "static". I have no interest in extern inlines.

July 26, 2010 at 6:51 PM

Blogger cbloom said...

And in fact that IBM Compiler that is so aware of the problem has a "-qstaticinline" option to make all inlines static.


Annoyingly I can't just put "static" on my #define INLINE to fix it all over my code, because I sometimes put INLINE on member functions (when they have their body in a header but inside the class definition), and "static" on member functions doesn't mean the same thing.

July 26, 2010 at 6:58 PM

Comment deleted

This comment has been removed by the author.

July 26, 2010 at 10:35 PM

Blogger ryg said...

"In further "GCC strictness is annoying", [..]"
Actually, C++ on GCC is annoying, period.

It's got a lot of good stuff and then some totally ridiculous warnings you can't turn off (unless you set the warning level extremely low, which is also retarded). Not sure what the exact message is, but one that's particularly annoying is "comparison is always true for this data type" when you do something like "if (x >= 0)" where x is unsigned. Easy to get when you have a template that's instantiated using both signed and unsigned types. We had something like this in a printf-like function that was templated on character type and existed in variants for ASCII (7-bit only, just for debugging) and UTF-16 (used for all visible / localized text). There was one check in there that tested "if (some_char < 128)", which is always true for chars if "char" is signed, but not always true for the Unicode variant. So we got that warning on every file that instantiated the template for char. Way to go. I think they finally added a switch to disable that warning in GCC 4.4 - I looked it up, the corresponding bug was filed something like 7 years ago.

Another one: Where it complains when elements in an initializer list are in a different order than in the class declaration. Now that's actually a good idea if there's ctor calls in there, but complaining about it when you're just initializing POD values is retarded, and this is the kind of stuff that gets unintentionally broken all the time in cross-platform projects because no other compiler complains about it.

July 28, 2010 at 1:43 AM

Blogger cbloom said...

"Not sure what the exact message is, but one that's particularly annoying is "comparison is always true for this data type" when you do something like "if (x >= 0)" where x is unsigned. "

Yep, this is one of the annoying ones I've been hitting.

This is -Wtype-limits , but oddly there is no -Wno-type-limits (most GCC warnings have a -Wno variant to turn them off).

I think the only way to solve this is to start with all warnings off and then turn on just the ones you want one by one. :(

"Another one: Where it complains when elements in an initializer list are in a different order than in the class declaration. Now that's actually a good idea if there's ctor calls in there, but complaining about it when you're just initializing POD values is retarded"

Yep this one is super annoying and I have the exact same complaint as you.

If they were actually complex ctor calls that could somehow affect each other, I would love to know about this warning, though it would be very badly written code if they actually were order-dependent.

July 28, 2010 at 10:57 AM

Anonymous Anonymous said...

"1. You can run into order-of-initialization issues if you aren't careful. (this is not a problem if you are a good C++ programmer and embrace proper best practices; in that case you will be initializing everything with singletons and so on)."
Do not know what the rest of the article is saying as I stopped reading after the above note. Best practices != Singleton!

July 29, 2010 at 8:04 AM

Blogger RCL said...

"Another one: Where it complains when elements in an initializer list are in a different order than in the class declaration. Now that's actually a good idea if there's ctor calls in there, but complaining about it when you're just initializing POD values is retarded"

It's actually not retarded even if you initialize POD values, because you may use function calls to calculate initial values for them and it gives you an extra warning that the order will be different from what you thought.

GCC is sometimes pedantic but as long as it doesn't prevent the compiler from generating optimal code, I'm happy to adhere to stricter practices (after all, why encourage sloppy coding?)

July 31, 2010 at 9:26 AM

Blogger cbloom said...

class C { int x,y; C() : y(1), x(2) { } }

that's not sloppy coding and there's no damn reason to warn me about it.

I don't think I have ever in my life put a (non trivial) function call in the initializer list.

I know that strict C++ people like to use the initializer list because you avoid double-setting values and its better for exceptions and so on, but for debuggability and readability I prefer to put any kind of complex intialization in the function body.

July 31, 2010 at 11:18 AM

Blogger cbloom said...

BTW this all wouldn't be so bad if GCC would just give me a damn warning ID when it spits out a warning !!!!

At least with MSVC they put the warning # right there, so when they give me a bogus warning I can just go disable it.

With GCC I have to go to fucking Google and try to figure out what warning that is and if it's even *possible* to disable it.

And then I can't disable it in the code file just where I want to.

GRR GRR GRR

If I take off my whiney hat, it's actually amazing how good it is, given that it's pretty democratic open source. As usual with open source stuff, lots of people want to work on the sexy bits (the scheduler, etc), and nobody wants to work on the usability.

July 31, 2010 at 11:25 AM

Blogger RCL said...

I believe that token-based approach is more preferable, because maintaining a database of IDs for all GCC versions and platforms would be much harder than it is for MSVC.

Spot on about free software. As someone said, "People draw for free. People don't clean toilets for free."

July 31, 2010 at 1:26 PM

Blogger Jonathan said...

gcc does have -fdiagnostics-show-option, which will indicate a flag that can be used to control a warning (if there is one). IIRC, gcc-4.5 has some improvements related to warnings.

In the little testing I've done with it, 4.5 has generated significantly better performing output than 4.4 for some SPU programs I tested (one fairly simple case being ~30% faster).

August 20, 2010 at 4:22 AM

You can use some HTML tags, such as <b>, <i>, <a>

This blog does not allow anonymous comments.

Comment moderation has been enabled. All comments must be approved by the blog author.

You will be asked to sign in after submitting your comment.