« first day (1487 days earlier)      last day (1357 days later) » 

7:52 AM
@nwp Is that different from auto lambda parameters? Or just an alternative syntax?
@user57048 The error is to use scanf which is untyped and an exploit on top of that.
 
 
2 hours later…
nwp
9:36 AM
@iksemyonov In this case it's different. You can't express that with auto because [](auto t1, auto t2){} allows different types for t1 and t2. But if you just use []<typename T>(T t){} then it should be the same thing as [](auto t){}. At least that's how I read it.
You also cannot express variadic templates with the old syntax, so you can express things a bit easier now.
 
@nwp Cool, thanks, I didn't know there was an extensive language reference at cppref as well. Renders some books obsolete, indeed.
@nwp I notice one more difference: the possibility to use concept constraints on the template form. And, do I understand correctly that both the auto and template forms produce a non-template class with a template call operator?
 
nwp
10:04 AM
Sounds right to me. They also said that auto produces a template parameter. I wonder if you can explicitly specify those.
 
 
2 hours later…
12:33 PM
@nwp As in, infer them with decltype? Otherwise I can't imagine how.
 
nwp
I think we are talking about different things.
I meant if you can do [](auto r){}.operator()<int>(42);.
 
@nwp Ahh, gotcha. Can you do that for the `20, explicitly templatized lambdas?
 
nwp
@iksemyonov I don't know what you mean.
 
@nwp I meant to ask if [](auto r){}.operator()<int>(42); was only possible for chat.stackoverflow.com/transcript/message/50125049#50125049
 
nwp
Oh. Yeah, I wondered about that too. And apparently the answer is no.
 
12:42 PM
For me, the syntax of [](auto r){}.operator()(42) in itself is a revelation. I somehow thought you could only assign the result of this expression to an auto variable. A cognitive error, really.
 
nwp
I don't think it's useful. What is sometimes useful is immediately calling it.
const int value = []{
    Database db;
    db.connect();
    return db.read_value();
}();
It looks kinda freaky, but sometimes this is a reasonable way to initialize constants that require statements.
 
Well you could factor it out into a "conventional" function?
 
nwp
You could, but then you unnecessarily add that function's name into the global namespace, which arguably isn't a big downside.
 
I see. It's just me used to working alongside embedded devs, who have this (reasonable) habit of sticking to the well-known. So when I come across a new language feature, my first question is, "could/can we live without it?".
I.e. "don't use it unless you're sure you know all the side effects".
 
nwp
I can get behind knowing what you're doing.
Not so much not using what you don't absolutely have to use.
That approach means never adopting lambdas.
Among other things.
 
1:00 PM
Right, that's a balance to strike, indeed. There's also the need to keep the code simple enough to reason about. Among other reasons, to keep the entrance barrier from getting too high.
 
nwp
It's a complicated question. It's not always obvious if a couple of variadic templates with some lambdas or a bunch of casts and function pointers are clearer.
 
"easier to hire" from some managers' perspective, I guess.
 
nwp
Personally I'd lean towards using the powerful language features and making people learn enough for them to use them instead of emulating said language features with other language features that are not designed for that.
If you hire C++ programmers that are uncomfortable with lambdas and templates then you're probably screwed. It doesn't help having an easy time hiring people who don't know the language they are using.
 
@nwp When you can make people learn, so to say.
Personally, I had to get out from under the rock promptly after a couple failed interviews in 2018. Then I improved a lot, but still managed to fail one in January 2020. They got me with unique_ptr to incomplete type (I had read about it in Meyers' book, but it didn't get through on the first read) and stuff like "write a lambda such that theauto return type is going to fail".
 
nwp
Unfortunate
 
1:13 PM
@iksemyonov Honestly if an interviewer is concerned about being a dick in an interview about something like that I'm not sure I'd work there. There are special cases where you're interviewing for something like numerics or HFT stuff... but by and large all of this stuff can be taught
 
@Mgetz be honest with you, that was good school for me, but it's good I never got employed there, you've nailed it. I'm in a much friendlier place now. Remote, too.
 
I once interviewed with MS boulder and they pulled that sort of "make the interviewer feel superior" question and it just pissed me off
FWIW MS Redmond was a lot more fun to interview with
 
Well, maybe they really require that level of knowledge for their stuff. But I got very little sleep the night before and talked a bit too much, probably.. maybe they decided I was a bit funny, lol.
By the way, should static local variables in class member functions outlive the class objects? Is that defined?
 
nwp
The same rules as for other globals apply.
 
So despite the lexical scope, it's still a global variable, right?
 
nwp
1:24 PM
Yup. And it's lifetime is defined by its definition, not declaration.
 
I must be confusing scope and lifetime of local static variables?
 
nwp
Hmm, magic statics are different.
At least their construction.
 
magic?
 
nwp
Search for "magic statics" here. TLDR: static objects in functions are initialized in a thread-safe way on first call.
 
So that's why there are guard symbols in ELF files, but only for local statics.
 
1:34 PM
Wondering if some Makefile wizard can explain why this doesn't work?
```
task: THINGS := $(if $(THINGS),$(THINGS),$(shell get-things))
task:
do-things $(THINGS)

shortcut-a: THINGS = this that
shortcut-a: task
```

If I run `make THINGS='this' task`

It will assume THINGS is set and not overwrite it for that target.

But if I run `make shortcut-a` it doesn't see that THINGS was set by the parent target and instead just overwrites the value.
 
@nwp Actually, that's a good read. We hit a bug once. A local static variable in a TU was being compiled into a .o, then linked into many .so libraries. Then, at runtime, the library is loaded dynamically (a plugin). So on Linux, code in all the libraries used the first instance of the static variable. On Windows however, each time a lib was loaded, a new instance of the static was created.
 
 
2 hours later…
4:04 PM
Can I initialize size of multidimensional array in initializer list of a constructor?
 
@Paul not if you're using C style arrays no
 
@Mgetz ok, does std:array support this?
 
@Paul std::vector does, std::array is fixed size. I also wouldn't do anything that can fail in the initializer list. Do it in the body so you can confim the object is fully constructed first
 
@Mgetz I'm constrained not to use vectors. So would my only option be dynamically allocated memory?
 
@Paul Yes in which case you should still do it in the body of the constructor, initialize the pointer to nullptr in the initializer list
 
4:13 PM
@Mgetz thanks
 
the issue is that if you fail in the initializer list then the object isn't 'constructed' as far as the standard is concerned.
so the destructor won't be run
because it never had a lifetime. Once the initializer list is done, the lifetime starts
 
nwp
If you use std::unique_ptr as you should then it's fine.
 
@nwp not if it's in the initializer list... it still won't be considered constructed.
you'd have to use the function try syntax to catch it and destroy anything
 
ABC
4:45 PM
Guys I need to clean udp kernel buffer sometimes. What can I do ?
I was thinking to read it, but which is the better way?
thanks in advance!
(I'm programming in C on ubuntu)
 
@ABC UDP or up?
different things
 
ABC
udp
 
also we need more context?
reading it is the best way AFAIK
 
ABC
what?
 
what's confusing?
 
ABC
4:56 PM
AFAIK?
what is it?
 
As Far As I know
apologies
 
ABC
I have a datagram socket. Sometimes I need to clean the socket
same thing with fflush(stdin) for example
but I know that I can't use fflush
in this case
so I was thinking to read the buffer, because I know that when I read for example only 1 byte of the datagram, the other datagram bytes are deleted
 
@ABC Then just call recv but you need to set O_NONBLOCK
so you can loop through until you get zero bytes recieved
 
ABC
Perfect, infact my problems now was that
PERFECT!
thanks!
I need to use setsockopt ?
 
33
A: Get the number of bytes available in socket by 'recv' with 'MSG_PEEK' in C++

hexistYou're looking for is ioctl(fd,FIONREAD,&bytes_available) , and under windows ioctlsocket(socket,FIONREAD,&bytes_available). Be warned though, the OS doesn't necessarily guarantee how much data it will buffer for you, so if you are waiting for very much data you are going to be better off readin...

 
ABC
5:11 PM
How can I turn off O_NONBLOCK state ?
when I write fcntl(sockd,F_SETFL,O_NONBLOCK); my socket is in NON_BLOCKING state... but how can I go back in the BLOCKING mode?
 
@ABC don't? Just poll
 
ABC
what?
 
Just Poll recv?
 
ABC
ok thanks
 
 
3 hours later…
8:07 PM
How do I call a parent class method from a child class method? An instance of the child class is declared in the parent class and I don't want the method to be static.
 
8:29 PM
@Paul show some code?
 
 
3 hours later…
11:11 PM
I figured it out. I had to pass a reference of the parent class to the child class.
 

« first day (1487 days earlier)      last day (1357 days later) »