« first day (373 days earlier)      last day (4558 days later) » 
02:00 - 18:0018:00 - 00:00

6:36 PM
@sbi Just one last thought ;-) Microsoft's decision to pause the program at the end when starting via Ctrl+F5 is an arbitrary choice (there are other IDEs that don't have this behavior). What would you have your students do if there was no such artificial pause?
 
@FredOverflow other IDEs like QtCreator and Eclips show the program output in the IDE's console window (the one where VS shows compiler errors).
 
Whatever, I want to know what sbi would teach his students if Visual Studio always closed the console immediately as soon as the program exits.
 
std::cout << "Press CTRL-C to continue...";
while (true);
If there are many computers then it would probably cause an increase of temperature in the room.
 
char c; while (cin >> c) { if (c == 'q') std::exit(0); }
 
Or, you know, just run CLI applications from CLI.
 
6:44 PM
::MessageBox(NULL, TEXT("C++"), TEXT("Press OK to continue."), MB_OK);
Or something like that.
 
Missing title and type spec.
 
@CatPlusPlus fixed
 
I got a question about multidimensional arrays
 
Use std::vector.
 
6:45 PM
But that is not my case
 
Replace it with std::vector.
 
Or Boost.MultiArray.
 
hmmm, I have a QWidget in which I draw a square, how can I make sure that the square doesn't go outside (becomes invisible) of the enclosing Widget, when moving the square around?
 
By checking the bounds.
 
Again: That is not my case. Is it correct that you return multidimensional arrays by writing "Type**" and do you make the native arrays with new/delete?
 
6:47 PM
hmmm can you elaborate?
check the bounds inside the paint event?
 
Again: you should not make dynamic arrays by hand.
 
Educational purposes, so again: Yes I am
 
T** is a pointer to pointer to T.
Oh, cool, loading shaders from file works.
 
57
Q: How do I use arrays in C++?

FredOverflowC++ inherited arrays from C where they are used virtually everywhere. C++ provides abstractions that are easier to use and less error-prone (std::vector<T> since C++98 and std::array<T, n> since C++11), so the need for arrays does not arise quite as often as it does in C. However, whe...

 
@FredOverflow Hi
It is for educational purposes, I am learning C++
 
6:50 PM
Arrays are rarely used primitives, and you do not need them.
 
@BPDeveloper Everything you want to know about arrays is in the linked FAQ. Part 4 deals with multidimensional arrays specifically.
 
When you'll need them, you won't have issues with their quirks.
Yay, runtime shaders.
 
@TonyTheLion Define a grid that has a fixed width and height. Then make sure your square's coordinates are always within the grid (this is where you need to perform bound checking when moving the square). Finally you need to define a function that can draw the entire grid. If the square never leaves the grid, then it will always be visible.
 
what is the difference between new/delete and just making an object of a class?
 
@BPDeveloper new creates it on the free store. You get one more level of indirection and a dynamic lifetime.
 
6:52 PM
Is it because it can be passed across scopes?
 
You can pass non-dynamic objects "into" scopes, but not "out of" scopes (Well, you can, but then you get a copy. Well, except if you return statics by reference.)
 
Function-local statics are not really in the scope.
 
If your object needs to be created every time you enter a function, and that object needs to survive the function call, then you need a dynamic object.
 
So if you have a function that makes an object you can't return the object unless it is made with new?
 
Basically, yes.
 
6:55 PM
You can return a copy.
 
Yes, but then you don't have the original :)
 
does it automatically make a copy if you return a object made that way?
 
Also, copies don't work together with subtype polymorphism (object slicing).
@BPDeveloper What is "that way"?
If your return type is MyClass, then you implicitly get a copy.
 
the SomeClassIsAwesome awesomeClass;
 
@BPDeveloper This is very nicely explained in the DeepC slides.
 
6:57 PM
Well, technically you get a copy, but the compiler will probably optimize that copy away (RVO/NRVO).
 
SomeClass::getAnObject() {
Warrior warrior;

return warrior;
}
That was the way I was thinking of @FredOverflow
 
You missed the return type. I assume it is Warrior?
 
Yes, sorry
 
Then it will work.
Can we see the data members of Warrior?
 
It was just a made-up example
Why would this work? Or do you mean it return a copy?
 
7:01 PM
@BPDeveloper if warrior has a destructor then you'll be in trouble unless you have correctly implemented the copy constructor and copy assignment operator.
 
It's just that as soon as you copy objects around, you have to know the rule of three.
74
Q: What is The Rule of Three?

FredOverflowWhat does copying an object mean? What are the copy constructor and the copy assignment operator? When do I need to declare them myself? How can I prevent my objects from being copied?

 
I am just looking for basic usage :) If it correct that you use new to make an object that will be returned from an function I will use that as long
 
And then you also need to learn the copy/swap idiom.
And after that you'll have to make yourself familiar with move semantics.
 
@BPDeveloper The "correct" way depends on a lot of things. Again, as long as your objects behave well when copied, you don't need new.
187
Q: In C++, why should `new` be used as little as possible?

BitgardenI stumbled upon the Stack Overflow question Memory leak with std::string when using std::list?. One of the first posters says: Stop using new so much. I can't see any reason you used new anywhere you did. You can create objects by value in C++ and it's one of the huge advantages to us...

 
@BPDeveloper Before all that you must learn RAII.
@FredOverflow IMO it's delete that should be used as little as possible.
 
7:06 PM
Man, I have almost just started with C++
 
@BPDeveloper And hence you should not touch naked pointers immediately.
 
But I couldn't hold my hands off
 
@BPDeveloper this stuff is really essential. You can't program good C++ code without this knowlegde.
 
@BPDeveloper What book are you learning from?
 
C++ How to program
 
7:09 PM
 
Most C++ books are not recommended. There are only a few good ones for beginners. "Accelerated C++" is what got me started and I recommend it to everyone wanting to learn the language.
 
> 3.4 Data Members, set Functions and get Functions 71
yuck
 
@StackedCrooked new, too.
 
40 pages on arrays and only 7 pages on vectors. That's a fail in my book. (pardon the pun)
 
Lol setters.
 
7:12 PM
45 pages on subtype polymorphism and only 16 pages on templates :(
 
Another thing, I don't know if anyone of you have done some Objective-C, but there are no release/retain count in C++?
 
Hey, it mentions unique_ptr! Albeit not sooner than page 648.
@BPDeveloper What is that, reference counting? We have std::shared_ptr<T> for that which does all the bookkeeping automatically without your intervention.
 
If you have two pointers to the same object
 
The Standard Template Library is introduced on page 850. I'm sorry, but I can't recommend that book.
 
then you don't want to invoke delete before both of them do not need them anymore
 
7:15 PM
std::shared_ptr<T> invokes the delete for you at the right time.
In modern C++, you absolutely never have to write delete yourself.
 
so the object has an internal count on how many other objects that points to it before it calls delete itself
you instead invoke "release"
 
Yes, it's called reference counting.
 
@BPDeveloper You don't even have to invoke release in C++ for reference counting to work. All you have to do is sit back and relax. Trust me, it really works. Just use std::shared_ptr<T> instead of T*, of course.
 
Raw pointers in C++ don't do anything on their own.
 
Right, hence I don't recommend touching naked pointers.
 
7:17 PM
But I need to do it:)
 
std::shared_ptr<MyClass> p(new MyClass());
std::shared_ptr<MyClass> q(p);
// as soon as p and q die, the MyClass object gets deleted automatically
@BPDeveloper Why?
 
No, you don't.
And it's best to forget all about Obj-C, really.
 
Yes, school
 
@BPDeveloper Post the exact assignment then.
 
Same with C.
 
7:18 PM
No assignments
 
So who is telling you to do it if there is no assignment?
 
Thinking in terms of ownership and object lifetime are cornerstones of good C++ programming IMO. std::shared_ptr has the downside that it reduces your awareness of these.
 
Well, std::shared_ptr implies shared ownership.
 
exactly
 
lecture
 
7:19 PM
Shared ownership is fuzzy.
Scope-bound resource management is superior.
 
Yes, but sometimes you need shared ownership.
@BPDeveloper And the lecture comes with no assignments to work on?
 
Sometimes you need reinterpret_cast. :)
 
Sometimes you need macros :)
 
@FredOverflow Any recommendations on where to read on new/delete operator?
@FredOverflow What fun would the tasks/assignments be if I just gave them to others? I rather learn it myself
 
@BPDeveloper Open your book index and browse the N and D parts of it?
@BPDeveloper I just want to read the assignment to see precisely what it asks you to do. I don't intent to solve it for you.
 
7:26 PM
Yeah, we just want to laugh at the person who wrote it.
 
Normal people have lunch time. We have lynch time.
 
Evening
 
I always used to think that if I were born a few hundred years ago my profession would have been to build clockwork. Seems to be the closest to programming.
Evening.
It would be hilarious to play this game as adults.
 
8:03 PM
I think I like Elenore more than Cannabinoids.
According to Wikipedia overloading is a feature of weakly typed languages. I'm not sure if I agree with that.
 
i think you shouldnt see that term negative, and as it is marked on top on the page, the article still lacks some proper writing and evidence.
 
[citation needed]
Default arguments are a form of implicit overloads.
 
Default arguments being a form of overloads doesn't prove or disprove whether overloading is a feature of weakly typed languages.
 
Also, C# and Java are both strongly typed, and have overloading.
It disproves that it's a feature of only weakly typed languages.
 
Typical example of weak typing is where 1 == "1" is not an error. However, a strongly language that supports operator overloading could provide an overload that enables this syntax. Does this (library feature) change a strongly typed language into a weakly typed language?
The distinction is really vague for me.
 
8:19 PM
No, a weakly typed language does a coercion, that's why the comparison succeeds. Strongly typed language will not do any implicit conversions, whether there's overloaded operator or not.
Or something like that. All that theory is fuzzy and boring, anyway.
 
You are defining the distinction between weak and strong typing by the inner working of the program. I would compare them by (observable) behavior. If a strongly typed programming language can be made to behave exactly like a weakly typed programming language (through overload and stuff) then that would mean the distinction is kind of meaningless.
 
8:36 PM
In other words, I agree that it's fuzzy.
 
But you usually can't overload for built-in types.
My usual definition of strong typing is "the type of the value never changes".
It might make more or less sense depending on how drunk you are.
 
I'll give it a try.
In this song the lyrics "fire in your eyes" really sound like "fire in your arse" to me. Listen at 0:14, 0:28 and especially at 0:51 (where she says: "I'm in your arse").
 
8:51 PM
Lol.
 
Right?
 
Misheard lyrics are the best lyrics.
 
I thought it would have been benny lava.
 
9:34 PM
 
9:47 PM
OMG, I just slept Monday away.
Hi btw.
 
I watched Futurama it away
 
Neat, my robotness is being doubted.
 
by who?
 
I'm just lolling at how long I'm slacking over my Robotics coursework and final year project
also, owned: my Geniusâ„¢ness isn't in doubt
 
9:50 PM
Right.
Now I have a big problem. I have no decent food at home (I mean, I have cookies and stuff like that, but not meat or rice or something). And it's too late to find a restaurant open.
 
don't you have 24hour shops?
there's a large supermarket within 5-10 minutes walk of where I live that's open to midnight every day
 
Not anywhere nearby.
 
then you need to plan this effort in advance :P
or search the cupboards/freezers again
 
I noticed that.
 
Order a pizza.
 
9:54 PM
yeah, mcdonalds here is open until 2am
 
There's a McDonalds within a 20 minutes walk. I guess I'll have to take that.
 
there should be fast food places that are open to cater to binge drinkers
 
I live on the suburbs of a small city. There aren't enough binge drinkers here to cater for :)
 
haha
20 minutes to a MacDonalds is plenty binge drinking range
 
Anyway, I'm going out now. Be back in about 40 minutes :)
 
9:56 PM
I shall be timing you
so chop chop
I've got plenty to bitch about myself and I intend for you to be here to listen
 
Lol.
>>> Unmerging dev-java/sun-jdk-1.6.0.27...
Here's Java gone from the server.
Buh-bye.
 
niice
 
10:41 PM
I'm back.
@sbi It compiles fine as a Bra*nfuck program that prints three times whatever the first tape cell was initialised with.
 
good
now let me explain to you in great detail exactly how unfulfilling I find my current life
 
Fire away.
 
10:56 PM
well
top of the list has got to be my damn digestion
it, of course, fails to function as always
then there's the fact that I'm cripplingly lonely in pretty much every respect
also, the fact that I fail to find the motivation for anything, even coding my own personal dreams
also, other people owe me a stunning amount of money and I'm short
 
@DeadMG Still at the hotel?
 
no, I have a new place to live
which is a plus
and it's got super-fast internets
but they're not very reliable
 
Well, staying home using the internets is not going to scratch your gregarious itch.
 
yes, that's rather obvious
however, around here, the only other definition of being social involves drinking so much alcohol you require medical attention
 
I'm being a bit of an hypocrite, because I rarely go out, but then I don't mind being alone.
 
11:01 PM
I fail at bitmaps and textures. Enough for today/yesterday.
 
the thing is, it's easy to suggest going out, but I have nowhere to go and nobody to go there with
 
Oh wait, it works.
I just tried to unload and then upload.
Woo, I have a texture.
The resizing to the nearest power-of-2 thing doesn't work, but screw that for now.
 
eh
 
ok, I have to prevent squares drawn to my screen from overlapping when moving around, anyone know how to best achieve that?
 
Direct3D had an annoying habit of doing that for me
 
11:07 PM
@DeadMG But being a hermit is fun! Well, maybe it isn't.
@TonyTheLion More info needed I guess.
 
well, I don't mind being a hermit really
 
Check for collisions and make them explode into tiny bits.
 
but the current state is more than a tad excessive
 
@RMartinhoFernandes what info do you need?
 
What are you using to draw the squares?
What does "moving around" mean?
 
11:09 PM
I have a canvas, onto this canvas I draw 50x50 squares, lets say 2. I am able to move one with the arrow keypad. I do not want it to be able to move over the top of the other, so it has to hit the other squares edges and then stop. I'm using Qt
 
basically in the function where you move the first square, you need to check to see if it would collide with the other
you need collision detection
 
Are the squares axis-aligned?
Or do they have arbitrary rotations?
Axis-aligned is simpler.
 
you can only move up-down, and left-right
and the square itself doesn't rotate
 
Before actually moving it, check whether they'd overlap in the new position.
I.e. check for intersection.
 
11:14 PM
collision detection is a well-known and well-studied problem
for it has important performance implications in games
 
70
A: Determine if two rectangles overlap each other?

Charles Bretanaif (RectA.X1 < RectB.X2 && RectA.X2 > RectB.X1 && RectA.Y1 < RectB.Y2 && RectA.Y2 > RectB.Y1) say you have Rect A, and Rect B. Proof is by contradiction. Any one of four conditions guarantees that NO OVERLAP CAN EXIST. Cond1. If A's left edge is to the...

 
you can do it in O(n log n) I believe, even in the arbitrary 3D case
 
vertex count, I believe
usually AABBs are used to simplify
 
In his case, he is moving AABBs, so it's not really a simplification :)
 
11:17 PM
agreed
 
If there's only one moving square, linear in the number of squares is the baseline.
 
@CatPlusPlus I guess X1,Y1 would be upper left corner and X2,Y2 lower right corner right?
 
yep
 
What game are you writing?
 
cool thanks
 
11:20 PM
0
Q: Inline in source file

DaniI have a big class with lots of utility functions. those functions are very small and I would like them inlined. The problem is they are all in a source file and should stay in the source file and not move to the header file (so I don't need to recompile everything every time one changes). If I...

 
(You're writing a game, right?)
 
yeah, I'm trying to write tetris, but I'm first doing it with ordinary squares
 
People have silly expectations sometimes.
 
@CatPlusPlus Magic!
 
It's Tetris month!
 
11:21 PM
because I have never really done all the moving things around on the screen business
 
(Also, copycat.)
 
@CatPlusPlus lol, actually I had started this a while back, longer then before you started
@StackedCrooked was the the one to give me that idea
@CatPlusPlus I'm a cat for a reason :P
 
Do you want fluid movement, or grid-based one?
Because for grid collision check is even simpler, just check whether cell below has something in it.
 
uh, grid == pixels
 
11:23 PM
Now that I think about it, that doesn't mean the movement can't be fluid.
I mean block-sized grid.
 
so unless you're going to start anti-aliasing
 
Anyway, I'm so far away from any movement, it's not even funny.
 
hey, I've done movement of 3D objects
 
I still need to get some input working.
 
not much, but some
 
11:26 PM
> I'm pretty sure it can just paste a symbol in middle of another symbol if its instructed to
I don't even.
Lol, MSDN example on Raw Input. //excludes answering machines
 
RI was fun to work with
 
I'm tempted to implement support for using answering machine as a controller.
 
the examples give you random magic numbers to use which aren't explained at all
 
However would that work.
 
and the documentation doesn't list them at all
 
11:30 PM
They were explained somewhere, they're HID identifiers or something.
Also, Google got new feature lately. If I go back from a result to the search page, it offers "block all results from X" link.
 
Google "Google", click the first link and then go back!
 
> - Block all www.google.com results
This kills the Internet, I presume.
 
the Internets can never die
 
> Zack, "because functions defined inside the class definition are not mandatory inline" - i guess it depends on the compiler, since I know at least one compiler where what I said is true. – suddnely_me 12 mins ago
Anyone knows what compiler this is?
 
@Nassosdim @asteris @wendyg sadly, we have confirmed that John McCarthy passed away Oct. 23.
 
11:37 PM
uh, functions defined in the class are mandatory inline
that's defined by the Standard
 
@CatPlusPlus Another one?
 
Apparently.
 
what is this, the Month of Death?
 
Black October.
 
@DeadMG Oh, missing context. "inline" there means "put the generated code inlined", not "fuck ODR".
 
11:39 PM
oh
then of course, there are no rules whatsoever as to what the compiler can and cannot inline
 
He claims there's a compiler that guarantees it.
I wonder which crappy compiler is that.
 
Could be MSVC.
 
even given a specific compiler, like Visual Studio, that has a __forceinline keyword, will still refuse to inline the assembler for some functions marked __forceinline
 
I think it's the only one that pays any attention to inline hints now.
 
nope
 
11:41 PM
You need __reallyreallyreallyforcethefuckinginliningofthisshitmotherfucker keyword.
 
Could be remembering wrong, though.
 
VS's MSDN page says that even __forceinline doesn't actually force inlining
 
I'm pretty sure GCC just points and laughs at you for using inline.
 
ICC he says.
I always thought ICC was decent.
 
I doubt it
 
11:43 PM
What lousy commercial compiler trusts the programmer's optimization hints?
 
I'd expect ICC to have the best inlining heuristics
 
now I can check overlap, but what the heck do I do when it occurs, I have to translate the moving square to just next to the other, right?
 
Check for overlap before moving.
If it occurs, don't move.
 
what you do when it's detected is your problem
 
(I.e. check for overlap as if you'd already moved)
 
11:45 PM
flash up a message box, move less, don't move, whatever
 
Throw nasal demons.
if(overlapping) { int x[1]; x[1] = 1; }
(I guess this would generate warnings on a nice compiler.)
 
What's a nice compiler?
 
One that generates warnings for that code.
 
har har
my theoretical implementation throws an error!
 
That's fine too.
I compile with -Werror, so the distinction is a bit lost on me.
 
11:48 PM
lol
 
My theoretical implementation is getting better each day.
I'm collecting silly assumptions by developers that are not guaranteed by the standard and twisting them around.
std::less for pointers is implemented with p > q. std::greater just delegates to std::less.
 
not sure that's legal, even in the Compiler from Hell
 
It provides a total order.
That's what's required.
 
if operator< is defined for two pointers, for example for two objects in an array, then I'm pretty sure that std::less must provide equal results
 
11:54 PM
I can't find that requirement.
 
it worked!
 
I've been considering inlining everything that is not marked inline (or in the class defintion), and not inlining the rest.
 
interesting
 
That would be cruel.
OMG
This is one database query.
 
Generated.
Also, TRWTF is printing it.
 
02:00 - 18:0018:00 - 00:00

« first day (373 days earlier)      last day (4558 days later) »