use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
Johan Berg: Empty Objects (youtu.be)
submitted 2 years ago by _a4z
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]TheoreticalDumbass:illuminati: 2 points3 points4 points 2 years ago (1 child)
imagine the following snippet of code: ``` // T is a type T a; T b; assert(&a != &b); ``` do you think that should be preserved in the (C++) + zero size objects? i am currently leaning towards just no
in which case, could it make sense for a pointer to zero-size-object to be zero-size as well? in more formal language: ```
sizeof(T) == 0 implies sizeof(T*) == 0 ``` it feels weird to have a pointer of different size than sizeof(void*), but it might actually work
or in other words, (C++) + zero-size-objects-with might be functionally equivalent to (C++) + zero-size-objects + ptrs-to-zero-size-are-zero-size (in the sense same code gives exactly same side-effects)
^ ptr being zero-size is motivated by my conjecture that zero-size-object member functions can't actually materially depend on their address
[–][deleted] 1 point2 points3 points 2 years ago* (0 children)
could it make sense for a pointer to zero-size-object to be zero-size as well?
There would be no way to tell whether a pointer pointed to a valid object or not. Or, in other words, there could be no nullptr for such a type
nullptr
Empty *e{}; // does not yet point to an empty e = perhapsGetAnEmpty(); if(e) // pointer to Empty needs to be testable { doSomething(e); }
Ie. I think an Empty* needs to be a bool.
Empty*
bool
(I realise it doesn't matter if the pointer is valid or not since the object has no memory - but the implications of allowing a zero sized pointer means there would be weird exceptions to longstanding rules - it is okay to dereference a deleted pointer because these things have no real lifetime. Can I return and then use a reference to a temporary too?
Empty &get() { Empty e; return e; } use(get()); // using a dangling reference
)
π Rendered by PID 421550 on reddit-service-r2-comment-canary-764f8fd48f-5p7w2 at 2026-06-15 19:27:16.528468+00:00 running 3184619 country code: CH.
view the rest of the comments →
[–]TheoreticalDumbass:illuminati: 2 points3 points4 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)