« first day (2142 days earlier)      last day (701 days later) » 

12:59 AM
@John "hello world" should be an lvalue, and 42U a prvalue. Why is either "the standard says so", "a string literal is a block of memory with an address", depending the level of detail you prefer.
 
1:18 AM
@JerryCoffin As a programmer, do you think what I need to do is just recite the said rule by heart?
 
 
2 hours later…
3:14 AM
@John That depends. Some rules are pretty arbitrary (e.g., the underlying rule that leads to the most vexing parse). Others (including this one) do at least make some sense, so it's generally better to understand them. But also understand that the terminology used by the standard is also somewhat arbitrary, so even though there's some sense to it, there are also cases where it's hard to find a simple rule that's accurate.
At one time, lvalue vs. rvalue was pretty simple: an lvalue reflected something stored in memory, whereas an rvalue was just a value in itself, independent of any memory location. But nowadays, something with a memory location can be an rvalue anyway (such as an xvalue).
 
I see. Thank you.
 
 
6 hours later…
9:02 AM
Hello. I am trying to define a coding guideline for the usage of new
I tend to think that new TestClass(); should be ok.
Is there any reason to use new(TestClass); or new(TestClass)();?
Wow, no code formatting in chat? What a pitty...
 
@ThomasWeller new (x)(y) means placement-new of some new y into the existing memory x, doesn't it?
 
I don't think it does, if you don't have a second identifier
 
yes, but he is just doing int * i = new(int);
I don't see any reason to surround the type with braces. Seems extra typing for no reason.
 
omg poor C++ parsers
 
When I saw the strange usages of new I also thought of placement new.
So IMHO it's not only unnecessary typing but also confusing others to look into special meanings of placement new, just to find out that it isn't placement new
 
9:14 AM
int* p = new(int);   // default-initialize: -1735318640
int* q = new(int)(); //   value-initialize: 0
std::cout << *p << "\n" << *q << "\n";
 
Or just to show that it is valid C++ code to surround the type with braces :^)
 
I used to like C++'s unnecessarily complicated syntax bullshit before I learned Clojure.
@ThomasWeller Are you related to Jens Weller of Meeting C++ fame?
 
@fredoverflow No, not related.
 
Aber zumindest geistig verbunden durch das gemeinsame Interesse an C++ ;)
 
Holy cow. How many ways are there to initialize an int?
int a(0);
int a{0};
int a{};
int a({0});
int a=0;
int a={0};
int a=int(0);
So I just need to understand all of them and know the difference.
@fredoverflow Das C++ treibt mich in den Wahnsinn. Ich komme von C# und werd mit C++ nicht warm.
 
9:26 AM
you're missing int a = {}; which is in fact with certain types different from int a{};
 
@ThomasWeller I think they all behave the same. A common pitfall that you did not list is int a(); which is a function declaration.
 
@PeterT how is it different?
 
@ThomasWeller Unless you have a specific need for C++, I would just stay with C#
 
Do all these variations exist for pointer initialization with new as well?
 
Doesn't really matter, you would never use raw new and delete in modern C++ code, anyway.
 
9:34 AM
@MangaD ah, I don't remember and now I can't find it quickly. Maybe it was only when it has list entries and you have a constructor with initializer lists or something. I just vaguely remember there being a difference
 
I'm in a 1M lines legacy codebase. Whenever I see something that starts with std:: I'm opening a bottle of champaign.
 
"legacy" meaning before C++11 or before C++98?
 
It's compiled with C++11 settings now, but large parts are actually C, not even ++.
 
I hope you get paid well ;)
 
Including funny "classes" with 10k lines.
 
nwp
10:31 AM
I can't decide if this should be moved.
Also you didn't even go into the int initialization variants using auto.
I think there were 13 different ways and the reason it's an odd number is because of int i();.
 
 
1 hour later…
11:58 AM
32 messages moved from Lounge<C++>
 

« first day (2142 days earlier)      last day (701 days later) »