Conversation started Sep 7, 2012 at 23:42.
Sep 7, 2012 23:42
@MohamedAhmedNabil hey
u8 isn't compiling
In any case, 65 - 90 is the ASCII range if I got that right.
:Should we feel sorry for the windows dudes or just hope for their demise?
@LucDanton looks wrong to me
@MooingDuck Reading tabulated data easily confuses me.
Sep 7, 2012 23:46
@LucDanton oh, depends on how you define it too.
@MooingDuck yesterday you gave me this ideone.com/1YgSd . While i was checking it, It always worked, except when the user enter " 4" or " 4" it accepts it
@LucDanton ASCII is officially 0x00-0x7F
I'm just going to do 'A' to 'Z'
@MohamedAhmedNabil yeah, it ignores leading spaces
@StackedCrooked [sorry, had to deal with fussing baby for a while] Hmm...now that I think about it, I don't remember ever failing a test. I must be getting old and losing my memory.
Sep 7, 2012 23:47
because that seems like a small thing for me to care about
@MooingDuck How can i stop that?
@MohamedAhmedNabil it's harder
@MooingDuck Let me ask another question, why does it skip leading spaces
@MohamedAhmedNabil all formatted reads >> ignore leading spaces.
Sep 7, 2012 23:48
.
@MohamedAhmedNabil I thought of an easy way
@MooingDuck mee too
@LucDanton Thanks
@MooingDuck that seemed to work, what was your way
user406009
cppreference.com >> cplusplus.com
Sep 7, 2012 23:50
Still using cplusplus.com?
@MohamedAhmedNabil does it? alright
I'm sort of annoyed that I recently installed Boost 1.50 on my machine and they released 1.51 right after that. Too lazy to bother doing that again. Hopefully I'm not missing on anything (can't say I'm enthused about Boost.Context).
@Rapptz sigh
@LucDanton That happened to me too. I installed 1.50 2 days before 1.51 came out
@MooingDuck What was your way?
Sep 7, 2012 23:51
@LucDanton On my machine, installing boost is the download + 10 minutes compilation. That isn't too much effort
user406009
Does Boost.Context finally allow multithreaded c++ coroutines?
@EthanSteinberg ? multithreaded coroutines?
user406009
Coroutines that can be passed between threads. The other solutions fail once you call on a thread that was not the original.
@EthanSteinberg You mean, stackful coroutines?
@sehe I do remember the b2 invocations this time, true. But I could be coding instead! Which I am!
Sep 7, 2012 23:53
Well they need to be stackful for that, but the point isn't as much that can be passed to another thread, although they probably can
OMG ideone is slow right now :(
Double free while (auto-)destroying am empty unordered_set of pointers. What the hell?
@bitmask UB. Memory corruption
@bitmask heap corruption/stack corruption, or it previously had data that you double deleted.
@MohamedAhmedNabil ideone.com/7wJ5G
@MooingDuck No, it's a local variable, and the loop that populates it does zero iterations. There was never data in it, but I can see two calls to the dtor.
Sep 7, 2012 23:56
@bitmask stack corruption then
@sehe Reproducibly?
@StackedCrooked No.
the stack is pretty full from a recursion ...
@bitmask Yeah. It's your program. You programmed it :) That's not an accident
Sep 7, 2012 23:57
@bitmask sometimes
@LucDanton That's good news :)
You don't say.
@bitmask ? what. You delete it at the bottom of a deeply nested recursive call?
@MooingDuck Why did noskipws work?
@sehe no, the stack looks like: fun1 -> fun1 -> fun1 -> ... -> fun1 -> fun2
Sep 7, 2012 23:58
@MohamedAhmedNabil Because the words say "No - Skip - Whitespace"
fun2 has a local variable, which is an unordered_set
@bitmask Nah, variadics are funtastic!
@MohamedAhmedNabil because noskipws makes it not skip whitespace when reading in stuff.
@bitmask Ok, so you're perhaps just bottoming out of stack space. Run it under valgrind?
@bitmask if you write past the end of array, anything can happen, including causing double deletes.
Sep 7, 2012 23:59
@MohamedAhmedNabil IOW: read the documentation. It's the only thing that'll work
@sehe Yes, it tells me that a lot of conditional jumps depend on uninitialised values. I thought it could be a symptom of the problem, as well.
@StackedCrooked I don't think you can have any issue with static_cast unless it involves void*. But I may be lacking imagination.
I had one where I wrote past the end of the array and caused each of my functions to grab an extra 33k of stack space.
@MooingDuck Which is better: Yours: ideone.com/7wJ5G or noskipws: ideone.com/WeH90
@MohamedAhmedNabil probably noskipws
Sep 8, 2012 00:00
@bitmask LOL. You think?
@MooingDuck does yours add any extra feature or is it the same?
@sehe Well, I'm not entirely sure, because it happens during the recursive descend.
@MohamedAhmedNabil you're displaying "The value stored in string str was" even if it reaches the end of the user's input.
@MohamedAhmedNabil other than that they're the same I think
@bitmask Where's your program?
There are about 17 recursive steps. That shouldn't manage to overflow the stack
@sehe What do you mean?
Sep 8, 2012 00:02
@bitmask Depends on what else you do on the stack
@bitmask Can I see it?
gdb tells me there are 43 calls on the stack, in total.
@MooingDuck huh?
@MohamedAhmedNabil the while(getline( causes it to keep going until you break or until it reaches the end of the input
@sehe In theory, yes, but I don't even know how to begin extracting the relevant parts. It's not exactly small.
look at the bottom of ideone:
input: no
output:
Enter a number:
The value stored in string str was: 0
Sep 8, 2012 00:04
@bitmask The size of the stack frames matters, as well as total stack size. Anyways, it's probably not a stack overflow then. I'd just start with the first reported unitialized value reported by valgrind and fix all the related code :)
I've been using some C++11 features I'm not yet 100% familiar with, maybe I messed something up, with that.
Is it just me, does chat seem to be running very slowly?
What part is slow?
@MooingDuck both programs use while(getline
Scrolling... probably my computer.... hard drive light is going crazy...
Sep 8, 2012 00:05
@sehe I obviously tried that, but I cannot see any problem there, everything looks perfectly initialised. Maybe I have to do some more investigating ...
@Chimera Soooo your browser's scrolling is diskbound? Swap thrashing?
@MohamedAhmedNabil yes, but look at the end of mine, after the loop. if(cin)
@bitmask How can it "look" initialized when it is reported to be unitialized?
@bitmask initialize yer variables
@sehe Don't know... I'm running inside a virtual machine... could be some crazy stuff going on.
Sep 8, 2012 00:07
@bitmask You can just trace the path to the point where it fails. You know valgrind --db-attach=yes, right?
@sehe All variables are properly constructed?
sudo -E valgrind --db-attach=yes ./test # get around permission issues the easy way
@bitmask Obviously not. Duh. Rule #1: To fix a problem you must acknowledge you have one.
@MooingDuck I was meaning to ask you about that. So its really if(cin) that is causing the change?
@MohamedAhmedNabil yeah, it checks to see if all reads from cin succeeded. If they did, we know there is a number. Otherwise, it failed
@MooingDuck So basically if one cin>> fails . cin will always return false?
Sep 8, 2012 00:10
@sehe Well the jump happens in ceilf (s_ceilf.c) which is called by hashtable_policy.c, so deep inside library code. The first outer function looks fine.
@MohamedAhmedNabil until you call cin.clear() yes
@MooingDuck Nice! Did you come up with that on the fly?
@bitmask irrelevant. Without full code, there's not much I can say about that. Other than that 'deep inside library code' doesn't mean it isn't your error. The problem may manifest it in library code, though you cause it
@MooingDuck aww...
Sep 8, 2012 00:12
that's the first point where valgrind starts complaining. in line 47, that is
@Mysticial that was a great comment
@MohamedAhmedNabil also good to know: it will ignore all >> after the first fails until you .clear() it
@bitmask check the validity of iterator parameter it, and whether unfold leaves the tree immutable. Iterators will be invalidated if the underlying collection changes. See the docs for precise specification when this may occur
I think I can see that func must be declared to take the content as const&, so that looks relatively safe
@MooingDuck so its a good habit to always clear()
@MohamedAhmedNabil after a failure. The important habit is to check for failures.
Sep 8, 2012 00:19
@bitmask good luck with the debugging. Pro tip: when valgrind says a value is uninitialized, listen to it!
I'm off to bed, cheers
night
@sehe thanks so far!
Sep 8, 2012 00:38
here

int i;
cin>>i;

if the user enters a letter, why does i=0?
@MooingDuck ?
The numeric value to be stored can be one of:
— zero, if the conversion function fails to convert the entire field. ios_base::failbit is assigned to err.
— the most positive representable value, if the field represents a value too large positive to be represented in val. ios_base::failbit is assigned to err.
— the most negative representable value or zero for an unsigned integer type, if the field represents a value too large negative to be represented in val. ios_base::failbit is assigned to err.
First case.
@LucDanton Any other cases?
I'm not super familiar with this part of the Standard Library, but I believe that's it.
@MohamedAhmedNabil because i just coincidentally happened to have the value 0 before the >>.
@LucDanton oh really? I thought it left the variable alone
@MooingDuck yea
Sep 8, 2012 00:48
@MohamedAhmedNabil Luc says I'm wrong, and he has a source to back him up
@MooingDuck i was actually 0, when i changed the value of i to 6, it changed to 6
@MooingDuck Had no idea myself. I wonder if you can imbue a stream with a numeric locale that doesn't do that and pass that stream to code that does expect formatted extraction to fill with 0 in case of failure, just to see something crash and burn.
int i=6;

cout << "Enter a number: ";
cin>>i;
cout<<i;
This outputs 6
Sep 8, 2012 00:51
I get 0 if input is ill-formed.
@LucDanton meaning of ill-formed?
@LucDanton too advanced man
@MooingDuck got something too add?
Sep 8, 2012 00:54
Avoiding std::cin makes it explicit what we're trying to extract from.
@LucDanton let me check wat <cassert> does
it's.. in the word
o.o
Could use static_assert too
@MohamedAhmedNabil it should be zero, if it's not zero, it's a bug in that cin object.
@Rapptz he doesn't know what assert is
@MooingDuck wait a sec
@MooingDuck It's an english word.
Sep 8, 2012 01:00
int i=6;
cin>>i;
cout<<i;
@MooingDuck shouldnt this output 6?
not unless cin is in error state, or the user types 6
why did you think it should output 6?
Youtube got a new look.
@MohamedAhmedNabil no, should be zero
@Rapptz not everyone knows all English words.
@Cheersandhth.-Alf im assuming the user entered a letter
@MooingDuck test it
@Cheersandhth.-Alf I accidentally told him it did a few minutes ago, then Luc corrected me
Sep 8, 2012 01:04
@MohamedAhmedNabil I've already provided you with a demo.
@LucDanton prints six on ideone: ideone.com/ZlNO4
@MooingDuck Actually, most likely nobody (or very few people) know all English words.
Uhm ... do I have to std::move an rvalue reference that comes out of a function call (as return value)?
Sep 8, 2012 01:06
@LucDanton I believe LWS does it right. But that doesn't change the fact ideone (and probably whatever Mohamed is using) is wrong.
@bitmask Depends on the return type and what you want to do exactly.
@bitmask no
auto x = foo();
@LucDanton not if it's already an rvalue reference
@MooingDuck You try with a move-only type then.
Sep 8, 2012 01:07
foo returns an rvalue ref and my stack is screwed with that line and is fine without it.
What does the reference refer to?
Local variable in 5, 4, 3...
@LucDanton Very funny :)
what does assert do?
the return statement looks like this
return std::move(local_variable);
@MohamedAhmedNabil crashes the program if the condition is false
Sep 8, 2012 01:09
So you are referring to a local variable then?
@MooingDuck simple enough
@MohamedAhmedNabil It asserts an expression to be true.
@bitmask that's not allowed
@MooingDuck I thought that was the point of returning an rvalue reference.
@MooingDuck It is. But it leads to bad things.
Sep 8, 2012 01:10
I'm extending the lifetime of a local variable
Here, attempting a copy from a stale reference.
@bitmask No such thing.
@bitmask no, that doesn't work
int&& foo() { int i; return std::move(i); } is the exact same kind of evil as int& foo() { int i; return i; }. They really do mirror each other.
@LucDanton Assertion fails at i==0, should that happen?
@LucDanton I see. Then, this was my mistake, I was convinced move would specifically allow me to do this.
Sep 8, 2012 01:12
@MohamedAhmedNabil your standard library is non-conforming (it's breaking the rules)
Can I avoid copy construction by using rvalue references as return type?
@bitmask you cannot extend the lifetime of a local. Period.
@bitmask either copy or use dynamic scope
@MooingDuck how do i fix that
@MohamedAhmedNabil what compiler are you using?
@MooingDuck But I can extend the lifetime of a temporary (aka rvalue).
Sep 8, 2012 01:14
@MooingDuck UB.
@MooingDuck MS VC++ 2010
@LucDanton say what?
@MohamedAhmedNabil The only way to get a compiler that conforms in that way is then to get a new IDE. (I don't recommend that, cin>>i is too unimportant)
@MooingDuck Well, I don't think that was your point. Regardless of that, I don't see how that goes against what I said. I'm really confused as to what you were trying to said back there :(
@MooingDuck I should just ignore that minor detail?
@LucDanton you don't have to move an rvalue from a function into a local variable
@MohamedAhmedNabil yes. It's so minor I've been doing this for 8 years and never knew about it
Sep 8, 2012 01:16
@MooingDuck ... but there's a call to std::move right there.
@LucDanton not from the variable the function is returning. The move is in the function.
And it's unnecessary to boot. WTF.
@LucDanton yes it is, that's aside from the point
11 mins ago, by bitmask
Uhm ... do I have to std::move an rvalue reference that comes out of a function call (as return value)?
And it goes without saying that you don't have to move rvalues. std::move is for lvalues.
@MooingDuck I took that to be about the return statement.
Isn't it?
@LucDanton I took it to be about moving "an rvalue reference that came out of a function call" into a local
user406009
Sep 8, 2012 01:19
What do you guys usually do when you want a unique identifier?
@EthanSteinberg afjklsbfdjklbasf
user406009
I am thinking of incrementing a uint64_t. Will that work?
@EthanSteinberg that too
anyway, time for me to go home. later all
@MooingDuck Given how the rest of the conversion went (esp. the code snippets), I don't think that's the right interpretation.
user406009
Oh well, uint64_t it is. Hopefully nobody ever goes past 2^64 transactions...
Sep 8, 2012 01:24
@EthanSteinberg Yes, it's like ... who will EVER need 2^32 IP addresses. That'd be madness ... wait a second.
2^32 != 2^64
Obviously. But it's the same line of thought.
18 quintillion is quite a bit
@Rapptz So are 4 billion, if you're trying to connect a handful of universities.
0
Q: ifstream best way to read without memory usage

soniccoolI have a textfile that contains authors and the books written by authors. I am assigned to write a program in that the user will provide the name of a author. And the program must print the name of any books written by that author. I understand that i am supposed to use an ifstream to read this ...

 
Conversation ended Sep 8, 2012 at 1:32.