« first day (554 days earlier)      last day (4410 days later) » 

12:00 AM
Wait, what?
 
That doesn't make any sense.
 
I can't do this a="hi";
but I can do this cin>>a; and then type hi at runtime
so why ?
 
No, you should use std::string.
You can't because an array does not have a proper operator= overload.
 
what about cin>>a;
 
But there's an overload for istream's operator>> that takes a char *.
 
12:01 AM
because >> takes stream as an argument and then char *
 
So, you can do cin>>a but not a = ... because they're not the same thing.
 
thanks
 
@CaptainGiraffe That, too, but not in a very clever and advanced way.
@jamesson What's the problem?
@EtiennedeMartel I tank brandy.
Hee hee.
 
@CatPlusPlus Bam.
 
12:05 AM
This is supposed to detect whether a point in 3-space is moving in any of 6 directions (up, down, left right, in out) using vector math (I can post the header and the vector math library it uses if that helps) but I don't know how yet
I need to see if I can figure it out to the point where I can save some time and build it in my own environment rather than c
 
Math is clever.
What's the problem with zee code ,though?
 
Well, you need to know BASIC analytical geometry ...
 
@CatPlusPlus, no problem, I just dont understand it yet
 
You'll be amazed to know I wrote tic-tac-toe in this state.
I'm that good.
 
ScarletAramant, I kinda do, but kinda don't
 
12:08 AM
@CatPlusPlus I wrote a Jimi hendrix tribut while sober!
 
Im doing tic-tac-toe for notches 0x10 16bit thingie :P
 
so, so,ebody? anybody?
 
nope You'll have to dive through this yourself.
 
I could make a CPU, if I wanted to.
 
okie thx
 
12:09 AM
I just don't feel like it.
 
I made the 586 FP glitch, i'm very proud of that
 
I'm very proud of being able to type.
 
cgflBLAGRLLLL ?
 
We have to kick amusement up a notch.
 
@jamesson I suggest you simply review the basic concepts of analytical geometry and you're perfectly good to go. There's nothing fundamental there about c++ really, it's just a few vector operations.
I'm off to sleep kids, I'll see you latarr'.
 
12:15 AM
@ScarletAmarant: understood, will do
 
Mmh, answering questions might not be the best idea.
 
12:47 AM
Alright, time to buy that indie bundle.
 
12:59 AM
what does this mean?JointHitDetector::JointHitDetector(joint, refJoint, string name, float requiredLength)
in particular the double colon
I'm assuming in the parentheses are attributes of the class
n/m found it
 
posted on April 22, 2012 by Herb Sutter

The solution to GotW #103 is now live. Filed under: C++, GotW

 
1:20 AM
@jamesson It's a constructor.
 
posted on April 22, 2012 by Herb Sutter

While spelunking through the code of a new project you recently joined, you find the following factory function declaration:   JG Question 1. What’s wrong with this return type?   Guru Questions 2. What is the recommended return type? Explain your answer, including any tradeoffs. 3. You’d like to actually change the return type to [...]

 
2:20 AM
Cat are you actually here?
or just lurking like a...sleeping cat?
I want to ask you a question
 
Xeo
2:42 AM
Then ping @Cat like this
If he's here, he'll answer
 
2:56 AM
Xeo, I don't know you, but you'll do. Why do people consider pointer decay an evil horrific thing to be avoided like herpes?
sorry
@xeo I meant.
 
Xeo
Because you lose static type information.
And C++ is really all about static type information
"Here, foo, have an array of 5 chars" - "Thanks, bar, but what do you mean, 5? I just see the beginning of a long strip here."
 
@Xeo I came up from C - I'm used to passing length after pointer. Yes, possible source of bug, ugly, but what is less ugly in C++(pre-11) for passing an array, other than a template?
 
Xeo
What's wrong with a template?
 
@Xeo I mean the template method is usually just a wrapper for a call to a generic that...passes the array size. in my experience
 
Xeo
Err, no.
 
3:02 AM
also, the template method doesn't really allow RTTI, like an array you don't know the size of at run-time
 
Xeo
And templates are generic. I don't know how much more generic you can get.
 
what if I wanted to pass dynamically sized arrays? is there a better (standard) method (pre-c++11) that allows RTTI?
 
@Xeo (Concerning the answer you brought up earlier....) Well that was embaressing. :) Fixed it; surprisingly, nobody had provided an actual answer. Better late than never, I suppose.
 
Xeo
@GManNickG I was thinking of actually pointing out intptr_t, but was too lazy in the end.
 
@Xeo I'm really seriously curious about this...is that just a situation where you have to use otherwise-evil pointer decay?
 
Xeo
3:13 AM
@OrgnlDave Huh? std::vector is your friend here, if I got you right. Fuck manually managed dynamically sized arrays.
Or are you talking about variable-length arrays?
Cause those suck aswell for passing around, just use std::vector.
 
@xeo you raise a valid point. I've heard std::vector is guaranteed to be contiguous in memory. does that make it suitable for, say, a pixel buffer?
 
Xeo
Uh, sure?
std::vector is just a normal dynamically sized (and allocated) array in a very convenient package
 
@Xeo are there any other reasons outside the static type info?
 
Xeo
Anyways, since you're coming from C, here's a good advice:
Wipe C off your mind, forget it completely, and learn modern C++ from ground up. You'll be surprised at how little similarity there is, if any. After that, if you need the low-level knowledge, remember it again.
@OrgnlDave You mean for the pointer decay thingy?
 
@Xeo I have learned modern C++ "from the ground up." I should say I came up from C years ago and just wondered what the big deal is - some people are pretty adamant about how evil they are. I'm one of those weird people who have seriously never, ever had a serious problem with pointers, but I also learned to be pedantic with them early on, and avoid being a 3-star and almost always 2-star programmer.
*almost never a 2-star programmer
 
Xeo
3:23 AM
Oh, okay. :)
You can edit your messages by hitting the up arrow
up to 2 minutes after posting them, anyways.
Also, no need to ping for every message, if the user is currently active
We usually check the chat every few minutes
 
so, with all this established - and yes, std::vector should have been fairly obvious to me - other than the potential for shooting oneself in the foot, are you of the mind that a "safer" method is always a better method? What I mean to say is, do you think C++'s ways are always so much better than decent C that we have to abandon them?
For instance, template instantiations that cause errors or bugs can be a pain to debug, sometimes worse than pointer errors, though not always
 
Xeo
Well, the compilers are to blame for that, no? :P
Also, after a few dozen errors, you start to see a pattern for your compiler and I don't really find them all that bad anymore (which doesn't mean they aren't horrific)
If you want a compiler with really awesome error messages, try Clang
It also got the best C++11 support IIRC, and is faster and has less memory footprint than GCC
(And of course, I'm talking about the current revision of the repository, since the latest release is Clang 3.0 and that is ages old in terms of features.)
 
Oh, how are the concurrency features coming along in Clang? the support page seems really out of date; I can't happen to...*gasp*...ditch Boost yet, can I? (to be fair, nothing against Boost, except that the documentation tells you how to go to the moon when you want to take a walk around the block)
 
3:40 AM
Anyone know how to set the value of a static const std::string that is a member of a templated class? I tried

template<T> const std::string className<T>::varName = "test"

but that generates a linker error (that that type of thing (minus the template parts) does work for other classes)
 
Xeo
@OrgnlDave No compiler except Visual C++ is really going strong with concurrency support. :/
@soandos The initializer is fine, where did you put it? It has to be in the header too.
 
@Xeo Which is, of course, quite ironic.
 
@Xeo, never mind, I misread the error message, the error was somewhere else. it all works now
 
@Xeo yes, GCC just pretends everything is single-threaded and std::async promises (futures? late at night) are only evaluated when called, unless you schedule it manually yourself of course
 
Xeo
@GManNickG Yeah, but they got their cool runtime and all that, so it's not that unexpected.
And MS is really all over concurrency
 
3:47 AM
@Xeo Yeah, the PPL library is actually quite useful.
 
I just wish that MS didn't have that delicious, mouth-watering IDE and extremely awesome debugger...sigh...it spoils you. I'm writing some Linux (well, cross-platform but mostly deployed on and meant for Linux) code in MS, when it's way too big to just SSH with vim.
I'm going to have to do some serious std::vector benchmarks, I'm about to enter into the pixel cup thingy and the graphics I'm doing in software are seriously, seriously, seriously intensive; 5% could be a huge problem
if there's one thing I haven't applied modern C++ to before it's bare-bones graphics algorithms
 
@OrgnlDave 5% what?
 
5% overhead
 
Where'd you measure that?
 
I didn't, that's why I said I have to
It's been so long since I've done anything game-y, I'm looking forward to it
 
3:58 AM
Oh, just an arbitrary hypothetical number.
 
yep. arbitrary hypothetical number.
I had a Java guy telling me .h and .cpp division was stupid
he went on to tell me how it was so cool to define an entire class in one file
I just looked at him and said "you can do that in C++ too...just do it."
C++ gets too much hate
 
Well the include system pretty much is atrocious.
 
Nobody's perfect
 
4:30 AM
But we can still criticize them. :P
 
user457812
I saw the word "criticize" and immediately knew I had to jump in.
 
user457812
Even though I've no idea what.
 
Shame it died down, though.
 
user457812
Someone needs to join and say C++ is just C with classes.
 
C++ is C with classes.
 
user457812
4:40 AM
Add the "just" in there.
 
Ah I messed up, my bad.
 
5:08 AM
How can I delete
int*a[3]

?
I have tried
for(int i=0;i<3;i++)
{
delete a[i];
}
delete[] a;
but VS warns me no matter how I use delete and delete[] (and sometimes it crashes)
 
What's your full but minimal code? Also, you should really be using std::vector.
 
@GManNickG, it is not growing ever, and it it just initialized once, so I don't see the need. The array is filled with

int* createInputArray(int size, int seed)
{
srand(seed);
int* inputArray = new int[size];
for(int i = 0; i < size; i++)
inputArray[i] = rand();
return inputArray;
}

once for each index
 
@soandos Because it's better to have safe, working code that automatically deletes and doesn't leak in the face of exceptions. :) you can also use std::unique_ptr<int[]> to have a dynamic array that doesn't resize for minimal overhead while maintaining safety and correctness. If it's not available it's still better to use std::vector.
But anyway, given that, the correct way to delete is just delete [] inputArray.
 
5:27 AM
@GManNickG, that will delete the subarrays also?
 
You know, I think I could do without C++ classes.
C structs are good enough for most things.
 
@Maxpm, scoping is a nightmare, there is no inheritance, no safe anything, no real type system, to name just some of the issues
 
@soandos I don't see any subarrays in your code.
You need to show your full code if I can comment on it.
@Maxpm Not sure if trolling.
 
@soandos That's true.
@GManNickG Not trolling. Though, it is 1:31 AM.
 
int* a[3] is not does not contain subarrays (each filled with the createInputArray, as mentioned above)?
 
5:34 AM
@Maxpm Constructors and destructors are quite useful.
@soandos Then a does not not need to be deleted if it wasn't new'd.
int* a[3]; for (unsigned i = 0; i < 3; ++i) a[i] = new int[10]; /* later */ for (unsigned i = 0; i < 3; ++i) delete [] a[i];
 
Right. Never mind. C++ classes are nice.
 
I though that the following line was syntactic sugar for that:
int* sourceArray[3] = {createInputArray(10, rand()),createInputArray(10000,rand()),createInputArray(100000,rand())};
 
@soandos Yup, but sourceArray is still automatically (stack) allocated, so it goes away on its own. The individually allocated elements need to be deleted though.
All this headache goes away if you use std::vector! (Or RAII in general.)
 
Can you have all that in an initializer list? It's not compile-time.
 
@Maxpm What do you mean?
 
5:39 AM
@Maxpm, yes, it compiles and runs just fine. @GManNickG interesting, even though it is declared as a pointer (or so I thought)
 
Huh.
 
@soandos sourceArray is an array of three pointers to int's. It itself was not dynamically allocated.
 
@GManNickG, ah, got it
@GManNickG, is there a way that a line like
if(left!=nullptr)

can fail?
 
@soandos What do you mean by fail?
 
I get the following exception: First-chance exception at 0x00151824 in prog.exe: 0xC0000005: Access violation reading location 0x5366D35C.
 
5:48 AM
@soandos What is the type of left?
(I'm assuming nullptr is the C++11 keyword.)
 
left is a BinaryTree* (custom version)
 
Then no, that line can't result in undefined behavior.
 
getting an exception there though... Strange. Going to reboot
 
@soandos Are you debugging in Release?
 
6:02 AM
@GManNickG, yes. Wow, just changed that, and the issues went away. Why is that?
Optimizations?
 
@soandos Wait, the bug is gone?
 
Yup. I restarted and switch from release to debug, and the issues were solved
(seems like so far)
 
Xeo
Debug is just filling pointers and memory up with 0s, so it's not fixed. You maybe got a 0 check that gets passed in release
 
@soandos You probably have an uninitialized variable. If you don't initialize left to null, for example, the check will pass, even though its value is garbage.
Debug builds tend to zero everything for you.
 
@GManNickG, I initalized both left and right to nullptr
 
6:06 AM
@soandos Then something else. :)
 
This is very strange
 
Xeo
What abouzt copy, move, anything else?
 
None of those
 
Xeo
Did you follow the rule of three? (didn't read the log)
 
But that check can't fail, by the way. The reason I asked is because in Release optimizations often make it impossible for the debugger to point at the correct and exact location where the error is occurring.
So even though it points at that check, it's probably a little bit before or after that, depending on inlining and whatnot.
 
6:07 AM
I build in debug, get some answers, in release mode I get garbage (@Xeo, don't know what that is)
What could be the issues?
 
Xeo
@soandos Then you've got some reading to do. Especially if you're playing around with raw pointers.
 
@Xeo, any ideas as to what could cause these types of errors?
 
Xeo
As I said, I didn't read the log, just the last three lines before my first answer
 
Well, somewhere, you're writing some very fragile code: code that relies on conditions that the programming language does not guarantee.
Accessing uninitialized memory is the most likely cause.
 
Xeo
@Maxpm He's using pointers!
@soandos Best idea at this point would be to show the code of your class
 
6:12 AM
what is crtmbox.c? maybe the debug version is not going as smoothly as I though (it does not finish, just seems to loop there
 
Try to go through your code and clean it up. Reorganize it to make it cleaner. You'll probably find the bug along the way.
 
Xeo
@soandos crt is normally the C runtime, dunno about the mbox suffix though
 
@Xeo @Maxpm, I did that. Pretty sure its clean (though it is in a bunch of classes)
@Xeo, message box from VS?
OK so good news, it is not crashing. bad news: it never calls the destructor of anything (hence the no errors)
 
Sounds like you're breaking the rule of three.
That's why we use std::vector's. :)
 
@GManNickG what is the rule of three?
 
6:19 AM
Google!
 
Xeo
@GManNickG of what?
 
Not sure that it applies. I never copy the objects, never assign to them (using = anyways) and just destruct the resources they manage
 
Xeo
Are you sure?
Really, just show the code, or this is going nowhere.
 
How can I show it?
(i.e. it is lots of small simple files)
 
6:21 AM
@soandos Rule of Three: If you have one of the following, you probably have the other two : Wife , Empty Bank Account , Anger .
12
 
Xeo
lawl
Say that's the rule of three and you get a star
 
@IntermediateHacker, and everyone else: my code basically creates three of the following (all of different sizes) linked list, array, binary tree, and conpares the timings. Thats it.
@IntermediateHacker, funny though
 
Xeo
That doesn't help. There's about a million ways to do that
 
actually it's a slightly adapted version of what my dad just said an hour ago.
 
Xeo
Just put up the code one Ideone and we'll probably find the error within 5 minutes
 
6:24 AM
when my mom spent Rial 80 on a hair highlighting streak thing from the beauty parlour.
 
@Xeo, How can I do multiple files?
 
Xeo
Paste below each other. But really, I think you can probably reduce the code to fit a single file. sscce.org
 
@Xeo, I have seen that, but that will mess with my templating
 
Xeo
We just need the code, it doesn't need to run or anything
 
is ideone.com down?
 
@Xeo Searching Google.
 
wow. bad timing
 
@soandos Inside every well-written large program is a well-written small program. -- Charles Antony Richard Hoare,
 
Xeo
Meh, then use codepad.org
 
@soandos Do you ever return them from a function or pass them as an argument?
 
6:27 AM
I'm getting a bit philosophical lately.
 
Xeo
@GManNickG Oh, nice
 
probably bec. my exams are a week away
 
You really need to follow the rule of three. You can't just bank on "well I think I never copied any...". If you want, just enforce it at the most basic level: ake the class noncopyable.
Then at least you can be confident in saying no copies are made.
 
Here is the main file: codepad.org/p2EColY6
@GManNickG how can I make it noncopyable?
 
@soandos Are you in C++03 or C++11?
 
6:28 AM
@soandos advice at first glance.. don't use pointers.
 
@GManNickG, c++11, @IntermediateHacker, don't have a choice, my professor does not like smart pointers (except when he asks us to implement them)
 
In C++03, you just declare (never define!) the copy-constructor and assignment-operator in your class in the private section. In C++11 you can write = delete after it.
 
@GManNickG Why not define?
 
codepad.org/5dPWn7Wh is one of the classes that is being used
 
So you can do:

    class noncopyable
    {
    public:
        // stuff

    private:
        noncopyable(const noncopyable&) = delete;
        noncopyable& operator=(const noncopyable&) = delete;
    };
 
6:30 AM
@GManNickG after what?
ah, got it
 
(Sorry, hit enter too soon.)
 
Xeo
Aight
Needs a defaulted move ctor though
or it's nonmoveable aswell
 
Well that was stupid. Once I enable fixed-font/multi-line editing in the chat window, it should disable send-on-enter...
@Xeo We're just trying to make the compiler prove the assertion that "this class is never copied."
 
@GManNickG What's wrong with defining a private copy-constructor with an empty body?
 
Xeo
Move can be just as hazardous
 
6:32 AM
@Maxpm Because then the class can copy itself.
 
Xeo
@Maxpm Or friends
 
Ah.
 
Xeo
Especially default pointer moves are bad
the pointers are just copied
 
@GManNickG, those two lines cause errors for me (VS 2011 beta)
 
Xeo
VS11 has no deleted functions
Don't think of VS11 as C++11 just because of some stuff
2
 
6:34 AM
Wow color me pissed. I'm using Notepad, the simplest possible text editor, hit Ctrl+S to save my progress on some little things I'm writing to myself...and the window literally just vanishes (probably crashed silently). Arg.
 
ouch
@Xeo, got it
 
@soandos Ah, VS has dirt-poor support for C++11. Just take out = delete.
 
Xeo
@GManNickG Maybe hit ctrl-W? that closes tabs/windows
 
got it
 
Xeo
Dangerously close together those two
 
6:35 AM
anyone see any errors with my code?
 
Xeo
No wait, that should bring a prompt if the tab is unsaved
 
@Xeo: Naw definitely hit Ctrl+S. I'm on XP and Notepad actually doesn't even respond to Ctrl+W (just tested), which is a bit weird but okay.
 
@GManNickG, did that, no changes.
 
Xeo
Oh, wait, notepad. I thought of Notepad++...
Really, Notepad?
 
Oh, that reminds me: I need to build Scribes.
And fix my boot sector. >_>
 
6:38 AM
@Xeo Haha, like I said just a single note. My XP machine doesn't have any of the nice things my laptop (development computer) has.
One of which is NotePad++, my favorite notepad editor. :)
@soandos What do you mean?
 
Like anything that I am doing that seems wrong, and/or could cause these errors
Oh sorry, wrong reponse, I mean nothing changed in the output or build warnings after I added those lines.
 
@soandos So still getting errors?
 
Xeo
We need the BinaryTree code still
 
Only in release mode. In debug mode, it just sits around (after printing the values correctly) and does nothing (no calls to any destructor are made)
@Xeo coming right up
Its destructor never gets called
 
Xeo
delete sourceArray[i]; should be delete[] too
Got the error I think
What does the default ctor of BinaryTree look like? It's not in the cpp
 
6:46 AM
fixed that, but that code was never reached (unless all the code above was commented out)
 
Xeo
What did you fix?
 
as far as the code to the default constructor, there is none, and it is no needed, as it is just created, and then insert is called
@Xeo, the missing []
 
Xeo
You sure have a default ctor, because it's being called right here in create: a[i] = new T();
 
Keep in mind that ArrSearch's destructor never gets called
@Xeo, it is the default.
 
Xeo
Or is the int data one the default one with a default value?
 
6:48 AM
data is an int* (array)
 
Xeo
Just show me the BinaryTree header please
 
sorry, was confused, data is an int* for ArrSearch, not BinaryTree
 
Xeo
Oh, I overlooked the default ctor at the bottom of the cpp
Jeez, put your ctors and dtors together in one place! :P
Okay, so which values are spit out? From which test subject? (in debug mode)
 
Sorry about that, not used to having my code read by other people.
 
@soandos It's actually a good experience to go through, so well done. :)
 
Xeo
6:53 AM
Put a breakpoint on each deleter, see which it hits
(if any)
 
@Xeo, did, it hits the first one (in debug mode) and gets to
delete[] toDelete[i];
 
Xeo
Okay, remove that one, continue
Wait, it loops there?
 
Same deal with all of them
 
Xeo
So it hits all of them?
 
yes, but it never moves past the first one
 
Xeo
6:56 AM
Err, that doesn't make sense
If it hits all, it obviously moved past the previous ones
 
@Xeo, I was too slow in responding. It does loop. it does not get past thef ristone
in release mode it DOES get into that first one, an hits ArrSearches destructor
 
Xeo
Ah, all right
 
and there it promptly throws an exception
on:
delete[] data;
Is what it looks like when run in release mode
 
@soandos are you aware that you can just copy the text from a console window?
 

« first day (554 days earlier)      last day (4410 days later) »