You're kidding, right?
(gdb) bt #0 0xaf88f2e0 in std::lround<Fixed<long, 14> > (__x=51.35198974609375) at /usr/include/c++/4.5/tr1_impl/cmath:710 #1 0xaf88f2e8 in std::lround<Fixed<long, 14> > (__x=51.35198974609375) at /usr/include/c++/4.5/tr1_impl/cmath:710 #2 0xaf88f2e8 in std::lround<Fixed<long, 14> > (__x=51.35198974609375) at /usr/include/c++/4.5/tr1_impl/cmath:710 #3 0xaf88f2e8 in std::lround<Fixed<long, 14> > (__x=51.35198974609375) at /usr/include/c++/4.5/tr1_impl/cmath:710 #4 0xaf88f2e8 in std::lround<Fixed<long, 14> > (__x=51.35198974609375) at /usr/include/c++/4.5/tr1_impl/cmath:710 #5 0xaf88f2e8 in std::lround<Fixed<long, 14> > (__x=51.35198974609375) at /usr/include/c++/4.5/tr1_impl/cmath:710
This goes on for a few tens of thousands of stack frames. Time to open /usr/include/c++/4.5/tr1_impl/cmath:710, which has this little gem:
template<typename _Tp> inline long lround(_Tp __x) { typedef typename __gnu_cxx::__promote<_Tp>::__type __type; return lround(__type(__x)); }
What happened? Fucked if I know (it's a bit hard to get to the bottom of the problem without being able to get to the bottom of the call stack, for starters; ought to figure out a better way than hitting Enter screen after screen, with gdb asking if I really want to proceed).
Did someone define an std::lround? (A quick grep didn't show signs of that fuckwittery; though I found a couple of std::mins and std::maxes, leading to colorful consequences.)
Did someone define a template lround and did a using namespace std?
Did someone define an implicit casting operator that used to be called here, before this lround template appeared, and became a better match for the argument, whatever that means?
Fucked if I know.
I'm sure this lround business wasn't ever supposed to call itself, though it rather obviously can, depending on what the __gnu_cxx::__promote<_Tp>::__type does.
All that from trying to upgrade from g++ 4.2 to g++ 4.5 (and to gnu++0x – a C++0x flavor brought to you by GNU, enriched by GNU extensions such as strdup.) Oh the joys and safety of static binding – statically changing the meaning of your code with every compiler upgrade!
It's a good thing I rarely get to deal with C++ these days.
(Why upgrade to C++0x, a.k.a. C++11, a.k.a C++0xb? Lambdas, for one thing. Also future job interviews. Embrace C++11, or die trying.)
172 comments ↓
For what it's worth, it looks like the typedef uses GCC-specific machinery to do some kind of cast (my guess is to remove const and volatile, but that's only a guess). The last line looks like a recursive call, but I suspect it's meant to call an overloaded function that uses takes the promoted type chosen by the typedef.
My diagnosis is that the second function doesn't exist for long, so the thing gets stuck in a recursive loop. However, I can't figure out what value there is in rounding longs, they're integral types so they have no fractional part to round.
I suspect that this is a bug in GCC's library. I have a hard time believing that you'd call lround directly. Instead, I'm sure you called another function that erroneously calls lround.
I don't have GCC 4.5, but what seems to be happening here is the following:
- libstdc++ has a few (>= 1) non-template lround() functions which handle some specific types.
- libstdc++ also has the generic, templated version shown above, which tries to promote the type it is given to one that's eventually handled by the non-template versions.
The diagnosis here would be to check what __promote does for your type; but it already looks like it's essentially the identity function. Which is the weird part; it should be doing something sensible or failing to compile.
In fact (so I got curious and starting digging around the web for the libstdc++4.5 header files), if you look at , that's exactly what's happening: __promote merely serves as identity, at least for types that __is_integer is not defined. This seems to be a bug, and it's been fixed in 4.7, where the generic version of __promote does not define __type at all. (And also in 4.7 the templated lround() simply calls __builtin_lround() and doesn't bother with any of this promoting chicanery).
Last paragraph should read: "[...] if you look at ext/type_traits.h, [...]" (looks like your blog code strips anything in angle brackets, which is probably a good idea, but still…)
Did you try GCC 4.7? Did you try clang 3.2? Even if they can't generate assembly for your arch, they might be useful as static analyzers.
Is 4.7 known to be much better than 4.5? I'm open to experimenting.
I bet you already know the "explanation" for what's actually happening at the compiler/library level here, but for the benefit of *anyone* who feels confused, here's my amateur take on it:
The standard library defines lround(float), lround(double), and lround(long double). It also defines a template function lround(T), as pasted in your post, whose job is to promote the T parameter to a new, more appropriate type __type and then call lround(__type) on the promoted value.
How is this new type "__type" determined? Well, if the original type was an integral type, the new type is "double". Otherwise, __promote is a no-op. Here's the code:
http://gcc.gnu.org/onlinedocs/libstdc++/libstdc++-html-USERS-4.3/a02061.html#l00161
00164 template<typename _Tp, bool = std::__is_integer::__value>
00165 struct __promote
00166 { typedef double __type; };
00167
00168 template
00169 struct __promote
00170 { typedef _Tp __type; };
Now, in Yossi's code, he's calling lround() on a value of type Fixed<long,14>. Presumably the Fixed type has an overloaded conversion "operator double()" or the like, and the original programmer expected that lround(fixedval) would be evaluated as lround(double(fixedval)). Unfortunately, GNU's library isn't playing along.
One workaround would be to insert the explicit cast everywhere lround() is called. Another (better?) workaround would be to provide your own overload or specialization of lround(), and make sure it's visible in all files where lround is called. Yet another (much much worse!) workaround would be to specialize std::__is_integer for your Fixed type.
In libc++, this library bug has been fixed by writing clearer code in the first place: std::lround<T> is enabled only for integral types, using the clever (TOO clever, I'm sure Yossi will say) "enable_if" construct.
template
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if<is_integral::value, long>::type
lround(_A1 __x) {return lround((double)__x);}
can you put post here the definition of Fixed, as well as what promote does to it ?
@A: you have rather thorough knowledge of this shit. I remember when I used to have rather thorough knowledge of this shit myself. I sure hope the process of interacting with the various new versions of gcc and their C++11 support will not force me to thoroughly learn this shit again. enable_if… fuck_me.
@David: no, that would be too embarrassing. The upshot is that it has an operator float and an operator double, I think – implicit casts because C++98 doesn't have an explicit cast, only explicit constructors, and now it's a bit too late to change the thousands of casts in user code to explicit ones. As to what promote does to it – I think that the recursion above demonstrates that promote does nothing to it, or rather it's an identity function, if you can call this shit a function.
Unpaged output in gdb?
Enter "set pagination off" in gdb or add it to ${HOME}/.gdbinit for automatic execution. Then welcome the gazillions of identical lines of back trace. ;-)
@Thomas: aha! set pagination off. Maybe it's worth adding to the company-wide .gdbinit… I wonder what happens under TUI and to what extent cmd.exe can scroll through the output though…
C++ is a cuntful language. When it is nice and dripping there is no better place to be, but when those mucus membranes dry up, it will tear the skin off your dick.
I generally avoid the use of templates at all costs. I find them objectionable.
I am still laughing! I have been calling myself a programmer for 30+ years (reference to another blog) and can still learn things right here!
Particularly that last bit about avoiding templates!
Thanks, folks!
carl.
@A: “How is this new type "__type" determined? Well, if the original type was an integral type, the new type is "double".”
Assuming that's accurate, who the hell rounds long to long by converting it to double!? Is that one of those mythical "smart compilers" which make templates "as performant as hand-written code"?
You got yourself a new rader.
This does interest me
Some truly interesting article on this web site , appreciate it for contribution.
Enjoyed reading through this, very good stuff, thankyou .
I enjoying, will read more. Cheers!
Ha, here from yahoo, this is what i was looking for.
Some truly wonderful article on this web site , appreciate it for contribution.
In my opinion, yosefk.com does a great job of handling subjects of this kind. While frequently intentionally polemic, the information is in the main well-written and stimulating.
I am glad to be one of the visitors on this great website (:, appreciate it for posting .
Great stuff to Read, glad that yandex brought me here, Keep Up awsome Work
I dugg some of you post as I thought they were very beneficial invaluable
This is nice!
Appreciate it for this howling post, I am glad I observed this internet site on yahoo.
Ha, here from google, this is what i was browsing for.
I like this site, because so much useful stuff on here : D.
I’m impressed, I have to admit. Genuinely rarely should i encounter a weblog that’s both educative and entertaining, and let me tell you, you may have hit the nail about the head. Your idea is outstanding; the problem is an element that insufficient persons are speaking intelligently about. I am delighted we came across this during my look for something with this.
I must say, as a lot as I enjoyed reading what you had to say, I couldnt help but lose interest after a while.
I’m impressed, I have to admit. Genuinely rarely should i encounter a weblog that’s both educative and entertaining, and let me tell you, you may have hit the nail about the head. Your idea is outstanding; the problem is an element that insufficient persons are speaking intelligently about. I am delighted we came across this during my look for something with this.
Very interesting points you have remarked, appreciate it for putting up.
Great, bing took me stright here. thanks btw for info. Cheers!
Cheers, i really think i will be back to your website
Intresting, will come back here once in a while.
Enjoyed reading through this, very good stuff, thankyou .
This does interest me
Good Day, glad that i saw on this in google. Thanks!
stays on topic and states valid points. Thank you.
I dugg some of you post as I thought they were very beneficial invaluable
Enjoyed reading through this, very good stuff, thankyou .
I love what you guys are up too. This sort of clever work and coverage!
Keep up the amazing works guys I've added you guys to our blogroll.
I like this site, because so much useful stuff on here : D.
Hey I know this is off topic but I was wondering if you knew of any widgets I could add to my blog that automatically tweet
my newest twitter updates. I've been looking for a plug-in like this for quite some time
and was hoping maybe you would have some experience with something like this.
Please let me know if you run into anything.
I truly enjoy reading your blog and I look forward to your new updates.
Hi, happy that i saw on this in bing. Thanks!
Howdy! This is kind of off topic but I need some help from an established blog.
Is it very hard to set up your own blog? I'm not very
techincal but I can figure things out pretty fast.
I'm thinking about creating my own but I'm not sure where to start.
Do you have any tips or suggestions? Many thanks
I am glad to be one of the visitors on this great website (:, appreciate it for posting .
Intresting, will come back here later too.
I read this post fully on the topic of the resemblance of most recent and preceding technologies,
it's remarkable article.
Quite a good read. I just now passed this on 5/30/2019 to a colleague who's been involved in some work of his own on the topic. To show his appreciation, they just bought me lunch! So, let me express my gratitude by saying: Thanks for the meal!
Intresting, will come back here more often.
Ha, here from yahoo, this is what i was browsing for.
I'm not sure where you're getting your info, but good topic.
I needs to spend some time learning more or understanding more.
Thanks for great info I was looking for this info for my mission.
Hi there, all is going fine here and ofcourse every one is sharing data, that's truly excellent, keep up writing.
Just wanna input on few general things, The website layout is perfect, the articles is very superb : D.
bing brought me here. Cheers!
This excellent website definitely has all of the info I needed concerning
this subject and didn't know who to ask.
Awesome, this is what I was searching for in google
fantastic publish, very informative. I'm wondering why the
other experts of this sector do not notice this.
You should continue your writing. I'm confident, you have a great readers' base already!
Do you have a spam problem on this blog; I also am a blogger,
and I was curious about your situation; we have developed some nice
procedures and we are looking to trade techniques with others, be
sure to shoot me an e-mail if interested.
Hi to every body, it's my first go to see of this web site;
this website consists of awesome and actually excellent information in support of visitors.
This article is truly a good one it helps new the
web people, who are wishing for blogging.
Attractive section of content. I just stumbled upon your site and in accession capital to assert
that I acquire actually enjoyed account your blog posts.
Any way I will be subscribing to your feeds and even I achievement you access consistently rapidly.
Informative article, exactly what I was looking for.
Every weekend i used to pay a quick visit this web site, as i wish for enjoyment, as
this this website conations genuinely pleasant funny stuff too.
Wonderful blog! I found it while browsing on Yahoo News.
Do you have any tips on how to get listed in Yahoo News?
I've been trying for a while but I never seem to get there!
Thank you
Please let me know if you're looking for a author for your site.
You have some really great articles and I believe I would be
a good asset. If you ever want to take some of the load
off, I'd really like to write some material for your
blog in exchange for a link back to mine. Please send me an email if
interested. Many thanks!
Howdy! Quick question that's completely off topic.
Do you know how to make your site mobile friendly? My web site looks weird when browsing from my iphone
4. I'm trying to find a template or plugin that
might be able to fix this problem. If you have any suggestions, please share.
Many thanks!
Cheers, i really think i will be back to your website
Hello, here from yahoo, me enjoyng this, will come back soon.
Howdy! This is kind of off topic but I need some advice
from an established blog. Is it hard to set up your own blog?
I'm not very techincal but I can figure things out
pretty quick. I'm thinking about creating my own but I'm not sure where to
begin. Do you have any points or suggestions? Cheers
Dove Acquistare Cialis Sicuro Kamagra Insuficiencia Cardiaca Purity Solutions Tadalafil Review [url=http://ausgsm.com][/url] Side Effect Of Amoxicillin
Me enjoying, will read more. Cheers!
Great stuff to check out, glad that duckduck brought me here, Keep Up cool job
Vpxl Pill Store Viagra Cialis Wirkung [url=http://xbmeds.com][/url] Priligy Omeopatico
Great, this is what I was browsing for in google
Respect to website author , some wonderful entropy.
Great stuff to check out, glad that yandex led me here, Keep Up awsome job
I’m impressed, I have to admit. Genuinely rarely should i encounter a weblog that’s both educative and entertaining, and let me tell you, you may have hit the nail about the head. Your idea is outstanding; the problem is an element that insufficient persons are speaking intelligently about. I am delighted we came across this during my look for something with this.
Keep this going please, great job!
Ni hao, i really think i will be back to your page
Hello, yahoo lead me here, keep up good work.
I consider something really special in this site.
I like this website its a master peace ! Glad I found this on google .
Appreciate it for this howling post, I am glad I observed this internet site on yahoo.
I like this site, useful stuff on here : D.
You got yourself a new follower.
I love reading through and I believe this website got some genuinely utilitarian stuff on it! .
Thanks for this site. I definitely agree with what you are saying.
I like this article, because so much useful stuff on here : D.
"Because the admin of this web site is working, no uncertainty very quickly it will be well-known, due to its feature contents."
Yeah bookmaking this wasn’t a risky decision outstanding post! .
I like this website its a master peace ! Glad I found this on google .
I consider something really special in this site.
You got yourself a new follower.
You got yourself a new rader.
Great, google took me stright here. thanks btw for post. Cheers!
Found this on MSN and I’m happy I did. Well written website.
You got yourself a new rader.
I like this website its a master peace ! Glad I found this on google .
Some truly wow article on this web site , appreciate it for contribution.
Online Pharmacy Cheap Retin A Real Viagra Pills Cheapest [url=http://elc4sa.com]viagra[/url] Secure Ordering Fluoxetine Medication Internet Free Shipping Overnight Shippingprozac Canada Cildentifil For Sale
I like this site, useful stuff on here : D.
I’m impressed, I have to admit. Genuinely rarely should i encounter a weblog that’s both educative and entertaining, and let me tell you, you may have hit the nail about the head. Your idea is outstanding; the problem is an element that insufficient persons are speaking intelligently about. I am delighted we came across this during my look for something with this.
I truly enjoy looking through on this web site , it holds superb content .
I was looking at some of your articles on this site and I believe this internet site is really instructive! Keep on posting .
Propecia De Dolor Testicular Viagra 100mg Buy [url=http://priliorder.com]dapoxetine on line[/url] Keflex Athletic Performance Cialis Se Puede Tomar Con Alcohol
Awesome, this is what I was browsing for in yahoo
google bring me here. Cheers!
My spouse and I stumbled over here different web page and thought I should check things
out. I like what I see so i am just following you. Look forward to
looking into your web page yet again.
I conceive you have mentioned some very interesting details , appreciate it for the post.
I love reading through and I believe this website got some genuinely utilitarian stuff on it! .
Very interesting points you have remarked, appreciate it for putting up.
I simply must tell you that you have an excellent and unique web that I really enjoyed reading.
Just wanna input on few general things, The website layout is perfect, the articles is very superb : D.
bing took me here. Cheers!
I must say got into this article. I found it to be interesting and loaded with unique points of view.
Hello, happy that i saw on this in google. Thanks!
This is awesome!
Cheers, great stuff, Me like.
Parasite backlink SEO works well :)
Some truly interesting content on this web site , appreciate it for contribution.
I enjoying, will read more. Thanks!
Enjoyed examining this, very good stuff, thanks .
Intresting, will come back here once in a while.
I simply must tell you that you have an excellent and unique site that I must say enjoyed reading.
Ha, here from google, this is what i was browsing for.
I like this website its a master peace ! Glad I found this on google .
Enjoyed examining this, very good stuff, thanks .
The next phase of the puzzle is to find out the order of the pyramid. This is your third confidential lead! 517232125
Thanks for this web. I definitely agree with what you are saying.
Great stuff to check out, glad that bing led me here, Keep Up awsome job
I like this page, useful stuff on here : D.
I love reading through and I believe this website got some genuinely utilitarian stuff on it! .
Thank You for this.
Some truly cool stuff on this web site , appreciate it for contribution.
Just wanna input on few general things, The website layout is perfect, the articles is very superb : D.
I must say, as a lot as I enjoyed reading what you had to say, I couldnt help but lose interest after a while.
I really enjoy examining on this page , it has got good stuff .
Thank you for some other great article. The place else may just anyone get that kind of information in such an ideal way of writing?
I have a presentation subsequent week, and I am at the search for such info.
I have interest in this, thanks.
You could certainly see your skills within the work you write.
The world hopes for even more passionate writers such as you who are not afraid to mention how they believe.
Always go after your heart.
you're truly a good webmaster. The website loading velocity is incredible.
It kind of feels that you're doing any distinctive trick.
Furthermore, The contents are masterwork. you've done a wonderful
activity in this topic!
great advice you give
I was suggested this blog by means of my cousin. I am
not sure whether or not this post is written by way
of him as nobody else recognize such targeted approximately my difficulty.
You're wonderful! Thank you!
Thanks in favor of sharing such a nice thought,
piece of writing is nice, thats why i have read it fully
Hi to every single one, it's really a good for me to go to
see this web page, it includes important Information.
Excellent post. I was checking constantly this blog and I am impressed!
Very helpful info specially the last part :) I care for such information much.
I was seeking this certain info for a long time. Thank you and good luck.
you are so great
This blog is amazing! Thank you.
WOW just what I was searching for. Came here by searching for plenty of
fish dating site
I think this is among the most important info for me. And i'm
glad reading your article. But want to remark on some
general things, The site style is great, the articles is really excellent :
D. Good job, cheers
I like what you guys are up too. This kind
of clever work and coverage! Keep up the excellent works guys I've added you guys to blogroll.
These are in fact fantastic ideas in concerning blogging.
You have touched some good factors here. Any way keep up wrinting.
Cheers, great stuff, I like.
Thank You for this.
Simply wish to say your article is as astonishing. The clarity in your
post is simply cool and i could assume you're an expert on this subject.
Fine with your permission allow me to grab your RSS feed to keep updated
with forthcoming post. Thanks a million and please carry on the enjoyable
work.
Thanks for this web. I definitely agree with what you are saying.
Its like you read my mind! You seem to know so much about this, like you wrote
the book in it or something. I think that you could do with
a few pics to drive the message home a bit, but other than that, this is excellent blog.
A fantastic read. I'll certainly be back.
I am not rattling great with English but I get hold this really easygoing to read .
I am 43 years old and a mother this helped me!
Howdy! Do you know if they make any plugins to protect
against hackers? I'm kinda paranoid about losing everything I've
worked hard on. Any suggestions?
hello!,I like your writing very so much! proportion we keep up a
correspondence more approximately your article on AOL?
I need a specialist on this house to resolve my problem.
Maybe that's you! Taking a look forward to look you. pof natalielise
Enjoyed examining this, very good stuff, thanks .
I dugg some of you post as I thought they were very beneficial invaluable
Hmm it appears like your site ate my first comment (it was extremely
long) so I guess I'll just sum it up what I submitted and say,
I'm thoroughly enjoying your blog. I too am an aspiring blog blogger but I'm still new to
the whole thing. Do you have any tips for beginner blog writers?
I'd really appreciate it.
I like this website its a master peace ! Glad I found this on google .
Levitra Medicament En Baisse What Is Keflex Combigan [url=http://cheapvia25mg.com]online pharmacy[/url] Amoxicillin Make A Full Dose
I conceive you have mentioned some very interesting details , appreciate it for the post.
I am not rattling great with English but I get hold this really easygoing to read .
This does interest me
Buy Generic Celexa Online Precio Levitra Tabletas [url=http://cialtadalaf.com]cialis cheapest online prices[/url] Bystolic Online Pharmacy Brand Levitra Online Pharmacy