« first day (332 days earlier)      last day (4615 days later) » 

4:01 PM
lol every programmer I know says so..
each to their own ha
 
Als
vim eh
 
1 hour ago, by Potatoswatter
A sufficiently good AI should be able to acquire a body.
But only during initialization, please. If the AI throws, I don't want the body to leak.
 
@FredOverflow LOL!
 
@Als What? You use one of those fancy pseudo-text editors too?
 
Hiya, I think I need a 2nd look, from Someone(TM):
0
A: Catch by reference when exception variable is not defined

Alf P. SteinbachThe standard does not require special optimization in the case of an unnamed exception object. On the contrary, it then requires an effect as if a temporary is copy-initialized. This copying can result in memory being dynamically allocated. N3290 ยง15.3/16: If the exception-declaration speci...

 
4:04 PM
@RMartinhoFernandes "pseudo-text editors"?
:(
 
@AlfPSteinbach Woa, this answer should get lots of upvotes. It got quotes from the Standard and code and everything!
 
But, seriously, it seems that, for C++ questions at least, "Standard = Upvotes"
 
Als
@RMartinhoFernandes: I use vim, MSVC, edit plus, Source insight, Notepad++, I just furiously write code, Text editors are least of my problems, the code i write is though :P
 
@RMartinhoFernandes Wait, who asked the other question, and why isn't it backported (or even linked) to this one?
 
4:06 PM
@EtiennedeMartel A side-effect of quoting the standard is that such answers are usually correct.
 
I've learned how to do s&r in vim and now I feel invincible.
 
@RMartinhoFernandes Yes. But equally correct answers might not get as much votes.
 
Search and replace?
 
Hi guys (:
 
The Standard is the Gospel.
 
4:06 PM
aha, you did.
8
Q: Can copy elision occur in catch statements?

R. Martinho FernandesConsider an exception class with a copy constructor with side-effects. Can a compiler skip calling the copy constructor here: try { throw ugly_exception(); } catch(ugly_exception) // ignoring the exception, so I'm not naming it { } What about this: try { something_that_throws_ugly_ex...

 
@RMartinhoFernandes Yup.
Tl;dw.
 
@EtiennedeMartel I think it makes sense that if they are equally correct, but one refers to an authoritative source, that one gets more upvotes.
 
Als
Can anyone care tell more about Side Effects?
@RMartinhoFernandes: ^^^^^^^^^^^^^^^
 
Would you like to know more about Left or Right ones?
 
Als
@CatPlusPlus: Seriously!
 
4:08 PM
@CatPlusPlus Both.
clear:both
 
Als
No trick, I want to know if i understand correctly
 
Side-effects: n. non-pure stuff that happens.
 
Rockets away!
 
Als
plain english please?
preferably, an code example
 
You seriously don't know this?
 
4:10 PM
std::cout << "foo";
 
> When the handler declares a reference to a non-constant object, any changes to the referenced object are changes to the temporary object initialized when the throw-expression was executed and will have effect should that object be rethrown.
So wait
if there is a catch(E const&)
 
Als
@RMartinhoFernandes: I need a simple example to explain it to someone
 
then the throw E(); can't copy that temporary.
 
int a; bool foo() { a = 42; return true; } int main() { foo(); /* modifying a is a side effect */ }
 
So E() must be the temporary to bind to the reference? O_O
 
Als
4:12 PM
@CatPlusPlus: And how do you explain its a side effect, an definition?
 
In a nutshell, of the result of foo(x) depends on anything other than the value of x, then it depends on a side effect. If the function modifies anything other than its return value, it causes a side effect
 
I prefer to define pure, and call side-effects to everything else.
@jalf Anything visible outside. Changing local objects is fair game.
 
I don't have any fancy definitions.
It's intuitive.
 
Als
Well, That is what i was asked :( and i didn't have an good definition
 
so side effects can be user input or global variables or anything else that's not directly part of the function signature
 
4:13 PM
i liked my example
 
@RMartinhoFernandes or anything visible to itself (a static local variable isn't visible outside, but it's a side effect which might affect the next call to the function)
 
Als
Anything that a compiler would not know to do if it were to do away with the function call by itself
does that look better?
 
@jalf Oh, right.
@Als Huh, consider a super-smart compiler.
 
CleverGCC.
 
Als
Then can we define a simple definition or not?
 
4:16 PM
@jalf's.
 
@Als Defining definitions is easy
 
Als
As it seems it would need standard quoted rules to explain that then
 
the tricky part is making ones that are correct and actually work in all cases
 
@Alf you missed the part of the question that mentions the by-value part. The question was about catch(T) vs catch(T&).
 
compiler theory people have definitions of this kind of stuff though
but I can't remember it
 
4:19 PM
@RMartinhoFernandes huh, i quoted the relevant standardeese on that, + elucidated what it means.
 
Als
@jalf: Hmm, I was seeing this same Q at work and someone at work who happened to be at my desk, asked me whats a side effect anyway? and then I didn't have a good definition...I was a lil at loss of words.
 
anything that's not a function's input or output :)
the entire world minus anything listed in the function signature ;)
 
Als
:) didn't strike me!
I was blabbering more of an examples and the person wanted an easy definition.
And was duh...
 
@RMartinhoFernandes ok i added a bullet list summary, thank you
 
if that doesn't satisfy him, I've got a book on type systems in programming languages which probably defines it pretty rigorously
 
Als
4:29 PM
@jalf: He might just would have run away :P
@jalf: Thanks by the way for the definition, tommorow im gonna dazzle that person(oh that person is a she)so maybe i earn some brownie points :P
 
16 mins ago, by jalf
@RMartinhoFernandes or anything visible to itself (a static local variable isn't visible outside, but it's a side effect which might affect the next call to the function)
Hah!
Missed it too!
 
@RMartinhoFernandes "ugh"?
 
@AlfPSteinbach The nasty code. :)
 
Als
okay gonna go for din din, see you folks in a jiffy.
 
4:39 PM
Gys, I was told before that using nested ifs takes it longer for the stack to unwind
Is it true?
I don't see how that is different from placing the ifs seperately
 
By whom?
Using heavily nested ifs only makes your eyes take longer to unwind.
 
@Als yeah, that's what I did when faced with that book at uni
 
A more experienced programmer than myself :) And yeah that's what I thought
 
Unfortunately, it appears that programming experience does not equate to wisdom.
 
Wow thanks for the answer to my question Alf. It's going to take a while to sit back and analyse that.
 
5:00 PM
One very experienced, grey-haired "software architect" kindly educated me that C always evaluates expressions left-to-right, as in f( ++i, ++i );
 
> Ok this program I am working on seems to be all ok except there is a problem.
 
Ah yes, the all conforming yet extremely lax mind compiler.
"No way this can't work!"
 
0
A: c++ - Store pointers or objects in classes?

Tony The LionIf you have a big object inside your A class, then I'd store a pointer to it, but for small objects, or primitive types, you should not really need to store pointers, in most cases. Also, when something is stored on the stack or on the heap is really implementation dependent, and A a is not alwa...

please tell me if I'm lying?
 
Als
@TonyTheLion: A is gauranteed to be on stack...yes
 
@Als oh, well, I've been told several times on SO that you can't depend on things being on the stack or not
 
Als
5:12 PM
Automatic variables are on a data structure, which is actually an stack
@TonyTheLion: Thats Pedantry.
I too sometimes brag about it
but Yes those are on stack
because the underlying data structure is always an stack
pedantically correct answer i would say.
 
@Als so should I change it?
 
Als
@TonyTheLion: no no, Just add the Freestore word before pedants attack you
:P
 
but we are pedants aren't we?
 
Als
they wont let go of you unless you mention FreeStore
 
@Als I've mentioned it now
 
Als
5:15 PM
Congrats Now you are immune to pedants.
:)
 
lol, well, some pedant will find something to pick on, I'm sure :P
 
Als
I will give you one
Why store raw pointers at all?
smart pointers, if at all you need to use pointers
 
I don't like that question on so many levels.
 
Als
@RMartinhoFernandes: It does not have any specifics
 
@RMartinhoFernandes Yeah I'm not touching it.
 
Als
5:17 PM
difficult to answer
One who uses popular words on that one, wins the most rep
 
The whole mish mash of performance, heap, stack, copies, moves...
 
very difficult to answer, thought I'd have a stab anyways, I'm repwhoring after all :P
 
But no semantics in sight.
 
Als
that is what happens to such questions, populist answers win
@TonyTheLion: You have a good chance of winning this one, in my exp
 
5:21 PM
Hehe, @Als and @Tony fighting for rep.
 
Als
@RMartinhoFernandes: haha
 
@RMartinhoFernandes got downvoted on that, I wonder why
did I say something incorrect?
 
@RMartinhoFernandes I love how they both got downvoted
along with the Q itself, it seems
 
I don't understand this sometimes
 
Als
Why did i get downvoted?
 
5:22 PM
probably a troll
 
I guess the question downvote was for the reason Fred explained in the comment.
 
Als
Is my answer wrong?
 
Why am I not upvoted? :P
 
Als
@robert: you didnt even post an answer!
 
Hm... fair enough!
 
5:24 PM
@Potatoswatter Did you point him to the sequence point FAQ?
 
sorry i've been away. what?
 
Als
Can anyone explain why i am i being downvoted on that one?
 
@Potatoswatter click the little arrow on his message.
 
Oh. No, he was beyond that.
If he read things, that would mean he didn't know everything.
 
Als
@jalf: ahh just corrected! while you poseted the comment
 
5:26 PM
@Als afaik, Kerreks comment is correct
 
Does Barton Nackman work with friend function templates?
 
(but I didn't downvote anyone)
 
Als
@jalf: I already modified that
and now its correct IMO
 
Speaking of downvotes, I have 4 spare.
Finding bad questions is easy, but they don't cost anything :(
 
@FredOverflow Yes, I believe it should. I was just thinking about thatโ€ฆ
 
Als
5:32 PM
There you go I killed it.
3
A: C++, are multiple inherited constructors called multiple times?

AlsBase() DerivedBaseTwo() Base() DerivedBaseOne() Derived() The Order is indeed well defined and it depends on the order in which you mention the derivation for base classes and the order in which you declare members in the class for members. Reference: C++ Standard C++03: 12.6.2/5, ...

 
0
Q: invalid operands of types - c++

fgfjhgrjr erjhmI have a class named ThreeDigits on c++ code. I overloaded the + operand, this way: ThreeDigits* ThreeDigits::operator+(const ThreeDigits &number) const { double result= getNumber()+number.getNumber(); ThreeDigits* new_result=new ThreeDigits(result); return new_result; } but when...

I think the problem here is that he is adding the pointers instead of the overloaded operator+ being called, right?
 
Als
But ofcourse
invalid operands of types ThreeDigits* and ThreeDigits* to binary operator+
he doesn't have anything which takes ThreeDigits*
 
I forgot my book, so I have a boring half an hour bus trip ahead of me. I'm pissed off.
See you after the break!
 
Als
go and upvote me @RMartinhoFernandes
I need to hit the rep limit on my comeback day!
@TonyTheLion: Why did you delete your answer?
It just needed edition to add more detail of the initialization order
 
@FredOverflow Come to think of it, that's actually a very powerful surrogate for function template partial specialization.
 
Als
5:57 PM
huh, Is this unlucky or woot :(
6
A: Using class member name in a constructor

AlsThat Thing is called a Member Initializer List in C++. There is a difference between Initializing a member using initializer list(2nd Example) and assigning it an value inside the constructor body(1st Example). When you initialize fields via initializer list the constructors will be called once...

 
Brevity is wit.
 
Als
hmm
 
6:11 PM
All those C++ questions look hard
 
Als
@LewsTherin: Life is hard too, We live it to the fullest though
And want to keep on living as well.
 
Oh yes! Fair point :)
 
Als
:)
@AlfPSteinbach: A lil confused about terms, a quick clarification pls
 
@Potatoswatter It is? Well, as long as you give me credit for your Nobel price... ;)
 
Als
6:14 PM
Type my1 = my2 is Copy Initialization and Type my1(my2) is Direct Initialization
or is it otherway round....
grr I always mix them.
 
they do the same thing though ?
sounds like its the other way around from the look
 
Als
Yes they call the copy constructor
 
@Als yes
@Als no
@Als heh
 
:O lol
 
@LewsTherin no
@LewsTherin huh
 
Als
6:16 PM
The terms were correct?
 
Als
I know they act differently
 
Yes.
 
Als
Just confused in what is what
 
How do they act differently?
 
Als
6:17 PM
@LewsTherin: see this
8
Q: Is there a difference in C++ between copy initialization and direct initialization?

rlbondSuppose I have this function: void my_test() { A a1 = A_factory_func(); A a2(A_factory_func()); double b1 = 0.5; double b2(0.5); A c1; A c2 = A(); A c3(A()); } In each grouping, are these statements identical? Or is there an extra (possible optimizable) copy in so...

 
Copy initialization considers implicit conversions while direct initialization doesn't.
 
Oh is this not when elision occurs?
 
Als
the keyword explicit matters to one of them :)
 
Elision can happen in both situations, assuming appropriate circumstances.
 
I so need to get a good C++ book
3
But they don't explain all this in a book though
 
6:19 PM
Might I suggest [Guru of the Week](www.gotw.ca) ?
 
@LucDanton Perhaps gotw.ca?
 
The fuck is wrong with a .ca domain :(
 
Als
@LucDanton: I believe @LewsTherin, needs to read a good book first
 
@JerryCoffin What is this wizardry!
 
Als
Jumping to gotw without knowing basics i wouldn't advice
 
6:21 PM
@LucDanton Nothing -- you need the "http://" for it to be recognized as a URL.
 
I guess that's useful to not convert [lambda](expressions& i) { blah; }.
(But that's what ` is for.)
 
@LucDanton Yup -- just be careful not to use a label named "http", followed immediately by a single-line C++ comment...
 
Als
@JerryCoffin: ah that age old q here
 
@Als You have a pretty fair point there -- especially now that substantial parts of GOTW are becoming somewhat dated.
@Als I think "trick" is probably more to the point than "q". It is kind of a cute trick though...
 
Als
221
A: Hidden Features of C++?

BenYou can put URIs into C++ source without error. For example: void foo() { http://stackoverflow.com/ int bar = 4; ... }

 
6:24 PM
I suppose I should have pointed to the relevant GotW article about copy initialization. (There's one right?)
 
Als
I would first advocate reading atleast one good book which teaches basic C++
before jumping to Meyers or Sutters
 
Accelerated C++
C++ Primer
Programming: Principles and Practice Using C++
 
Als
They don't write it from beginner perspective
 
^ pick one of them
 
@LucDanton no no
 
6:26 PM
@AlfPSteinbach Go on
 
@FredOverflow saved the list
ty
 
It's all just ordinary construction, but with copy initialization it's formally as if a T objects temporary is first constructed on the right hand side.
 
Als
@LewsTherin: @FredOverflow, and @sbi, @AlfPSteinbach are guys who actually teach/taught C++, So you know whom to ask :)
 
The copy initialization can fail (not be accepted) due to lack of accessible copy constructor.
@Als Well I think it's a bit of a put-down to not mention me in that list.
 
Mmmn, cool. I say you guys must be loaded :D
 
6:28 PM
@AlfPSteinbach Is the formal stuff still relevant for C++11?
 
Als
uhm ah I am sorry :( @AlfPSteinbach, Added
 
lol
 
@LewsTherin compiled, linked, loaded and executed!
 
@LucDanton why shouldn't it be still relevant for C++11?
 
haha all the way through :P
 
Als
6:29 PM
@FredOverflow: you should teach me C++11! :)
 
@LucDanton Yes, and it got even more complicated :)
 
@AlfPSteinbach Because I can't find the relevant part. AFAICT copy init and direct init are largely syntax issues.
 
@Als because the pedantry comments annoy me, that's why I deleted my answer
 
(Apart from the implicit conversions being taken into account.)
 
Als
@TonyTheLion: No, Its correct, it just missed a part, but it had that valuable statement
 
6:31 PM
@Als C++11 Lesson 1: named rvalue references are lvalues, and unnamed rvalue references are xvalues.
Next week's topic: Reference collapsing rules, or: how T&& can bind to an lvalue.
 
@Als what valuable statement?
 
Als
@TonyTheLion: " it's constructed from Base then Derived downwards, and on destruction, it's destroyed from Derived, then Base upwards."
@FredOverflow: You are teaching me or scaring the shitt out of me!
 
@LucDanton Right -- there are some requirements about what ctors (officially) have to be visible, even if they're never actually used. In reality, most compilers ignore those requirements unless you ask for pedantic errors though (even Comeau normally ignores them...)
 
@LucDanton In N3290 it's §8.15/14 through §8.15/16.
 
6:33 PM
@AlfPSteinbach 8.5?
 
Als
@TonyTheLion: And you have no downvotes on that one, actually
 
@Als yea, but I can't be asked to change it again now
 
I think C++ desperately needs a type constructor for recursively nested unions called onions. Anyone with me?
5
 
@LucDanton Actually, the very first GOTW was (at least partly) about this.
 
@JerryCoffin I remember it.
 
Als
6:35 PM
@TonyTheLion: Hmm..
 
@AlfPSteinbach Thanks.
 
lol, just got the "Strunk & White" badge :P
 
Als
@TonyTheLion: Oh tantalizingly close to 10k
oh me too i got that one today!
 
@FredOverflow For onions, "throw" will be changed to "cry" (and is always invoked implicitly).
 
Als
what are the odds haa @TonyTheLion
 
6:36 PM
I've run up and down 8.5 so many times and I still couldn't see the tree in the forest :)
 
@Als Yes, I'm very damn close, like 155 rep to go
 
Is it bad if a member object had a pointer to the class that holds it?
 
Als
@TonyTheLion: I would say, tommorow is the D-Day then
 
@LewsTherin It can be legitimate, but it's generally preferable to avoid it if at all reasonable.
 
Als
@LewsTherin: Code please
You need to think where and how that would be useful, if you get a fancy idea like that.
 
6:38 PM
@LucDanton well i had to put some wieners in water. but here's code example:
#include <stdio.h>

struct A
{
    operator char const* () const { return 0; }
};

struct B
{
    B( char const* ) {}
};

int main()
{
    A   a;
    B   o1( a );
    B   o2 = a;
}
 
ok a few mins
 
@Als hehe, yea if there's enough questions I can actually answer
 
@TonyTheLion You close to 10K?
 
Als
@TonyTheLion: oh you sure can, you hold back a lot for the final burst eh :P
 
@Als lol, yea well I hate being downvoted to shit
@CodeMonkey yea 155 rep to go!!
 
6:40 PM
@TonyTheLion Perhaps we can help with that...
 
Als
@TonyTheLion: I don't see 155
:P
 
@TonyTheLion I hit 10K a few weeks ago
I thought it would be exciting but the excitement wears off :(
 
@Als huh?
 
Als
@CodeMonkey: haha I know the feeling
 
I need another year and half to reach 25K
 
6:41 PM
@JerryCoffin hehe yea you could :P
 
@AlfPSteinbach What of it?
 
Als
@TonyTheLion: I gave you few imaginary $
 
@Als It took me 1 year and 10 months to reach 10K
 
in ideone it always results in a compilation error
 
they need to add some more stuff for 10K users to do
 
Als
6:42 PM
@CodeMonkey: Just checked, 11 months and I am at 23k
 
unless the constructor doesn't have "this" pointer
 
@Als i think if you graphed it most of it would be lately, for FAQ entries, yes?
 
@Als Thx :P
 
Als
@AlfPSteinbach: No
 
6:44 PM
ok, less then 100 rep to go :P
 
Als
@AlfPSteinbach: Just one of my top 5 answers is an FAQ.
Why did you think most for FAQ entries btw?
 
they seem to generate a good deal of rep points
 
Als
@LewsTherin: No it workss, you had some compilation errors
@AlfPSteinbach: I have 3 faq entires
 
@Als why would you assign this to Aptr in B?
I'm confused
 
@Als why is class A; at the top?
 
Als
6:48 PM
@TonyTheLion: I didn't assign anything i just made @LewsTherin, code compilable so he could explain us what idea he had behind it
@LewsTherin: Read Forward Declarations
 
0
Q: map of vectors C++

Gaurish TelangHi if I C++ I created an STL map of the type map<int, vec<double>> are the vectors stored under the different keys placed consecutively in memory?

 
@TonyTheLion kinda complicate....While the player is editing the game I want him to see changes real time
 
heh, one more upboat and I've got a new shiny badge :P
 
hence call update .. :(
@Als ok thanks
 
Als
@TonyTheLion: too bad i already gave you my vote on that
 
6:49 PM
lol
 
Als
I have nothing left to give...sobs...
 
Badges? Where?
 
Als
@RMartinhoFernandes: Pushing the @TonyTheLion, to 10k mind joining us?
Or are you gonna be pedantic arse?
 
I just lost 10 rep, randomly it seems
second time this happened today :(
 
Als
@TonyTheLion: I seemed to notice that
 
6:51 PM
Maybe someone withdrew a vote.
 
hmm
but that would constitute a downvote?
 
Als
that someone is bot?
no it doesnt
 
@TonyTheLion No. A downvote is -2.
 
Als
upvote and downvote are separate you see
even separate arrow buttons
 
You can have "no vote".
 
6:52 PM
oh I see
 
Als
I think i have reached rep limit, but someone can upvote me actually, Im close to 2k votes on C++ tag :P
 
lol
Success is an error?
 
That's a common appearance in TDWTF.
 
I also personally witnessed the CLI version of it.
$ something I can't remember
error: Success
$
 
6:54 PM
@Als what's not fair?
the accepted answer I guess?
 
@RMartinhoFernandes That's strerrno for 0 isn't it?
 
I suspect that happened because perror prints "Success" if there's no error.
 
Als
Yeah its not fair on me :P @TonyTheLion
 
(With glibc)
 
@LucDanton Right.
@Als Go for Populist!
 
6:56 PM
@Als ?
 
Als
@RMartinhoFernandes: Way off it
@CodeMonkey: ?
 
@Als ?
 
I want to play this game too!
?
 
Als
@CodeMonkey: Woot?
 
@Als Raise the roof!
I was just wondering why it is unfair
 
6:57 PM
How much do you need for populist?
 
@TonyTheLion Answer outscored an accepted answer with score of more than 10 by more than 2x
 
Als
@CodeMonkey: Because I wrote a lot of things :)
 
Twice the accepted answer, and the accepted answer must be at 11+.
 
Als
@RMartinhoFernandes: I aint at 11 lol
leave aside accepted thats a measly 1!
 
@Als You need to be at least at 22!
 
Als
6:59 PM
@RMartinhoFernandes: That looks highly unlikely
I dont know 22 people on SO haha
I doubt 22 people know me either
 

« first day (332 days earlier)      last day (4615 days later) »