« first day (2055 days earlier)      last day (2895 days later) » 

user1804599
2:05 PM
blue eyes are ugly
 
I was thinking ... maybe the magic mirror possessed by Snow White's evil stepmother, is actually future version of siri on iPad when the front cam is on?
 
nwp
/me set the temperature of the oven without turning it on like a pr0
 
user1804599
I used to think ovens had no temperature limit so they would keep getting hotter and hotter until you turned them off
 
"Siri? Who is the fairest of all" "you, my queen is the fairest" (search result returned by google.) This begs the question: so maybe the evil queen was actually a time traveller who had an ipad powered time space distorting wormhole technology?
 
@Telkitty comparisons are cheap. I always knew Brexit were predicted by Nostradamus
 
2:10 PM
that also explain why she's the fairest of them all, thanks to modern plastic surgery ...
 
The bird has died
 
:'(
 
RIP
Hopefully it didn't suffer too much
 
nwp
@Telkitty ah, and the poisoned apple is actually a metaphor for ... an update?
 
user1804599
@sehe woot so brexit is gonna happen? :D
 
2:13 PM
Nostradamus famously predicted:
> A talking lobster /
> Risen from flat lands /
> Will not hit /
> On that singular spot so small /
> A whoosh is all is left
 
@nwp doesn't explain why it killed snow white though ...
but ... not many witness after snow white went into the forest, maybe the queen sold snow white into prostitution? I mean ... a hot young woman sleeping in the same house as 7 men sounds dodgy at best ...
 
nwp
maybe snow white asked for directions to find the dwarfs little people and the "apple" sent her to a forest where she got lost and starved and was later found by the hunter
 
@nwp good point, apple map/location service does suck ...
 
With an hour left to vote, it'll take a miracle for spaces to pull this out.
Come on lounge. You know what to do
 
Ven
not give a fuck?
 
user1804599
2:21 PM
> Practical Developer
> Wastes time on a debate on tabs vs spaces
 
user1804599
very practical
 
@Ven exactly
@rightfold You don't seem to know much about the guy/account
 
TabX
2
 
@rightfold you're just mad cause spaces is better
 
@sehe Already voted iirc
 
2:43 PM
Wait
Calculating the prime factors of a number is NP because you have an infinite domain?
Or is there something that I'm missing?
If I have a limited set of integers of arity N and I want to calculate the prime factors of that it's going to be some very high complexity value, but it would still be polynomial no?
Oh maybe not
Because the prime factors are not necessarily 2
 
user1804599
@Shoe no
 
user1804599
getting the first element of a linked list is P and the domain is infinite too
 
user1804599
there are also algorithms with infinite domains that are outside NP
 
user1804599
I want to go to IKEA.
 
user1804599
2:49 PM
I want to work for IKEA.
 
q_q Disco Cords is blocked by my school.
 
user1804599
They're looking for interior designers. I want to be an interior designer.
 
Hi everyone. I'm trying to write a simple split functon, something like

```
vector<string> split(string str, string sep)
```

But I've no idea what the idiomatic way to manage the memory here is... Should I return a unique_ptr? What about the individual strings? Should they also be wrapped in unique_ptrs?
 
nwp
@RomanCheplyaka the idiomatic way is to not do anything and let string and vector handle it
you may also want to check if you really must split the string or if an iterator is sufficient
 
this last statement ^
 
2:54 PM
So, should I allocate them with new? When will they be destroyed?
Good point re iterators, I'll need to read up on how to use them.
 
Don't use new
 
nwp
@RomanCheplyaka no, never use new. let vector and string handle it and don't worry about it
 
If you don't use an iterator or some proxy thingy, you'll have to copy the strings. You might as well copy them into an std::string and that automatically manages the memory for you
 
user1804599
@bolov No, it is not undefined behavior. There is a special rule that allows this. stackoverflow.com/a/14505930/1804599rightfold 1 min ago
 
user1804599
rightfold, informing the uninformed since 1994
 
2:56 PM
What do you mean don't use new? If I just say vector<string> myvec, then it'll be allocated on the stack and I won't be able to return it, right?
 
user1804599
Never use new.
 
nwp
@RomanCheplyaka you just return it
 
or will it get copied or something?
 
user1804599
std::vector will use new for you.
 
@RomanCheplyaka just return it
 
user1804599
2:57 PM
If you return a vector, it will be moved.
 
Ell
@RomanCheplyaka there is nought wrong with that
 
it will probably not be moved
 
user1804599
Forget everything about new until you've programmed in C++ for at least three years.
 
okay, but what about strings inside that vector? Those will be on the heap, right?
 
Ell
NRVO will move it right
 
2:58 PM
If they are results of substr()
 
@RomanCheplyaka doesn't matter, use std::string
 
I do use std::string
 
user1804599
> When in doubt, verb the noun.
 
user1804599
I like this.
 
nwp
@Ell NRVO makes it not need to be moved
 
2:58 PM
use std::string's constructor which takes two iterators and copies the string
 
Your original interface is fine.
 
Ell
@nwp sorry that's it
I'm still bad at c++
RVO and moving are unrelated
 
user1804599
everyone is bad at C++
 
user1804599
Anything you return except references will get moved.
 
Ell
But I'm esp bad
 
3:00 PM
@rightfold source?
 
nwp
meh, stay away from pointers and inheritance and C++ is a fine language
 
user1804599
@Shoe C++ standard
 
lol
 
user1804599
also common knowledge
 
what section?
 
user1804599
3:00 PM
do I know? use grep
 
Do you know what RVO is?
 
user1804599
Yes, I do.
 
Ell
@nwp pointers & inheritance are the easy bits
 
user1804599
Use Rust.
 
nwp
@rightfold pretty sure they now require (N)RVO, so no moving
@Ell ok now I'm curious, what is the hard bit?
 
3:01 PM
@nwp yes
 
Ell
@nwp idk, name resolution
 
at the very least it depends on what version of the C++ standard you are reading
in C++03 things were either copies or RVOed
 
nwp
@Ell if all your overloads do conceptually the same thing you don't need to worry about which one is called
 
Ell
Writing code that isn't accidentally UB is the hard bit
 
3:03 PM
I'm p sure in C++11 things were either copied or RVOed or moved there too
 
Ell
@nwp its not just about overloads
Overloading, hiding, templates, ADL
There's lots of stuff going on
 
restrict problems
Properly handling and documenting exception safety
lock-free programming
 
Why are people so mad about pi?
 
Ell
Yup exception safety is a massive hard bit IMHO
 
@fredoverflow Because it lacks an « e » to be truly worth it.
 
nwp
3:05 PM
@Ell The way I see it is they make complicated rules to make C++ behave the way one would expect. Of course they don't succeed 100%, but you usually don't actually need to know these things.
 
@Morwenn lol
 
Ell
@nwp well somebody does
Maybe not the average c++ programmes
 
@nwp Well, until you actually need to know them that is.
 
Ell
And average = bad as far as I've been told
 
3:07 PM
average = C + Java
 
nwp
Good = making useful stuff, and you don't need to know any of the super special cases and standard wordings to do that
using sanitizers that tell you when you do something that is UB is much more important than reading the standard and know all the ~138 places it says that something is UB
 
Are there really just 138 places?
 
nwp
I saw that in a talk, didn't count it myself
 
at 0:40 the oboe does a really cool lick to transition
and for some reason I can't figure out the notes for the life of me
 
There's 67 cases of the behavior is undefined in n4567.
 
3:14 PM
@Morwenn I guess you as well :P
 
undefined behavior is there 60 times.
 
so 127? nice
 
Not exactly - some of the undefined behavior ones are... the definition of undefined behavior.
 
Maybe they wanted to fit the number of undefined behaviors into a signed char to prevent undefined behavior from overflow?
 
;_;
 
Ell
3:16 PM
@nwp disagree
Well, maybe you don't need to know the wording
But you need to know what is UB
Obviously not be right 100% of the time
 
nwp
I don't know, it would be pretty difficult to find UB that does not get caught by clang or ubsan, which makes UB about as dangerous as forgetting a ; or dereferencing a nullptr. You just get told you did it wrong and fix it.
 
err, dereferencing a null pointer is UB
Also it's not that hard, just run comprehensive tests. vOv
 
Even if you don't use the lvalue?
 
I mean, sanitizers are great and shit, but man, don't over-estimate their usefulness.
@fredoverflow I'm pretty sure it's UB everywhere if evaluated.
 
int * p = nullptr;
*p;   // UB?
 
3:26 PM
yes
 
user1804599
yes
 
nwp
sure it's UB, but you get told when it happens, so it is not necessary to be able to recognize it
 
user1804599
Dereferencing a null pointer is always UB
 
to recognize what; it's UB, the compiler can order you a pizza
 
&*p;   // UB?
 
3:27 PM
in C, no; in C++, yes
 
user1804599
@nwp you aren't. This statement will get optimized out and the compiler will further assume that p is not null
 
&* in C is noop
&* in C++ is not
so UB in C++ for sure, not UB in C for sure
(unless I am wrong)
 
> in particular, a null reference cannot exist in a well-defined program, because the only way to create such a reference would be to bind it to the “object” obtained by indirection through a null pointer, which causes undefined behavior
 
nwp
@rightfold if you use vim and gcc without flags sure, if you use appropriate tools you get told, even when *p is not evaluated
 
user1804599
*p; if (p == nullptr) std::cout << "optimized away";
 
3:29 PM
@Borgleader Title of the day:
-19
Q: java tells me: Hello there. Are you ok?

Hunarthis question can't be duplicate I don't know if you believe me or not but here is the story i study physics at university and we also learn java and my friends are not familiar with it and they make really horrible mistakes in syntax .. that day my friend asked me to correct the compiler errors ...

 
I think (from what I remember from discussions with LRiO) this is the only part of the standard (or at least it used to be the only part of the standard) that literally says that indirection through a null pointer is undefined behavior.
...although the bad part here is that it's a note.
 
nwp
@rightfold does not compile. error: expression result unused [-Werror,-Wunused-value]
 
@Mysticial lol
 
It's a note in [dcl.ref].5.
> There shall be no references to references, no arrays of references, and no pointers to references.
ah the beauty of standardese
 
@Griwes Oh yeah, no references to references? So what about int && rr = 42;? ;)
 
3:35 PM
@fredoverflow What about it?
This is obviously a logical AND of int and rr, and asserting that the result should be 42. Clearly that's wrong since the result of a logical and is either true or false.
 
Ah, and int ** p is the exponentiation of int to the power of p?
 
@fredoverflow Of course not. Everybody knows that (in SNOBOL) * marks the beginning of a comment, so you'd have to look at the next line to see what really goes with that int.
 
Ven
@fredoverflow yes
 
user1804599
@nwp don't use Werror then
 
user1804599
It's a well-formed pair of statements
 
nwp
3:45 PM
why would I disable the compiler rejecting shit code?
 
user1804599
For the same reason you perform some chemical experiments with pure H2O: because you're interested in a certain property, not in others.
 
user1804599
This is an experiment that probes the optimizer. It demonstrates how the optimizer acts on buggy code. Rejecting the buggy code renders the experiment unexecutable
 
nwp
I was talking about how you don't need to know about these things since you have tools that just tell you. I don't know how you got to experimenting and probing.
 
user1804599
If you want to find out what the optimizer does, you have to run the fucking optimizer
 
Well, you still need to know these things even if you have tools to detect them.
 
3:59 PM
@Mysticial lollllll whatafail
 
4:10 PM
@fredoverflow Interesting talk
 
user1804599
Ik wil een gleufdier zijn
 
nwp
@rightfold a slot animal?
 
Neo
Hello all
I would like to know what it means for a pointer to be invalidated?
 
@Neo I think you mean iterator
 
Neo
Yes iterator ^^'
 
4:25 PM
18
Q: What is iterator invalidation?

Mark CanlasI see it referenced a lot but no clear answer of what exactly it is. My experience is with higher level languages, so I'm unfamiliar about the presence of invalidity in a collections framework. What is iterator invalidation? Why does it come up? Why is it difficult to deal with?

have fun reading
 
Neo
Ok, thx
 
@Borgleader I don't use Scala that much anymore, but I still love watching Martin's talks :)
 
user1804599
Fred you should try Rust
 
user1804599
Try Rust anyway
 
user1804599
4:31 PM
You'll never want to teach C again
 
Hi longeurs.
 
Who wants Rust teachers?
 
/me raises hand
 
/me raises funds to stop the bourgeoisie
 
@ellisbben So how much do you pay?
 
4:39 PM
@fredoverflow not enough to make up for however much you make presumably teaching C++?
 
I haven't been teaching C++ in quite a while, but I still teach C.
Apparently, there is a demand for C teachers.
I don't see this demand for Rust.
 
nwp
@fredoverflow in 50 years when Rust is outdated the demand for teaching it will arrive
 
@fredoverflow There's a demand for C89-with-POSIX-but-not-C99-because-not-all-compilers-support-it teachers.
 
Right, I teach C89.
 
Well, you C?
 
4:51 PM
@fredoverflow 17 years later still? Wow.
What compilers do not support C99?
 
nwp
@wilx VS
 
@wilx That one compiler that runs on Windows and doesn't support POSIX either anyway.
And these days it supports a bigger subset of C99 than it used to.
 
@nwp Isn't VS 2015 almost compliant?
 
nwp
@wilx almost compliant with C++11, but not C99
they said somewhere they do not intend to ever go past C89
 
@nwp Plot twist! What about Visual Studio 2015 with Clang for C99? :)
 
4:56 PM
@wilx There is nothing exciting or groundbreaking in C99 really, is there?
 
@fredoverflow Mixing declarations and code is pretty ground breaking. Single line comments, too.
Variadic function-like macros.
stdint.h is pretty useful, too.
 
@wilx Oh yeah, I support both in skorbut :D
 
@fredoverflow But then you are not teaching C89/C90.
 
user1804599
@fredoverflow Nobody; Rust teaches itself
 
user1804599
Mutable global variables are the hardest thing in programming, and Rust prohibits them.
 
user1804599
5:06 PM
Globals in Rust are not allowed to have dtors, cool
 
user1804599
TIL
 
@wilx Should I give the money back?
 
@fredoverflow Only if you are ashamed!
 
Actually, my students use Visual Studio and have to declare first and use /**/ comments. I just use skorbut for demonstration purposes.
 
user1804599
How do you do 16-bit arithmetic in a system that only has 32-bit integers?
 
5:13 PM
& 0xffff everywhere?
 
user1804599
Do you put % 0xffff after each operation?
 
& not %
 
user1804599
@fredoverflow I want overflow
 
user1804599
Wrap on overflow
 
user1804599
Signed
 
5:14 PM
I think they have the same implications in this case
 
then << 16 >> 16 after each operation
 
user1804599
Coool
 
user1804599
So a + b would become (a + b) >> 16
 
No, (a + b) << 16 >> 16
 
user1804599
Oh I see
 
5:17 PM
isn't that just & 0xffff?
 
No, you want to copy bit 16 to all bits above.
& 0xffff will set them to 0.
 
user1804599
How is that different from & 0xffff?
 
user1804599
Oh right
 
well
he didn't specify if he wanted signed or unsigned.
I guess I was assuming unsigned.
 
3 mins ago, by rightfold
Signed
 
5:18 PM
oh ok
 
By the way, x86 has an instruction to copy bit 15 (not 16, silly me) to all bits above:
cwd
 
user1804599
Thanks
 
user1804599
I need this for my code generator when generating JS code
 
Okay JS probably doesn't have the x86 cwd instruction ;)
 
user1804599
PHP is more challenging as the size of an int is implementation defined in PHP. So I cannot just shift by 32 - n
 
user1804599
5:20 PM
It might have to be 64 - n
 
user1804599
I guess I'll just assume 64. Nobody uses 32-bit PHP. Or make it configurable
 
0xffff is not USHRT_MAX ?
 
Apparently, x64 has an equivalent movswl instruction.
I guess swl stands for "signed word -> long" or something.
@rightfold Is there no way to query if it's 32 or 64 bits?
Oh way, you don't know at compile-time?
Hm, maybe bake some "reflection" into the generated code? :)
@Ramy It probably is in most C implementations.
 
user1804599
@fredoverflow there is but that's at runtime lol
 
what i trying to say if why to use 0xffff and not directly USHRT_MAX. I saw in many sources this
 
5:28 PM
@orlp I just created a "new" O(n log n) sorting algorithm that always seems faster than heapsort :D
 
user1804599
> Prior to PHP 7, if an invalid digit was given in an octal integer (i.e. 8 or 9), the rest of the number was ignored. Since PHP 7, a parse error is emitted.
 
user1804599
lol
 
@Ramy Because 0xffff is for kewl 1337 hackers, whereas USHRT_MAX is for software engineering pussies.
 
user1804599
lol casting anything other than a Boolean, float or string to an integer in PHP is UB
 
Why? Is PHP having an UB contest with C++ or something?
 
user1804599
5:35 PM
No idea why, but the manual says so.
 
user1804599
If you cast an array to an integer you seem to get 1 if the array is non-empty and 0 if it's empty lol
 
user1804599
That's kind of useful
 
user1804599
but meh UB
 
@fredoverflow LLVM can sext
 
@fredoverflow Sort of, but not exactly. cwd copies the sign bit from AX into all the bits of DX. There's also movsx, which takes (for example) a 16-bit input and copies it to a 32-bit register, with the sign bit extended into the upper bits of that register. If memory serves, you can do an in-place extension, such as movsx ah, eax
 
5:41 PM
@Puppy Don't name your variable ape then ;)
@JerryCoffin right
 
I immediately thought you meant like i32 ape = sext i32 existingVar; and I'm like "What's wrong with that?"
 
@orlp Eb D B Bb Eb D B Bb I'd say if we're talking about the same melody.
 
cwd
xor ax, dx
sub ax, dx
^ compute absolute value without branching ;)
 
user1804599
@fredoverflow clang generates this:
 
user1804599
sarl    $31, %edx
xorl    %edx, %eax
subl    %edx, %eax
 
5:47 PM
After a multiply or something? How else does edx have the sign bit of eax?
No wait, edx seems to be a copy of eax... how?
 
user1804599
This is AT&T syntax; the output operand is right.
 
What's the instruction immediate above the sarl?
 
user1804599
Here is the Intel syntax:
 
user1804599
f(int):
        mov     edx, edi
        mov     eax, edi
        sar     edx, 31
        xor     eax, edx
        sub     eax, edx
        ret
 
Where does edx get its initial value?
 
user1804599
5:48 PM
edx = eax at the start.
 
Okay that makes sense.
What calling convention uses edi for first parameter?
 
user1804599
The sign function is particularly interesting:
 
user1804599
    test    edi, edi
    js      .L3
    setne   al
    movzx   eax, al
    ret
.L3:
    mov     eax, -1
    ret
 
user1804599
@fredoverflow System V AMD64 ABI, i.e. Linux/OS X x86-64 cdecl
 
user1804599
This table is handy dandy: en.wikipedia.org/wiki/…
 
nwp
5:53 PM
I saw people using void foo(auto x) instead of template <class X> void foo(X x) and like it and wanted to apply it to my code, but it turns out that is just a gcc extension and clang doesn't allow it :(
one day C++ will have sane syntax, I believe!
 
You'll be dead before that.
 
nwp
:(
 
user1804599
@fredoverflow clang emits different code:
 
@Morwenn hit me
 
user1804599
test    edi, edi
setne   al
movzx   ecx, al
mov     eax, -1
cmovns  eax, ecx
ret
 
5:58 PM
@orlp What?
 
@Morwenn with your sorting algo
 
@orlp Why would want to me to hit you? :(
 
@Morwenn hey we all want some kinky stuff from time to time
 
:D
 
@nwp You can't have sane syntax and be compatible with C.
 
5:59 PM
Basically I use std::nth_element to split the collection in 3, then I sort two thirds with blind mergesort. Then I "recurse" in the last third.
 

« first day (2055 days earlier)      last day (2895 days later) »