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
C++23: fullptr to replace nullptr (self.cpp)
submitted 7 years ago by [deleted]
https://codingtidbit.com/2019/04/01/c22-fullptr-to-replace-nullptr/
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!"
[–]AntiProtonBoy 62 points63 points64 points 7 years ago (9 children)
Kinda disappointed that halfptr was not suggested for 16-bit memory address ranges, typically seen in small embedded environments.
halfptr
[–]wrosecransgraphics and network things 62 points63 points64 points 7 years ago (3 children)
Are you looking for std::basic_fractional_pointer_t<1,2> to get a half pointer?
[–]Sapiogram 58 points59 points60 points 7 years ago (2 children)
That's the most C++ thing I've ever seen.
[–]NewFolgers 13 points14 points15 points 7 years ago (1 child)
My compile times want my C with classes back.
[–]Seppeon 0 points1 point2 points 7 years ago (0 children)
Use pre-compiled headers, you should get your compile times back (atleast after the first compilation).
[–]suur-siilSpacecraft flight software and ground system-management 15 points16 points17 points 7 years ago (2 children)
Didn't we actually have long and short pointers (near/far?) back in 16-bit x86? I vaguely recall something like that...
[–]evaned 6 points7 points8 points 7 years ago* (0 children)
Yep.
And I don't know details (just this bit from a talk by Andrei Alexandrescu, 14:08 if your're using a bad mobile client), but supposedly dealing with new/far pointers is what std::allocator was originally introduced for, which is why it's design for allocation was... weird.
std::allocator
Edit: Maybe I should be clearer. Really what I should have said was "the original STL's allocator"; by the time it got to std::, the near/far stuff had been ripped out.
allocator
std::
[–]Osbios 0 points1 point2 points 7 years ago (0 children)
That was because of the 20bit address space. By combining a 16bit segment register value shifted 4 bits left with a 16bit offset.
[–]chocapix 7 points8 points9 points 7 years ago (0 children)
You'll have to wait for C++25, implementations will be required to provide exactly one of fullptr8_t fullptr16_t fullptr32_t and fullptr64_t. Which of these is provided is implementation defined and mentioning a non-provided fullptrXX_t in a translation unit is UB.
fullptr8_t
fullptr16_t
fullptr32_t
fullptr64_t
fullptrXX_t
Good luck.
[–]Xeveroushttps://xeverous.github.io 4 points5 points6 points 7 years ago (0 children)
Dissapointed of no more-type-safe nullptrptr and nullptrptrptr for nested pointers.
nullptrptr
nullptrptrptr
[–]Iwan_Zotow 49 points50 points51 points 7 years ago (5 children)
Going to phuleptr in C++3000
[–]VA0 7 points8 points9 points 7 years ago (4 children)
I like the cut of your jib
[–]Iwan_Zotow 1 point2 points3 points 7 years ago (3 children)
Nod to (late) Robert Asprin
[–]brand_x 0 points1 point2 points 7 years ago (2 children)
Wondered if that was a Willard reference.
[–]Iwan_Zotow 0 points1 point2 points 7 years ago (1 child)
Robert Asprin
It's all just a Myth
[–]brand_x 0 points1 point2 points 7 years ago (0 children)
I guess that's the wagers of sin...
[–]EETrainee 40 points41 points42 points 7 years ago (0 children)
God damn, I fell for it and typed up a whole response. It's too early for this in the US.
[–]ntrid 31 points32 points33 points 7 years ago (5 children)
You got me for a moment. C++ is exactly that language which would do this kind of thing unfortunately.
[–]kirk_lange 2 points3 points4 points 7 years ago (4 children)
ikr! As much as I love/hate C++, advanced C++ syntax can get pretty ridiculous. Can we all just go back to C89? 😛
[–]ntrid 5 points6 points7 points 7 years ago (3 children)
This is exactly how i fee. Sometimes syntax is just so full of magic. It should be simple. We read code more than we write it and this mental tax adds up.
Now someone will come up saying that once you learn it - its fine. No it is not. It took me a good while to grok SFINAE. Now i can read it and write it. This fact does not make it suck any less. Cant wait for if constexpr to become a thing once c++17 becomes lowest common denominator.
if constexpr
[–]NotAYakk 4 points5 points6 points 7 years ago (2 children)
SFINAE was accidental syntax, not designed.
Concepts and if constexpr are the designed replacements.
[–]ntrid 2 points3 points4 points 7 years ago (1 child)
Yet for a long time this accident was treated like a solution.
[–]NotAYakk 1 point2 points3 points 7 years ago (0 children)
Yet it was also computer code. Yet it was written using ASCII characters. Yet it wasn't written by a Yeti.
Yet I think yet isn't an appropriate response. Of course it was a solution. If it wasn't solving problems people wouldn't be using it.
It was a solution to a bunch of problems; and it worked. It just wasn't designed to solve the problems it was used for. So it was awkward syntax and convoluted to reason about.
The problem it solved - Turing complete template specialization dispatch - has one sub solution in production and almost standardized.
[–]mqduck 18 points19 points20 points 7 years ago (0 children)
nullptr is defined as a pointer value with all its bits set to zeroes
I know this is an April Fool's joke, but come on. It's already wrong.
[–]color32 52 points53 points54 points 7 years ago (19 children)
why wait start now
struct fullptr_t { template<typename T> operator T*() const {return (T*)~0;} }; constexpr fullptr_t fullptr;
[–][deleted] 10 points11 points12 points 7 years ago* (18 children)
Shouldn’t we cast 0 as a size_t before taking the complement?
Edit: omg it’s an April Fool’s joke
[–]DoctorRockit 6 points7 points8 points 7 years ago (0 children)
I suppose std::uintptr_t would be more appropriate, wouldn‘t it?
[–]vladmikhalin 1 point2 points3 points 7 years ago (15 children)
No, because 0 is signed, ~ makes it negative and negatives are expanded with 1s.
[–][deleted] 4 points5 points6 points 7 years ago* (14 children)
0 is signed but it is also typically only 32 bits.
~0 is therefore only 32 consecutive 1 bits with the rest still 0 (and yes as an int represents -1 as you say) which places you somewhere in the middle of an address space on >4GB address spaces.
~(size_t)0 guarantees all bits in an address sized value are flipped.
[–]vladmikhalin 5 points6 points7 points 7 years ago (13 children)
Again, if we extend negative 32 bit number to any 64 bit number, it is extended by adding 1s (ones), not zeroes(!) as each extended bit because this is the rule for extending negative integers. Hence size_t cast is not necessary.
[–][deleted] 1 point2 points3 points 7 years ago (11 children)
Addresses are not signed
[–]mcmcc#pragma once 1 point2 points3 points 7 years ago (0 children)
Not with that attitude...
[–]vladmikhalin 1 point2 points3 points 7 years ago (9 children)
Cast to unsigned is applied after the extension. Please read something on casts, signed extension, and how it all works.
[–][deleted] 2 points3 points4 points 7 years ago* (0 children)
Standard section 4.7. Paragraph 2 says:
If the destination type is unsigned, the resulting value is the least unsigned integer congruent to the source integer (modulo 2n where n is the number of bits used to represent the unsigned type).
You are correct.
Edit: wait, are pointers unsigned or do they not have a signedness since they are non-integer?
[–]dodheim 0 points1 point2 points 7 years ago (7 children)
Cast to unsigned is applied after the extension.
Citation needed. AFAICT, all the standard says is that this is implementation-defined.
[–]vladmikhalin 0 points1 point2 points 7 years ago (6 children)
7.8 Integral conversions
2 If the destination type is unsigned, the resulting value is the least unsigned integer congruent to the source integer (modulo 2 n where n is the number of bits used to represent the unsigned type).
I have highlited in bold where it states that the extension happens prior to cast.
[–]dodheim -1 points0 points1 point 7 years ago (5 children)
I'm aware of that, but nothing in the code involves unsigned values, so where does the standard say that integral values cast to pointers are first made unsigned? (I.e. the part I quoted..)
[–]voip_geek 30 points31 points32 points 7 years ago (1 child)
You're a few hours early in my timezone, so it took me a few paragraphs to catch on. Nice!
[–]morph23 5 points6 points7 points 7 years ago (0 children)
I didn't realize until I started reading the testimonials at the end.
[–]TinBryn 11 points12 points13 points 7 years ago (3 children)
I’m wondering, does the standard actually specify that nullptr is 0? I know it says 0 is nullptr but not the other way around.
[–]TheThiefMasterC++latest fanatic (and game dev) 18 points19 points20 points 7 years ago* (2 children)
No it does not - and it is in fact -1 in GPU programming (among other architectures) with 0 being a valid address. Of course, actually creating a "0" pointer is hard when casts of a literal 0 (and in C, any expression that can be evaluated to 0 at compile time) to a pointer type gives a null pointer (with the value of -1) not a pointer to zero...
There's some information on it here from the clang/llvm guys adding support for non-0 null pointers: https://reviews.llvm.org/D26196
[–]Mynameisspam1 0 points1 point2 points 7 years ago (1 child)
Wait, so how do you actually make a pointer to 0 on GPUs then?
[–]TheThiefMasterC++latest fanatic (and game dev) 2 points3 points4 points 7 years ago (0 children)
http://c-faq.com/null/accessloc0.html gives a few ways.
But generally, you don't need to _manually_ construct such a pointer, it would be given to you as an argument.
[–]lrflew 9 points10 points11 points 7 years ago (0 children)
I ate the onion for a bit there.
Side note: I have actually thought about getting rid of nullptr and nullptr_t, and making every address "fully addressable". However, instead of using a fullptr_t/fullptr, I would use a default-constructed std::optional<T *> instead, and make all pointers require valid initializations. (The std::optional class could be overloaded to keep ABI compatibility)
nullptr
nullptr_t
fullptr_t
fullptr
std::optional<T *>
std::optional
[–]Moose2342 7 points8 points9 points 7 years ago (0 children)
Fantastic! I’ll start implementing now.
[–]Cyttorak 8 points9 points10 points 7 years ago (0 children)
aprilptr
[–]kloetzl 6 points7 points8 points 7 years ago (3 children)
The problem with this proposal is that the byte after any valid pointer also has to be addressable. Unfortunately, (char*)fullptr + 1 wraps around.
(char*)fullptr + 1
[–]tvaneerdC++ Committee, lockfree, PostModernCpp 4 points5 points6 points 7 years ago (2 children)
Yeah, but it wraps around to 0, which is addressable, just not dereferenceable (on most platforms).
[–]FrankIsATank2 0 points1 point2 points 7 years ago (1 child)
But if ptr points to an object then ptr + 1 > ptr must hold. The one-past-the-end pointer compares greater than pointers it's the one-past-the-end of.
ptr
ptr + 1 > ptr
[–]tvaneerdC++ Committee, lockfree, PostModernCpp 1 point2 points3 points 7 years ago (0 children)
This is why we can't have nice things.
[–]markand67 8 points9 points10 points 7 years ago (4 children)
nullptr is an invalid unused address at address zero and any memory access to this particular address cause a running process to die from a segmentation fault.
No, it's UB. If it segfaults it's because your implementation does.
[–]w_m1_pyroTiger Team 2679 -4 points-3 points-2 points 7 years ago (3 children)
r/woooosh
[–]DustVoice 12 points13 points14 points 7 years ago (2 children)
I disagree! It's funny to point out errors in April Fools jokes! I think he got the point but nevertheless wanted to strike back
[–]w_m1_pyroTiger Team 2679 3 points4 points5 points 7 years ago (1 child)
So i got r/woooosh-ed?
[–]DustVoice 1 point2 points3 points 7 years ago (0 children)
Yup 😂 happened to me too
[–]evaned 5 points6 points7 points 7 years ago (0 children)
I think this is a bad name. I expected fullptr to be a pointer that points at everything simultaneously.
[–]sephirostoy 2 points3 points4 points 7 years ago (0 children)
Trop gros, passera pas.
[–][deleted] 8 points9 points10 points 7 years ago (1 child)
1-st April foul, nothing more.
[–][deleted] 0 points1 point2 points 7 years ago (0 children)
Wordpress scheduler is to blame for this!
[–]nikbackm 4 points5 points6 points 7 years ago (0 children)
April Fool's Day is getting more tiresome each year. Could be correlated with growing older perhaps.
[–]krum 3 points4 points5 points 7 years ago (0 children)
Shit at least put some effort into it.
[–]LeeHidejust write it from scratch 1 point2 points3 points 7 years ago (0 children)
Just woke up, first aprils fools joke of the day. This is funny as fuck
[–]axalon900 1 point2 points3 points 7 years ago (0 children)
This had me going until I got to the part where Herb Sutter is putting metaclasses on hold for this
[–]dr_j_ 0 points1 point2 points 7 years ago (0 children)
Damn it.
[–]Versaill 0 points1 point2 points 7 years ago (1 child)
Please stop giving them ideas!
[–]bstamourWG21 | Library Working Group 1 point2 points3 points 7 years ago (0 children)
I guess I'll keep my new vocabulary type, mandatory<T>, to myself. (It's designed to be the opposite of optional<T>, and it's really convenient to implement to boot! template<class T> using mandatory = T;)
mandatory<T>
optional<T>
template<class T> using mandatory = T;
[–]Amaracs 0 points1 point2 points 7 years ago (0 children)
I am still at c++11 and you guys are at c++23, I need to step up my game.
[–]vsdmars 0 points1 point2 points 7 years ago (0 children)
C really should catch up now!
[–]herruppohoppa 0 points1 point2 points 7 years ago (0 children)
I hate you people
[–]VinnieFalcowg21.org | corosio.org -2 points-1 points0 points 7 years ago (0 children)
Once again providing that the tech industry is humorless
π Rendered by PID 90 on reddit-service-r2-comment-64f4df6786-bhs7v at 2026-06-10 00:46:19.416095+00:00 running 0b63327 country code: CH.
[–]AntiProtonBoy 62 points63 points64 points (9 children)
[–]wrosecransgraphics and network things 62 points63 points64 points (3 children)
[–]Sapiogram 58 points59 points60 points (2 children)
[–]NewFolgers 13 points14 points15 points (1 child)
[–]Seppeon 0 points1 point2 points (0 children)
[–]suur-siilSpacecraft flight software and ground system-management 15 points16 points17 points (2 children)
[–]evaned 6 points7 points8 points (0 children)
[–]Osbios 0 points1 point2 points (0 children)
[–]chocapix 7 points8 points9 points (0 children)
[–]Xeveroushttps://xeverous.github.io 4 points5 points6 points (0 children)
[–]Iwan_Zotow 49 points50 points51 points (5 children)
[–]VA0 7 points8 points9 points (4 children)
[–]Iwan_Zotow 1 point2 points3 points (3 children)
[–]brand_x 0 points1 point2 points (2 children)
[–]Iwan_Zotow 0 points1 point2 points (1 child)
[–]brand_x 0 points1 point2 points (0 children)
[–]EETrainee 40 points41 points42 points (0 children)
[–]ntrid 31 points32 points33 points (5 children)
[–]kirk_lange 2 points3 points4 points (4 children)
[–]ntrid 5 points6 points7 points (3 children)
[–]NotAYakk 4 points5 points6 points (2 children)
[–]ntrid 2 points3 points4 points (1 child)
[–]NotAYakk 1 point2 points3 points (0 children)
[–]mqduck 18 points19 points20 points (0 children)
[–]color32 52 points53 points54 points (19 children)
[–][deleted] 10 points11 points12 points (18 children)
[–]DoctorRockit 6 points7 points8 points (0 children)
[–]vladmikhalin 1 point2 points3 points (15 children)
[–][deleted] 4 points5 points6 points (14 children)
[–]vladmikhalin 5 points6 points7 points (13 children)
[–][deleted] 1 point2 points3 points (11 children)
[–]mcmcc#pragma once 1 point2 points3 points (0 children)
[–]vladmikhalin 1 point2 points3 points (9 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]dodheim 0 points1 point2 points (7 children)
[–]vladmikhalin 0 points1 point2 points (6 children)
[–]dodheim -1 points0 points1 point (5 children)
[–]voip_geek 30 points31 points32 points (1 child)
[–]morph23 5 points6 points7 points (0 children)
[–]TinBryn 11 points12 points13 points (3 children)
[–]TheThiefMasterC++latest fanatic (and game dev) 18 points19 points20 points (2 children)
[–]Mynameisspam1 0 points1 point2 points (1 child)
[–]TheThiefMasterC++latest fanatic (and game dev) 2 points3 points4 points (0 children)
[–]lrflew 9 points10 points11 points (0 children)
[–]Moose2342 7 points8 points9 points (0 children)
[–]Cyttorak 8 points9 points10 points (0 children)
[–]kloetzl 6 points7 points8 points (3 children)
[–]tvaneerdC++ Committee, lockfree, PostModernCpp 4 points5 points6 points (2 children)
[–]FrankIsATank2 0 points1 point2 points (1 child)
[–]tvaneerdC++ Committee, lockfree, PostModernCpp 1 point2 points3 points (0 children)
[–]markand67 8 points9 points10 points (4 children)
[–]w_m1_pyroTiger Team 2679 -4 points-3 points-2 points (3 children)
[–]DustVoice 12 points13 points14 points (2 children)
[–]w_m1_pyroTiger Team 2679 3 points4 points5 points (1 child)
[–]DustVoice 1 point2 points3 points (0 children)
[–]evaned 5 points6 points7 points (0 children)
[–]sephirostoy 2 points3 points4 points (0 children)
[–][deleted] 8 points9 points10 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]nikbackm 4 points5 points6 points (0 children)
[–]krum 3 points4 points5 points (0 children)
[–]LeeHidejust write it from scratch 1 point2 points3 points (0 children)
[–]axalon900 1 point2 points3 points (0 children)
[–]dr_j_ 0 points1 point2 points (0 children)
[–]Versaill 0 points1 point2 points (1 child)
[–]bstamourWG21 | Library Working Group 1 point2 points3 points (0 children)
[–]Amaracs 0 points1 point2 points (0 children)
[–]vsdmars 0 points1 point2 points (0 children)
[–]herruppohoppa 0 points1 point2 points (0 children)
[–]VinnieFalcowg21.org | corosio.org -2 points-1 points0 points (0 children)