« first day (167 days earlier)      last day (4775 days later) » 

6:02 PM
@sbi DAMN The Accelerated C++ sample is a word counter. And it follows with explaining the concept of value-initialization..
 
sbi
@Xeo Make sure you buy the third (latest) edition. The first one had a few bugs in it, which the second fixed, but both were tailored for programmers coming from C to C++ (which was very appropriate back then). The third is more tailored to programmers coming from more modern languages like Java etc.
 
TIL I'm a terrible student.
 
sbi
@StackedCrooked I have used that word counter example a lot when I taught C++, and I know I didn't invent it. :) Actually, I'm pretty sure it's also in TCPL.
 
@sbi , just to be certain, value-initialization only happens if you use the "()" syntax right?
 
sbi
@StackedCrooked Yep.
@StackedCrooked Actually, for teaching I consider a good example one that you forget immediately, because it's so obvious.
 
6:06 PM
@sbi Well in my first "C/C++" classes it was severely stressed that a variable contains garbage unless explitely initialized with a value.
@sbi So it was not at all obvious to me that int() will be initialized to zero.
 
sbi
@StackedCrooked And that's true, because int() is a value. :)
Finding good examples was one of the hardest things for me in teaching programming. A good example can go a long way to make students understand what you're talking about, but it's really hard to find.
A good example should be small, self-contained, easy to understand, except for the concept it should explain it should use only concepts well-known to the students, should have little code except the one you want to teach about, and the simplifications you need to achieve that should not produce code that deviates from what you want your students to write.
 
@sbi OK int() is a value, but ..
struct A {
A() : a(), b(), c() {}
int a, b, c;
};
^- => a(), b(), c() -> these are not "values"
but variables
 
@StackedCrooked In this context, a() is neither a value nor a variable, but an "initialization clause" (word made up by me).
 
sbi
@StackedCrooked Actually, I think they are explicit constructor invocations, except for built-ins, where they invoke value-initializations. But don't rely on me for standardeeze, I hate reading the standard.
 
@sbi do you teach your students about value initialization?
 
sbi
6:14 PM
@StackedCrooked I don't currently teach, but when I did I taught that, too. It's an important concept in C++, after all.
 
So you taught C++ after 2003? ;-)
 
sbi
@FredOverflow I taught until 2009.
 
@sbi ok, but I think it's currently a little known feature among professional C++ programmers.
@sbi, or I'm just hoping I wasn't alone. I've been programming for 5 years unaware of this.
 
In C++0x, value initialization also happens for int{}
i would like to have a C++0x course at our university
 
does anyone know hoz a basic type like int, how is that implemented under the hood?
 
6:19 PM
@JohannesSchaublitb do you mean taking or teaching the course? :)
 
it must like a class or struct or something?
 
sbi
@StackedCrooked Most of the students I taught (I taught in different contexts) had about 12-14 lectures (90mins) plus the same amount of lab work, to go from "Hello, world!"to template meta programming. They had one year of Java as previous programming experience. Many said my course was one of the hardest of their first 1.5 years of study. :) Afterwards, I told them that they are now fit to apply for C++ novice status. But really, they knew some things most of my cow-workers didn't know.
 
@Stacked both
i would like to have several C++0x teachers here
 
sbi
@JohannesSchaublitb What do you want to learn in a C++11 course? You're one of the, uh, maybe two dozen most knowledgeable people when it comes to C++11. Get used to the fact that your task is to teach C++, not learn it.
 
@sbi when I started at my current job I was lectured during a code review because I deleted a pointer without checking if it isn't equal to 0 first...
 
sbi
6:21 PM
Well, maybe it's three or four dozen, there's probably already two dozen people regularly on the committee.
 
@sbi so yeah, co-workers often aren't very knowledgable
 
i'm not knowing much about c++0x. there are only a few things I know about it
 
@JohannesSchaublitb I thought I knew a 'few' things about it, guess I'll have to reevaluate that conclusion...
 
sbi
@StackedCrooked Oh boy. See, I never read the standard (I can't stand its meter), but managed to become the C++ guru in any company I've been within months in the last decade. C++ knowledge is really poor.
 
@sbi I notice that I'm slowly becoming accepted as a C++ guru there. But there's much resistance, because they used to believe their code was really pro.
They are using exceptions as a default error mechanism, and at the same time using the native posix lock/unlock functions for mutex locking...
I was flabbergasted :)
 
sbi
6:25 PM
@JohannesSchaublitb I think you're seriously misjudging yourself there. Yes, you've never actively tried to assemble all the knowledge you have, and teaching definitely would require you to do that first. But if you'd invest that time, and if you have the slightest of talent for teaching, you could easily be among the Beyond gang.
2
 
@JohannesSchaublitb you not only have the knowledge, but you are also capable of correctly formulating why something is like it is. Many programmers are able to discern correct from incorrect code, but explaining why is also quite a challenge.
 
sbi
@StackedCrooked If you want to take a hint from someone who's been there for a decade: Telling them their code is terrible and pointing out the many blatant mistakes usually just triggers resistance, and makes your life at work very miserable. It's far better to teach positively ("this is the way you'd do it to be exception safe") than negatively ("it's horribly unsafe to do it the way you do!").
 
@sbi I definitely agree.
 
sbi
@StackedCrooked I usually ended up giving a C++ seminar in the company I worked for. :)
 
@sbi I'm probably too careful, I just waited until someone was actually struggling with deadlock, and then I carefully mentioned that I had added a scopedlock class .
@sbi I've been thinking about that a lot...
Especially about multithreading, but I'm currently not very experienced either.
 
6:33 PM
@StackedCrooked could disguise it as a workshop kind of "let's learn together" thing then
 
Hmm :)
 
sbi
@StackedCrooked I'm not all that good at being diplomatic. I'm the Grumpy Old Man, and if someone fucked up, I'd tell them. One company where this was very good was when I teamed with someone who was the mediating kind of guy.
Usually we'd sit together late in the night, deciding what we wanted to change. Then, when whatever needed to change would blow up into somebody's face, I'd blurt out what I had said all along, getting everybody worked up. That would cause a meeting to sooth the waves, where he'd moderate. The result was what we'd decided days or weeks ago.
 
Actually it's just one person that is resistant. He's the one that lectured me about not deleting null pointers...
 
@sbi good cop, bad cop? ;)
 
sbi
Over the years, we'd put the company's development process on its feet that way. :)
 
6:36 PM
@sbi it would be better if i was more straightforward
 
sbi
@jalf Yep, exactly that, only we started to do this accidentally, without planning to do so. But we saw the opportunities, and seized it. :)
@StackedCrooked There's always one who's reluctant and thinks he knows better. (And, no, it never is a "she".) It's very hard to deal with those.
 
Xeo
woohoo, back from chicken cheese nuggets
 
@sbi, yeah actually the situation isn't that bad. I work in a team of 5 people, me included. The director quickly turned to my side. The other three are kind of noobs and just believe whatever I say. So ..
 
Xeo
you had an interesting discussion going on in here it seems
 
@sbi it's just one person.
 
sbi
6:40 PM
@Xeo Yeah, this room currently has two dozen logged in users. That's more than many rooms have in a week, including rooms for languages that are allegedly much more popular than C++. :)
 
@sbi yeah, it's hard to deal with..
 
sbi
@StackedCrooked How old are you, how old is he?
 
@StackedCrooked yeah, I was about to say, if you can't convince him, then go around him, and make the rest of the team see the light. Then if he resists, he'll be the one who ends up looking bad
 
sbi
@jalf Yeah, that's good advice.
@Xeo Don't let DeadMG hear that!
 
@jalf yeah, in meetings, whenever he says something I agree with then I way so otherwise I remain silent. It seems to make him softer for my arguments.
 
Xeo
6:42 PM
@sbi he isn't in here currently, so dare you ping him
 
sbi
@Xeo I made sure I didn't attribute him so he'd get notified. :)
@Xeo (Incidentally, where are you living in Berlin?)
 
@jalf actually the director has seen the light, and usually he ends up favoring my point of view during meetings. that definitely helps a lot.
 
Xeo
@sbi the outskirts of the outskirts you could say, in treptow-köpenick/friedrichshagen, not far from erkner...
@sbi seems @StackedCrooked is self-conscious about his age, since he doesn't answer :)
 
@Xeo sorry, did you ask something? I'm kind of confused...
 
sbi
@Xeo Who am I to complain? I kept my mouth shut really tightly about myself, so I don't mind others doing the same.
 
6:46 PM
Hello.
 
hi
 
sbi
@Xeo Oh. My ex-s-i-l lives in Friedrichshagen. It's nice there, but really far off. Where do you study?
 
@sbi he's 29 I think
 
Xeo
@sbi Jannowitzbrücke, Games Academy Berlin
 
6:47 PM
@sbi, and I'm 30
 
Xeo
Though I'm not very certain i'll remain in the games industry for long if i can help it.
 
hey ho, what are we grumpy about today?
 
@sbi, but he has been working at the company for 5+ years, and built up the codebase as it is today. However, I'm new.
 
@JohnDibling people who insist you compare pointers to null before deleting them, I think
 
sbi
@StackedCrooked Well, then that's not as bad as it can get. When you come into a company age 27 knowing more than the 42 year old guy at the desk opposite who thinks he knows it all, that is a bad situation. :)
 
6:49 PM
@jalf and about being scolded for not doing pointless optimizations...
 
@jalf: Pointless. HAHA, see what I did there?
 
sbi
@Xeo Well, it's not that bad a connection then. Will I meet you next week?
 
@sbi, yeah, it's not THAT bad, and I feel that I'm slowly gaining more influence in the decisions made.
 
Xeo
@sbi That's what is currently planned.
 
sbi
@StackedCrooked Good.
@Xeo Good.
 
6:50 PM
@sbi, you got stuck with the 42 year old guy then?
 
Xeo
Or at least was, until I found out that school starts again at the 6th when i thought it was the 11th. introduction at 13:30, I hope I can get away before 6pm there
 
sbi
@JohnDibling Anything. Really, it doesn't matter. Grumpiness is a state of mind, and if you want to, you'll always find something to be grumpy about. (If you're really desperate, not finding something despite frantic searching is a very good reason to be grumpy.)
@StackedCrooked No, it didn't happen to me. I always worked for small companies (the biggest one had ~30 developers), and those cannot afford to accumulate people who don't know what they are talking about.
 
Yay, dancing unicorns.
 
sbi
@PiotrLegnica Unicorns? <yawn> :)
 
@sbi, I never worked for really big companies as well. I worked for very good companies with very good people, but due to circumstances I now ended up at an "intermediate" place.
 
6:56 PM
I'm yawning all day. :/ I hate getting up at 6.
 
I almost jumped when I saw that first unicorn.
@Piotr I love getting up at6 ...PM.
 
@Piotr: try getting up at 5:00 and having clients sometimes call you at 2:30
 
If I get up before 13, I'm basically a zombie.
 
sbi
@Xeo It only starts at 7pm, and it's one stop with the S-Bahn plus one stop with the underground to the place, which should take you about 12mins. Getting out at 6:45 should be enough to be in time. And I doubt we'll already leave at eight, so being late shouldn't be a problem.
 
The day is ruined and nothing works like it should.
 
sbi
6:59 PM
@JohnDibling Now why would we try that? We know it's bad. No need to try.
@PiotrLegnica But lying around for 13 years is no fun either.
 
Nitpicker. ;)
 
Let's talk about something exciting. Like singletons!
 
Glorified globals. Next.
 
Well, I have a question about singletons.
 
sbi
@PiotrLegnica Hey, it's the C++ room. What did you expect except nitpickers?
 
7:01 PM
@sbi Ponies.
 
Did I hear someone say singletons? Sup.
 
Two aspects of singletons are: global access and lazy instantiation.
 
And single instance.
 
sbi
@PiotrLegnica You got them. Oh yes, they do have horns on their noses. So?
 
@GMan, right, I forgot the most important one :)
 
7:02 PM
Someone asked on SO "how do i implement mutithreaded logging in C#" and everyone said "use a singleton"
 
I don't like singletons exactly because of the lazy instantiation.
 
But, it's the lazy instantiation part IMO is bad, because it doesn't allow having deterministic object lifetime.
 
sbi
@PiotrLegnica Towards the end of my studies, I rarely ever had a lecture before 12. Now one of my kids leaves at 6:30...which is when I get up. :)
 
I have discrete maths class. On Friday. At 7:30.
 
@StackedCrooked Why do you need it?
 
7:04 PM
@GMan I have two singletons: a LeakChecker, and a Logger.
The LeakChecker logs leaks when itself is destrucgted.
So Logger must survive longer than the LeakChecker.
 
Then why a singleton? Put it on stack in main.
 
sbi
@StackedCrooked There is no need to find any fine detail that's bad about singletons. A singleton basically is a glorified global variable, and those being really bad has been established long enough that, thankfully, very few, um, misguided individuals question this.
 
@PiotrLegnica that's what I sort of ended up doing.
 
because everything gets better when you make it a singleton, dontchaknow? ;)
 
@sbi, perhaps a singleton is worse than a global variable because of it's undefined lifetime length.
 
7:05 PM
Hey, I kinda like globals (assuming single-threading).
 
@StackedCrooked You have to create a system where singletons can register dependencies.
I made a Boost.Global thing once, never submitted it because I didn't feel like cleaning it up.
 
Yeah, and don't forget XML configuration system on top of that. ;)
 
sbi
@StackedCrooked No. It's easy to solve that (just add a local global object which initalizes the singleton in its constructor), but the singleton is still bad.
 
@sbi imo the problem with singletons is that they're not just globals. They also suffer from an absurd restriction that only one instance can exist
 
I ended up with the following class:
template<class T>
class Singleton : boost::noncopyable
{
public:
typedef Singleton<T> This;

// User must create a scoped Initializer object to
// determine the lifetime of the Singleton object.
struct Initializer : boost::noncopyable
{
Initializer() { This::CreateInstance(); }

~Initializer() { This::DestroyInstance(); }
};

static T & Instance()
{
if (!sInstance)
{
throw std::runtime_error("Tried to dereference null singleton instance for " + std::string(typeid(T).name()));
 
7:06 PM
plain globals have their place, occasionally, as long as they're honest about being global, and as long as they don't drag in other bad habits as well
 
@StackedCrooked Why is it noncopyable?
That is, why is whatever resource you intend to make a singleton noncopyable?
 
sbi
@PiotrLegnica The reason this is usually done is because something like logging is needed all over the place, so you'd have to hand around a pointer to your logger to every function that might want to log something, thereby putting implementation details into function signatures. (That's about the only excuse I consider valid.)
 
@GMan I just made it noncopyable because I didn't want to think about copy-semantics yet. I should update it.
 
@StackedCrooked Copy-semantics are the first thing you think about for a resource. :)
 
@GMan I usually first think about ownership.
 
7:09 PM
@sbi I use global unbuffered ostream object and a fancy macro that adds __FILE__ and __LINE__.
 
I think this thread stackoverflow.com/questions/5517513/… is a pretty good illustration of what i'm saying here stackoverflow.com/questions/4257659/c-versus-c-performance/…
 
@GMan and I admit being lazy and sometimes just making the class non-copyable until the need for a copy arises. It's safe like that.
Btw usage is like this: class MyClass : public Singleton<MyClass> {};
 
@StackedCrooked Well since C++ has value-semantics, ownership directly implies copy-semantics are next in line.
So, why is MyClass a singleton?
 
@StackedCrooked yeah, I tend to do that too.. Make a class noncopyable by default, and then remove that restriction later, when I know I need it
 
@GMan: the Logger and the LeakChecker are singletons.
 
7:11 PM
minus the singleton part, of course
 
@StackedCrooked Why? :)
 
@jalf well, I don't make my classes singleton by default :)
@GMan : because I want to be able to access the same instance, without having to pass the object around.
 
if you have enough singletons to justify a singleton base class, you have too many singletons
 
sbi
@PiotrLegnica That's fine as long as you don't want to change properties of your logging (like, e.g., the severity you want to log). If you want to do that, you need state, and that's when you have an object, whether you like it or not.
 
@StackedCrooked Then just make a global instance of your non-singleton class.
2
 
7:13 PM
@StackedCrooked how does that justify making them singletons? Make them global, as @Gman says
 
@GMan: you can't really determine the lifetime of global instances
 
sure you can. It lives "long enough" ;)
 
sbi
@StackedCrooked And that's where you get at the heart of the matter. Why don't you want to pass it around? As I said, there are what I consider legitimate reasons for this, but they don't justify the proliferations of singletons we've seen throughout the last decade.
 
@StackedCrooked Then make a global wrapper (like I did) that does manage lifetimes.
 
if that's not precise enough for you, then make a global pointer, and initialize it to point to a locally scoped object
 
7:14 PM
@GMan I prefer creating a "Singleton<T>::Initialzer logInit;" on the stack in the main function. This way I can order them.
 
But note that doesn't entail anything about copying, single-instance, etc.
 
Xeo
@jalf the problem is that the logger needs to survive the leak checker
 
@GMan the global wrapper, isn't that getting close to the singleton solution?
 
sbi
@jalf The trouble is when you have more than one and they depend on each other. Then making them singletons makes sure they are initialized in the right order.
 
@StackedCrooked Not even close. A singleton not only provides whatever global utilities you find useful, but intrusively makes your class non-copyable, and single-instanced.
@sbi @StackedCrooked You can still control order easily: MyClass get_global_MyClass() { static MyClass result; return result; }
Call that function in the order you want in main, and presto, you've controlled their destruction order.
 
7:17 PM
@sbi you don't need a singleton for that. Could just make lazily initialized globals
 
@GMan really?
 
sbi
@GMan I considered this pretty much the same as singletons. They, too, are just glorified global variables.
 
but I'd say that if you have globals that depend on each others, you've already lost ;)
 
Xeo
@GMan aren't static objects always there? not just when the function is called the first time?
 
@GMan I thought order of destruction of statics was not defined.
 
7:17 PM
@Xeo No, they are initialized the first time they are used.
If they are never used, they are never initialized.
@StackedCrooked At file scope, sure.
In function-scope, static's are equivalent to (one moment, typing):
 
sbi
@jalf But I dislike singletons exactly because they are global variables. There's other classes you can't copy (streams are a prominent example) and nobody complains about that. If you do OO, you sometimes just have to model something that's inherently not copyable.
 
@sbi but you can make multiple instances of a stream
Singletons aren't about preventing copying, but about preventing you from instantiating
which is ridiculous
 
@sbi, replying to your previous comment: I don't think passing a Logger and a LeakChecker object to almost all my class constructors is appropriate.
 
Do you need LeakChecker in every object?
 
Singletons aren't necessarily global variables. In C# land, we use some libraries like Castle Windsor to support dependency injection, and there are cases we register types as singletons and instances of our singleton type are passed in to other classes as needed
 
7:20 PM
@sbi, also because the LeakChecker will probably only be created in development builds
 
sbi
The evil thing about singletons is that they glorified globals, making people think that turning their global variables into singletons would magically remove the evil out of them being global. Needlessly prohibiting copying is stupid, too, but that's orthogonal to the main issue of singletons.
 
@Juliet depends on what we mean by singleton though. The ones defined in the design pattern of the same name are, by definition, globals
 
MyClass get_global()
{
    static MyClass result;
    return result;
}

// becomes (conceptually):

MyClass* __get_global_static_var;

void get_global_atexit()
{
    delete __get_global_static_var;
}

MyClass get_global()
{
    if (!__get_global_static_var)
    {
        __get_global_static_var = new MyClass();
        std::atexit(get_global_atexit);
    }

    return *__get_global_static_var;
}
So note that the atexit registration won't happen until it's used; that's where controlling the order comes in.
 
sbi
@StackedCrooked Yeah, I said so myself further up. All I'm saying is that this is the question where you decide whether a singleton is the lesser evil.
 
Where pointers are swinging through the night..
 
sbi
7:23 PM
@cyberrog Yeah, now that you mention this... we would need another room motto. This one must already be about three days old. That's terrible. A good idea, anyone?
 
Where singletons die.
 
@GMan I can't immediately reply to your code sample. It's a very unfamiliar way of doing things for me. I'll give it a try. But currently I'm not yet convinced that it is better than my current solution.
 
sbi
*room topic changed to Lounge<C++>: Where we shoot down singletons mercilessly. *
@PiotrLegnica :)
 
@StackedCrooked Oh, don't actually do that (the long form), that's just similar to what the compiler generates.
But if you need a global instance, just make a global getter. (Note my examples failed to return a reference, they did value instead, trivial error.)
 
@GMan I see.
 
7:25 PM
As a bonus, in C++0x the initialization of static's has to be thread-safe.
(Though I'm not sure if any compilers pay attention to it yet.)
 
sbi
@StackedCrooked Putting globals as local static variables into global functions is something I came up with long before the GoF codified singletons. IT's old, and a good technique. But they are still globals, despite the nice wrapping.
 
by the way, is there a way in on either windows or *nix to register a function to be called when a thread exits?
 
@sbi Yup, but they are only globals, and not singletons.
 
@sbi , yeah in most cases, but in some cases I want to control lifetime duration.. but appearently it is determistic after all..
 
Xeo
@jalf wouldn't it work registering it at that threads atexit function? don't know much about threading though
 
7:27 PM
@jalf I think I've seen that asked on SO, I don't think there was a way. (Just random thinking: you could easily emulate it by having a local variable first thing in a stack, and in the destructor you call all the functions registered with it.)
 
I had an ambitious plan to write something working in Factor today. I need to stop lying to myself.
 
@GMan assume I don't control the thread though (I define a library that it calls into from time to time)
so putting something on the stack would be impractical
 
Ah. :/ I'm not sure how thread-local global destruction semantics work, but if those die when the thread ends you could move it there.
 
sbi
@GMan You say that. In a company I worked for, we once had an intern one of whose job it was to find out why the code had become so sluggish. So after wrestling with the compiler for two days he comes to me, and asks me to look at an innocently looking line which ate lots of CPU time. Turns out what was missing there was an &, causing a huge map to be copied thousands of times per second. Unfortunately, that line was written by me. :(
 
Haha, ouch.
 
Xeo
7:31 PM
@sbi could be turned into anoth GotW: the most important ampersand
 
sbi
@GMan Yeah, that's been many, many years ago, but when I meet my ex-colleagues from that company, I still get to hear this once in a while. It's become part of the company's folklore. (And they seem to be especially happy that it happened to the guy they considered the C++ guru...)
@GMan Did I mention it's the being global part of singletons that I dislike? :)
 
@GMan another thing is that I usually put my wrap the main function in try catch block, the Singleton::Initializer objects are created inside the try block. It they were to be called atexit I'm outside of the try block, which can lead to uncaught exceptions.
 
@sbi Haha, yes, but I think sometimes globals are the right solution.
 
@sbi I suppose it's too late to claim that you did it on purpose, as a test? ;)
 
sbi
Oh, I meant "wrestling with the profiler" there. But I guess you figured that out anyway...
 
7:33 PM
@StackedCrooked Nothing should be throwing an exception in atexit.
 
Man I'm really slow in responding in chat.
 
sbi
@jalf Actually I initialized the guy being given the task of profiling so that we'd see what has happened. I'm not sure if this would back such a plan or hinder it...
 
@GMan well, it's not impossible
 
@StackedCrooked It is in good code. :P Destructors shall not throw exceptions.
 
@GMan: the delete of big object with many members that also have destructors, if one of them throws, it will propagate.
 
7:35 PM
@StackedCrooked then it should be caught before then ;)
 
Don't propagate exceptions from dtors.
 
@GMan : I'm undecided about that. Do you suggest putting try/catch blocks inside a destructor then? What will you do in the catch block?
 
If you throw from a dtor during an unwind, terminate will be called, and you lost.
 
@PiotrLegnica I know, and it's very unfortunate :)
 
@StackedCrooked The real question is why you've left objects in an insecure state. All objects should be able to cease existence without exceptional errors.
 
sbi
7:37 PM
@StackedCrooked Whatever you need to do to prevent it, but never throw from destructors.
4
 
And yes, if you know some code might throw thats being called in a destructor, you have to swallow it up.
 
@sbi yes but it's usually not the destructors themselves that throw
 
Don't call throwing functions from a dtor. Its not that hard.
 
In my small experience, if a class can throw from a destructor, that means there's some pending operation that needs to be done. In that case, the class should supply a sort of flush() function that lets me explicitly perform that operation, in my own controlled environment, so that an exception won't leave the destructor.
 
sbi
@StackedCrooked That doesn't make a difference. No exception should leave a destructor. Ever. Period.
 
7:40 PM
First I want to make clear that my in my code destructors don't throw (not that I know of). My main point is not trying to defend throwing from destructors but to have a catch block, just in case.
But I worry that using RAII extensively may lead to situations where a destructor throws.
 
@Stacked: In order to accomplish what? Delay the crash until 5 minutes from now when your dump file is completely irrelevant?
If your use of RAII results in destructors therwing, then you're doing it wrong.
 
@JohnDibling If I have a catch block in the main function then I can terminate the application with an error message instead of having it crash.
 
You can do that anyway.
 
If you throw from a dtor during the unwind, then it'll never reach that catch block.
2
 
@PiotrLegnica yes, indeed.
@JohnDibling Well, you're right that I can put a try/catch block inside the atexit block.
I hadn't thought of that.
So, getting back to the singleton issue. If I use a global variable instead of a singleton, then how can this global variable be accessed from other .cpp files?
 
7:49 PM
extern foo bar;
 
Other files will include MyClassGlobal.hpp which has MyClass& get_global_MyClass();, and you have MyClassGlobal.cpp which has the implementation.
 
@Stacked: That's what .h files are for.
 
Speaking of crash dumps, has anyone used Breakpad? Its lack of documentation bugs me.
 
@GMan ok, so I have two files: Logger.h and LeakChecker.h, which each their GetGlobalObject() functions, which is implemented in each header's corresponding .cpp file. How is order of destruction of both objects defined?
 
@Piotr: The documentation says it all: "An open-source multi-platform crash reporting system" What more could you possibly need?
 
7:52 PM
@StackedCrooked In the reverse order of their creation. And since they won't be created until the "get" function is called, you can explicitly define that order in main by calling the respective "get" functions.
 
@GMan so it is guaranteed that their destruction will be in reverse order of the order of the first time "getglobalobject" was called?
 
@StackedCrooked Yup.
 
@GMan now I want to make sure that the Logger outlives the LeakChecker. Then I must somehow make sure that I call the GetGlobalLogger() function first. However, I probably won't call it until it's actually needed.
@GMan while the GetGlobalLeakChecker() will be called at object creation of monitored objectgs.
 
Then you need a more robust solution. Much easier is to just call it, though.
 
I find my singleton class with scoped initializer sufficiently robust :p
 
Xeo
7:56 PM
just call each once in main. where's the problem with that?
 
@StackedCrooked ideone.com/PiUAm
 
@Xeo that would work, but I find it smelly
 
@StackedCrooked But your Singleton class breaks the single-responsibility principle.
 
@GMan how so?
 
@StackedCrooked If it wants to be a robust global variable utility, that's fine, but it has no business making my class non-copyable or single-instanced.
 
Xeo
7:58 PM
@StackedCrooked it's a question though, if the compiler would just optimize them away
 
By the way, I'm expecting a phone call, so I may disappear at any moment.
@Xeo It can't, since it has a side-effect (that of defining a moment of destruction).
 
Xeo
@GMan ah okay, good to know
so it's two function calls at the beginning of main, easiest solution, huh?
 
@GMan the singleton class is to be inherited by classes that I want to be single instanced and non-copyable. Your argument is (to me) like saying that boost::noncopyable has no business making a class noncopyable.
@GMan no prob
 
Xeo
@StackedCrooked new idea, wait a bit
 
@Xeo ok
 
8:01 PM
@StackedCrooked No. You've got your cause and effect reversed. If I have a class that I don't want copied (a single issue), I have a single utility to take care of it.
What I don't have is a utility that's noncopyable, a utility that's noncopyable and single-instanced, nor a utility that's noncyopable, single-instanced, and global.
Rather, have a single noncopyable utility, a single single-instanced utility, and a single global utility.
If you happen to use all three (well, the second imples the first, but whatever), then that's fine.
 
@GMan wouldn't a copyable singleton be self-contradictory?
 
Call it a singleton, but note you don't actually have a multiple-responsibilities utility hanging around.
@StackedCrooked Yes.
 
Xeo
@StackedCrooked how about this: (no example, just code) ideone.com/XN1wV
no first call at main to both functions
 
@GMan I'm still reading your reply, sec...
@Xeo that looks fine, but remember that many classes may need the logger. So I would end up having to to add a Logger argument to their constructors. That doesn't feel right to me either.
 
Xeo
@StackedCrooked Nono, only do that for the leak detector
it's just to make sure the logger excists before and after the leakchecker
 
8:11 PM
@Xeo ok, I see it now, it's a clever solution
 
Perhaps I'll rekindle my global variable utility and post it on my blog sooner or later.
 
@GMan so you differentiate three responsibilities: single instance, global access and non-copyableness. I can remove the noncopyableness from the singleton class and leave it to the subclass to decide.
 
Xeo
just leave that singleton class out and provide global variable
 
@GMan that leaves 2 responsibilities. I can remove the single-instance restraint by making the constructor public. This also implies that I now have to rename my class from Singleton to GlobalObject or something.
So I end up with a similar solution, but named differently ;)
 
@StackedCrooked That sounds a bit better. I have yet to see a good reason to have a single-instanced class.
 
8:14 PM
@StackedCrooked sounds good to me so far
 
Note that it doesn't need to be intrusive, either. (Not a base class.)
 
@GMan @jalf the GlobalObject still has the initializer inner class of which I make objects in the main function
 
My template was akin to: template <typename T, typename Tag> class global_ptr {};
 
@GMan I don't immediately see a non-intrusive solution. But that's probably because I need a break..
 
(It had many more policies, like creation, destruction, locking, etc. Perhaps very over-engineered.)
I love it when things compile and run correctly first try. :)
@StackedCrooked Here's how you might do it non-intrusively: ideone.com/sejqW
 
8:23 PM
@GMan thx, having a look
@GMan The global_ptr is similar to the meyer's singleton. So you have to be very careful with dependencies between global_ptr objects. My main goal with the Singleton class was to fix that by having the user explicitly define the object lifetimes relative to each other.
 
@StackedCrooked It's not like a singleton, it doesn't touch the specified T in any way. But yes, like I said in the comment at the bottom, you can add more powerful destruction methods.
 
@GMan I mean that the lazy instantiation aspect with a local static is similar to how the meyers singleton works.
 
Ah, yeah.
 
@GMan so the danger remains that a global_ptr<LeakChecker> is called earlier than the global_ptr<Logger>. I don't see a way how destruction policies could fix that (unless they require the user to explicity define them).
 
@StackedCrooked Allow me to type some more code up. But yes, there is no automated way since only you know what code uses what other code (aka, only you know the dependencies).
 
8:37 PM
@GMan yep
 
8:49 PM
@Xeo sorry for ignoring your suggestion earlier. I'm am really interested in the discussion of a general solution, and not really looking for a specific fix.
 
Xeo
stop editing, that always pings me again xD
 
@sbi if you dislike global variables, then what do you think of std::cout?
@Xeo Ok. Fine. I'll stop.
:)
 
Xeo
I knew it. ;)
 
sbi
@StackedCrooked The same as of any other.
 
@sbi A necessary evil?
 
sbi
8:54 PM
@StackedCrooked It is, sometimes, the lesser evil.
 
Xeo
>64,327 questions tagged c++
i'm really thinking of making a question solemnly for the purpose of it being the 65.535th question...
 
@Xeo 65535 - 64327 = 1208
 
Xeo
I know, preplanning :]
 
Write a script :)
A script that farms old questions and uses dictionary to change the wording a bit. Then reposts.
Doesn't matter if the answer gets closed as duplicate. It doesn't hinder achieving your goal.
 
ah finally got around to trying my code under gcc4.5. Compiles smoothly there, so I guess 4.6 is bugged after all
 
9:02 PM
@jalf Toying with C++0x stuff?
Damn now that I know editing an answer triggers an additional ping, I'm nervous.
 
@StackedCrooked yeah, but it's not even C++0x stuff that's failing
I had to swap out a few nullptrs for NULL to make it work with 4.5 though
 
sbi
@Xeo At one company I worked for, the most developers had an eye on SVN's revision numbers, trying to catch the "interesting ones". What was funny that most of them were taken by one guy who pretended to not to be interested in this game at all. :)
 
but the code that's failing seems to be relatively innocent C++03 code. A function template and some types defined in an anonymous namespace
 
Xeo
@sbi If that number comes near, just lock an important file so noone can check-in besides you :D
@StackedCrooked Nervous as in "wanting to repeatedly edit that answer" ?
 
@Xeo that's only in extreme cases, usually it's simply hesitance to edit it
 
9:07 PM
will be nice when clang supports lambdas
wouldn't mind another compiler to test on
especially one that actually tries to generate readable error messages
 
sbi
@Xeo That was the place with ~30 developers, divided into units, which were usually working on 5-6 projects in parallel, but built on a common code base. You wouldn't want to put 30 people to halt just for a funny number. It'd be really crowded in your office when they all came demanding access to that file. :)
@jalf Makes you wonder whether they have regression tests worth mentioning.
 
@sbi yeah.... At least it's better than the first beta of VS2010
 
sbi
@jalf Before clan came along como was thought to emit spectacularly good error messages.
 
where you got a linker error in a hello world
 
sbi
@jalf Oh, wait. Is GCC 4.6 still a beta?
 
9:10 PM
nah, it's supposedly a final release
 
Xeo
i'm eagerly awaiting vs11 beta.. it keeps iching in my fingers when STL talks about it in his lectures
 
I just thought that error in VS was amazing. I mean, even for a beta, you'd think someone would test "can I write a simple test program with a main function, and have it compile and link correctly?"
but yeah, pretty disappointing for gcc4.6.
 
sbi
@Xeo If some geek talking about a new compiler version makes your fingers itch, it seems high time you got your hands on a woman again.
 
@jalf seriously?
 
@StackedCrooked what, the gcc thing or VS?
 
9:12 PM
@jalf VS
 
yeah, this code would fail with a linker error: int main() {}
 
sbi
@jalf It probably wasn't in the regression tests. :) (But I bet now it is.)
 
@jalf yeah, that's a bit unreasonable.
 
@Xeo when they mention vs11, it just makes me want to punch them for having such a ridiculous release schedule
 
Xeo
hehe
 
9:15 PM
I mean, what is this, the 80s? If you have something your customers would find useful, ship it! Get it into their hands. Don't wait for the next release 2 years from now
you'd think they had to ship it out with snail-mail on floppies or something
 
Xeo
Yeah, that's pretty bad. if only vs2010 had variadic templates... i sometimes wonder if I should change to gcc just to get that.
 
down vote favorite


Hi

I have one triangle ad one circle moving objects on plane.How will i know both of them are collide to each other.
 
@Xeo have you seen Poco's Tuple class?
It may serve as a temporary fix for variadic templates.
 
sbi
@Ajay_Kumar Listen? Put your ear to the plane...
@Ajay_Kumar If you've already asked this on SO proper, please post the link here, instead of asking your question again.
 
Here's a good one: given a 10 cm high stack of paper (A4 format). Prove that if you drop this stack horizontally from a 2 meter height, the stack will remain composed when falling on the floor.
 
sbi
9:22 PM
0
Q: How to get collision detection of circle and triangle in opengl

Ajay_KumarHi I have one triangle ad one circle moving objects on plane.How will i know both of them are collide to each other. ?

 
Xeo
@StackedCrooked lol, "prove"
 
@Xeo this exercise comes from the cartoon "Hitman reborn", the answer by the greatest physician in the world was as follows: The paper was glued together, so the stack remained composed. --- Silly cartoon..
 
@sbi do u know answer ?
 
Xeo
@StackedCrooked oh, another manga reader in here?
 
@Xeo, mostly anime, but I read some manga as well.
 
9:30 PM
Sometimes I loose my patience with n00b OPs. I answered a question and the solution of the problem was a comment I added on my answer. Two days later, the OP came back, added an answer that stated the very same thing I said on the comment, and ACCEPTED his answer as the official.

http://stackoverflow.com/questions/5451489/c-weird-problem-undefined-reference/5451575#5451575

That sounds so wrong.
 
@Xeo currently reading the English translation of the first Twelve Kingdom novel.
If static is not thread-safe, does that mean that the code below is unsafe as well?
void foo()
{
static Mutex fMutex;
ScopedLock lock(fMutex);
// ....
}
 
cpx
I was thinking, when does the 'seen' under the user info changes?
 
@karlphillip Do you suppose this sufficient reason to flag his answer? It's clearly not spam, but even if the content of the answer isn't offensive, I think it's existence is...
 
@StackedCrooked Yup.
 

« first day (167 days earlier)      last day (4775 days later) »