« first day (557 days earlier)      last day (2287 days later) » 

11:51 AM
I have a question which if asked on the main site would get down voted into oblivion.
I have a timing effect due to accessing a network resource.
If I move an object into a vector while the object is accessing the network, the object shouldn't change location should it?
 
yeah it would get downvoted
what does "move an object into a vector" mean
 
because I am finding that if I echo the location of this to the console it is changing.
 
what does "object is accessing a network" mean
 
emplace_back(std::move(s));
 
what does "change location" mean
what is the type of the "object"
 
11:55 AM
the object is accessing a remote location through the boost::asio and the object is my own type for handling the interface to the remote location.
If I put a sleep_for to allow the access to complete then everything works okay. Without the delay the returned value is lost.
 
for starters, "moving" an object in C++ means creating a new object and moving the old object's innards into it
it's like a copy except we don't care what happens to the old object
so yes, address changes because it's a different object
 
All the parameters of the object are references so they shouldn't move should they?
 
references like in T&? no
given your description it seems you have a multithreaded application with no synchronization
run your application under valgrind/helgrind or sth
 
12:25 PM
I tried with valgrind and while it gave a lot of noise, it was mainly in the settings class that uses statics everywhere (i didn't write that code).
I also tried gdb but getting to the point where this occurs took a long time to set up and gdb steps into the standard library so it is painfully slow to use.
Well it has given me a bit to go on. Thanks.
 
Ron
1:04 PM
A rather interesting question appeared. Can anyone shed some light on that one?
 
@Ron 'b' will be initialized after 'x'
 
nwp
Meh, not relevant in practice.
 
Clang warns about these kinds of things, the warning is -Wreorder
 
the order of construction is the one of the data member declaration (and not the one specified in the constructor initializer list), because the order of destruction must be consistent and inverse to the order of construction
of course, that's not what the question is about
 
Ron
Should one use or avoid using parameters in member initializer lists like that?
I would think it's the latter.
 
1:10 PM
I think several initializers in the constructor initializer list count as separate statements, so it's not about sequenced-before/sequenced-after
I really doubt that's not the case, but I never looked it up in the C++ standard
 
Ron
I see.
 
generally there's nothing wrong with the code except that the order of the listed members is inconsistent with the actual initialization order
 
@milleniumbug but types that are TriviallyDestructable don't hold to that restriction
 
yes, but if adding a destructor would influence the construction order, that would be a slight wtf
 
Ron
1:14 PM
Is this to be avoided in production code?
 
what's "this"
I'd say your order in the constructor must be consistent with the one in the constructor
 
Ron
The OP's way of initializing the data members.
 
side effects in initializers or putting them out of order?
 
you can enforce it by enabling warnings
in fact, I think -Wall warns on that
side effects in an initializer list aren't a problem
 
Ron
I was just about to ask that. The order of data member initialization can be?
 
Ron
I see. Visual C++ gobbles that up without warnings.
 
visual studio default warnings settings are far too lenient because their lib headers violate just about all of them
 
Ron
I see. Thanks all. Appreciate the help.
 
nwp
@ratchetfreak I heard STL brag that they are -W4 clean now.
Or /W4. Whatever the flag is.
 
that's just the STL, visual studio also has stuff like windows.h
no-one likes windows.h
 
1:47 PM
Is the rule of three deprecated in C++17?
 
It's Rule of Five from C++11 onwards
well, it's actually Rule of Zero
 
@ratchetfreak windows.h is now /W4 safe (not clean, but safe as in it won't issue warnings from it)
 
@ratchetfreak there apparently has been a very concerted effort to fix this
 
@milleniumbug I was thinking so... :D
 
1:52 PM
but following rule of 3 is valid, just not optimal (default generated move assign/construct will be created from the copy variant)
 
@ratchetfreak Ok
So, for safety reasons should I use copy & swap for moving?
Is it the best method to handle moves?
 
5 mins ago, by milleniumbug
well, it's actually Rule of Zero
 
for moving default init and swap is the way to go
 
you don't need to write any of the Big Five if all your members have sane semantics
 
@milleniumbug You like repeating yourself, don't you? :P
 
1:55 PM
and if you really need to manage a resource then a smart pointer with custom destructor will handle the details for you
 
Rule of Zero is the best method to handle moves
 
nwp
@SzymonMarczak You seem to like asking questions that were already answered :P
 
@nwp Like any other questions... :P Must try the search feature in top right corner XD
yesterday, by milleniumbug
half of the transcript of this room can be reduced to "don't use new"
 
nwp
Half of the rest is probably "don't use C stuff" and half of that rest belongs in the lounge.
 
@nwp you're right
yesterday, by milleniumbug
the other half is "I know but fucking uni hasn't updated their learning materials for 20 years"
@nwp "half of that rest belongs in the lounge" haha, you got me :DDDD
 
2:06 PM
People wonder why C++ vets get annoyed with questions, it's mostly because they've already answered them publicly about a thousand times
 
@Mgetz There should be some sort of C++ Bible in which all questions and answer would be placed. I'm just wondering how many pages would it count...
 
@SzymonMarczak there is.... it's Bjarne's book
it even gets updates for each new C++ release
 
nwp
@SzymonMarczak If only there was a website where you could ask questions and people would answer them and then you could look up answers later. Nah, that would never work.
 
@nwp I think there is one... StackOverflow :P
 
but it's endless september and no-one seems to be able to find the search bar
 
2:17 PM
@ratchetfreak Why did you name it endless september?
@milleniumbug just being curious - why is your about text set to wake up and smell the disgust? The disgust of repeating questions day by day? :P
 
@SzymonMarczak it's an old lounge meme
 
because back in the old days september was the time new students flooded the interwebs and offended everyone by not following netiquette, however nowadays people join at any time
 
in Lounge<C++>, Dec 2 '15 at 16:58, by Andy Prowl
I just spent about 35 minutes reading the transcript for the C++ room and have to say that it looks just as bad as some of the worst reddit threads I've seen. #disgusted — Tiny Giant 14 hours ago
 
nwp
794
Q: Open letter to students with homework problems

user40980It is September once again (today is the 8755th day of September), and once again students are asking their homework problems on Stack Overflow and SoftwareEngineering.SE. We start seeing questions like: A car dealer has 10 salespersons. Each salesperson keeps track of the number of cars sol...

2
 
LOL
@nwp best open letter i've ever read
 
2:27 PM
EX of a september question:
-2
Q: File Handling and if else

Moeed Rehman MasoodI am trying to make a program for my University project and I needed some help. I am trying to make a program which creates a file using ofstream and stores 1 or 0 in it (I've already found a way to store 0 or 1 in the file using random) and tells if the file contains 0 or 1 using if-else statem...

 
@Mgetz "University project" says everything xd
 
@SzymonMarczak there have been SOME good uni project questions, but they are very few and far between.
 
2:43 PM
@milleniumbug Rule of Zero - But why would anyone want to do that when you can just grab an existing reusable ownership policy instead and get the same effect? - I'm not sure if I understand the rule correctly: usually I don't need to write move constructor, move assigment, copy assigment because they're all based on the copy constructor?
 
49 mins ago, by milleniumbug
you don't need to write any of the Big Five if all your members have sane semantics
if you prefer a more code-oriented approach to explaining what's Rule of Zero is about, here's what I've written gist.github.com/milleniumbug/38224655327844a94a95e915023a4ebf
 
@SzymonMarczak if you don't write any the compiler gives you them all for free
 
@Mgetz "for free" :D YES! I don't have to pay XD
 
well you don't have to type them
but the big 5 will still be generated based on the corresponding big 5 of each of the members
 
@SzymonMarczak "for free" is appropriate. otherwise you're paying for the maintenance cost of having more code which is fragile
 
2:53 PM
that took forever to upload
 
@Mgetz hmm, it looks like forever has an end :P
 
@SzymonMarczak pedantry is not always appreciated, please accept hyperbole on occasion
also technically speaking infinity is finite
 
nwp
what?
 
@Mgetz just kidding, don't take it seriously :)
 
@nwp IIRC it's a quirk of number theory that infinity is finite because it IS the bound itself. But I'm probably wrong
 
3:01 PM
@Mgetz :O
@Mgetz But... you can't tell how many exactly it is... IMO Infinity is infinity (it has no end) so it can't be bound because it's infinity already. It has no bounds, I think so.
 
@SzymonMarczak I'm not a mathematician or number theorist, and please understand it's probably BS mis interpreted by a layperson
 
nwp
I read something neat somewhere. Someone would add 10 balls to a box and remove 1. Repeat infinite times. How many balls are in the box?
Apparently the answer is 0 and it makes no sense to me.
 
@Mgetz I'm not a mathematician either, I just said what I think. I don't know the truth either :P
@nwp Could you drop a link?
 
nwp
@SzymonMarczak yup
 
3:21 PM
@milleniumbug What if it gets a bit complicated: it can create a new D using smart pointers or take B* which is owned by another class?
Also thank you very much for that example. It helps a lot! :)
@nwp "I think that after one accepts the second version, there is nothing particularly surprising about the third version anymore."; "In the second version, nn-th ball is removed at the nn-th step. There are zero balls left after midnight because each ball is eventually going to be removed at the corresponding step.". TL;DR: each ball will be removed at certain time, so in the end there'll be 0 balls left. I'm confused too.
 
@SzymonMarczak that doesn't change anything. The "conditional ownership" policy should be separated into a separate type
of course, my opinion is that having ownership conditional at runtime is a questionable decision that will inevitably result in bugs
 
@milleniumbug ok
@milleniumbug I meant const B* (read-only). Will this change something?
 
well, you're still having ownership conditional
 
nwp
@SzymonMarczak Yeah, that makes total sense. But saying "each step 10 balls are added and 1 removed, so 9 balls are added each step and 9 times infinity is infinity" makes an equal amount of sense to me.
 
@nwp You're right. I'm not sure which answer is correct...
@milleniumbug I'm noob. Could you explain what exactly is ownership conditional? The class would not own the D.
 
3:35 PM
In my example "B" and "D" are a base and a derived type. What are they in yours
(also: there is a single resource so it doesn't matter that if it's B or D. B/D was a demonstration of a use case. it would work the same with any other resource)
 
@milleniumbug assume it's the same as yours
 
ok, let me break this down
> it can create a new D using smart pointers or take B* which is owned by another class
"creates a new D" implies it has ownership over it
 
@milleniumbug yup
 
"takes B*" implies it doesn't have ownership over it (unless we're talking about shared ownership, but you haven't specified that)
"or" implies there is only one of these that happens at a given time
 
@milleniumbug yes it doesn't have, it's not shared ownership
 
3:41 PM
so, the ownership is conditional because it either owns or it doesn't given a runtime condition
 
@milleniumbug OK, now i get it
I think the solution is to copy the data from B*
 
Jul 28 '16 at 20:36, by milleniumbug
well there are several options you can take:
Jul 28 '16 at 20:36, by milleniumbug
a.) just copy it
b.) take ownership of it (see `unique_ptr` or `shared_ptr`)
c.) UNSAFE: take a pointer to it
the last option is unsafe because you have to document that the thing you're accepting has to outlive the thing you're currently creating
 
@milleniumbug assume it will outlive it
 
assumptions tend to make bugs
3
 
@ratchetfreak true
 
3:45 PM
it's unsafe, but it's done (heck, std::string_view does it)
 
@milleniumbug I want to do the thing same as std::string_view does :PP
 
std::string_view doesn't conditionally own the string
also, if it's about that ByteBuffer, then yes, it should have used a std::vector<char>
 
@milleniumbug It has changed a bit, IKR it was too easy to figure out that I ask about it :P
@milleniumbug it's some kind of mix. Got and idea: seperate class A. X would create new D using smart pointers (or make a copy) and Y take a pointer. As you've pointed out, the safest way is to use std::vector<char> I agree :)
 
4:05 PM
@SzymonMarczak just use a GSL span
 
@milleniumbug Here's the result: coliru.stacked-crooked.com/a/f938007ad708d9c2 There's [almost] no difference [in performance on my machine; now -O3 is as fast as -O2] between std::vector<char> and char[]. I think switching to std::vector<char> gave more benefits. Now it satisfies the Rule of Zero, I think.
I would appreciate any advices, even shoutouts about the project above :)
2 days ago, by milleniumbug
Sep 15 '17 at 16:04, by milleniumbug
@StephanHofmann If you need to release anything, you're doing it wrong. (see: RAII)
2 days ago, by Mgetz
if you need to write a destructor... you're probably doing it wrong
^^^ Rule of Zero ^^^
 
 
2 hours later…
6:01 PM
HI there, quick question. Does C++ have a modulus operator that functions similar to a regular calculator?
for example, when I use my calculator -1 mod 4 gives me 3
 
2 messages moved from Lounge<C++>
fairly sure you can implement it on top of %
otherwise no
 
not even in a library?
that seems odd
 
25
A: What's the difference between “mod” and “remainder”?

chux Does '%' mean either "mod" or "rem" in C? In C, % is the remainder. ..., the result of the / operator is the algebraic quotient with any fractional part discarded ... (This is often called "truncation toward zero".) C11dr §6.5.5 6 The operands of the % operator shall have integer ty...

 
I see.
It's actually surprising that euclidean modulus isn't defined anywhere in the libraries.
 
6:21 PM
When we do bit=1, we can set a bit. When we do bit=0, we clear a bit. What's the word for bit=x ?
where x can be either 0 or 1, and it isn't known in advance.
 
set a bit
 
3 messages moved from Lounge<C++>
 
When we do bit=1, we set a bit. When we do bit=0, we clear a bit. What's the word for bit=x ?
 
1 message moved from Lounge<C++>
 
You can also set a bit to zero :-)
Or in an FPGA, set a bit to high-impedance (aka "Z")
 
6:26 PM
With hardware people, "set a bit" means 1, while "clear a bit" means 0.
 
1865
Q: How do you set, clear, and toggle a single bit?

JeffVHow do you set, clear, and toggle a bit in C/C++?

 
This is confusing with the getters and setters in OO. So, SetBit method can be confusing to some hardware folks. That's my concern.
 
Another reason why everybody doing OO with bits should be shot.
Actually this is what nvidia does.
 
Hello I'm looking for someone expert with Hex editing that could help me ^^
 
6:29 PM
So in Simulink "bit set" means "set to 1", and "bit clear" means "set to 0", unlike the C++ reference by milleniumbug
 
Do you know a chat for it even on freenode ?
 
I'll probably do ChangeBit(bit, value), or AssignBit(...), or ProclaimBit(...), or some such. This is to solicit humorous verbs.
 
@NickAlexeev "assign" (or possibly "copy").
@NickAlexeev Oh, in that case I'd think of when you put a bit in a horse's mouth, so the verb would be "bridle".
@Mikhail Hardware in general, not just FPGA (but of course you knew that already).
 
@JerryCoffin ...or riddle ...as in RiddleMeBit()
 
@NickAlexeev Riddle me bits and shiver me timbers!
 
6:40 PM
Bite off a bit?
 
7:24 PM
@Mikhail Thanks, but no--I already bit off a bite.
 
 
3 hours later…
Ron
10:26 PM
Is code under possible implementation on cppreference a proprietary code?
 
I saw it once. It's under a similar license as Stack Overflow code
At least if I understand it correctly
 
guys don't you think music is a key component of programming?
 
Ron
@Justin Appreciate it. Who decides on possible implementation code snippets? Committee, or is it a user contribution?
 
fairly sure the latter
 
@Ron It's a wiki. It's the latter
 
Ron
10:31 PM
I see.
 
nwp
10:59 PM
@questnofinterest no
 
key component of programming is programming :P :D
 
11:24 PM
@questnofinterest I consider the key component of programming to be a keyboard. For better or worse, I'm not a big fan of piano music though, so I'm less interested in key components than in strings.
 
Hello people
did anyone of you know why cout is evil in the combination with cout
?
sorry, I mean in the combination with auto_ptr
 
std::auto_ptr is deprecated in C++11 and removed in C++17 in favour of std::unique_ptr
 
thank you @milleniumbug
 
so if anyone is actually "evil" here, it's std::auto_ptr
 
Same using unique ptr after cout, automatically I get for my class member cout string length size on auto destruct, anything after cout is broken.
 
11:37 PM
post the code
 
so I was thinking that the jump on the sys calls will loose the scope
ov my var
I have made a bare test randomly added constructors and so on..
@milleniumbug pastebin.com/Vgmss6La
I have also made a test using nested functions instead of cout which will not cause that, value at init will remain until destruction of the object
I am trying to explain to a friend of mine but I can't
 
nwp
I don't really know what you are trying to show either, but I can tell you that cout doesn't change any scopes.
 
> warning: a temporary bound to 'Component<short unsigned int>::m_identifier' only persists until the constructor exits [-Wextra]
 
Hey guys, looking for some help with my code. Is it ok to paste a link here?
 
@milleniumbug maibe just a coincidence there using different versions of compiler settings
 
11:49 PM
yes, post a link
 
0
Q: Errors linking crypt_blowfish in C to C++ executable

SagunKhoI'm trying to use libbcrypt and I'm facing an issue compiling this on a docker debain container (cmake v3.7.2-1), while it compiles without errors on macOS (cmake v3.10). I'm sorry if my post is mostly code but I'm also trying to learn how cmake works, and what i've done wrong here. Any other inp...

 
@LXSoft the warning accurately points to the problem with your code
 
@milleniumbug you right, I appreciate
 
@SagunKho I don't know these libraries, but are you linking the library that has crypt_gensalt_rn?
 
hmm.. you're right. I'm probably not... going to try something
 

« first day (557 days earlier)      last day (2287 days later) »