nullptr Questions
3
Solved
In this answer to this question, it was noted that:
If you're going to 'clear' the pointer in the dtor, a different idiom would be better - set the pointer to a known bad pointer value.
and also ...
Macneil asked 24/6 at 19:23
2
Solved
The expresssion (void *)0 is called a null pointer.
But how about the following:
int i = 0;
void *s = (void *)i;
Is s also a null-pointer? The C-language standard says:
6.3.2.3 Pointers
3 An inte...
Ordain asked 6/6 at 4:9
3
After updating to Ventura 13.3, installing latest Xcode and command line tools, I get this error while compiling any cpp file
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/De...
1
Solved
The following code prints nullptr instead of empty (godbolt link):
#include <iostream>
class empty { };
#if 1
void f(std::nullptr_t) {
std::cout << "nullptr\n";
}
#endif
v...
Neocolonialism asked 20/12, 2023 at 16:31
2
Solved
Consider this union:
typedef union
{
void* vptr;
nullptr_t nptr;
} pun_intended;
nullptr_t is supposedly compatible with void* 1). Ok so what if we initialize the void* to some non-zero value?
p...
Coinsure asked 15/8, 2023 at 13:39
3
Solved
Our project uses C++11/14, and we want to use nullptr instead of 0 or NULL with pointers, even when 0 (as an integer literal) is allowed.
I have the following code:
int main()
{
int *ptr1 = null...
Provisional asked 22/1, 2016 at 18:15
5
Solved
Considering the following code, is it safe to do pointer arithmetic on nullptr?
I assume adding any offsets to a nullptr results in another nullptr, so far MSVC produce results as I expected, howe...
4
Solved
I'm having trouble with vector iterators. I've read in a few places that checking for null iterators isn't possible, and that the usual way to check iterators is to check it against vector.end() af...
1
Can anyone tell me why the internal representation of a nullptr assigned to a data member pointer of type Class::* is -1 for MSVC, clang and g++? For a 64-bit system (size_t)1 << 63 would be ...
Violence asked 19/5, 2022 at 13:31
5
Solved
I read about std::is_pointer in C++.
Then I wrote the program and check whether T is a pointer type or not using std::is_pointer.
#include <iostream>
int main()
{
std::cout<<std::b...
2
Solved
I am curious to know how nullptr works. Standards N4659 and N4849 say:
it has to have type std::nullptr_t;
you cannot take its address;
it can be directly converted to a pointer and pointer to me...
Germiston asked 18/4, 2020 at 2:36
5
Solved
I've been writing C++ for many years, using nullptr for null pointers. I also know C, whence NULL originates, and remember that it's the constant for a null pointer, with type void *.
For reasons, ...
Merete asked 4/9, 2021 at 16:37
4
Solved
I learned that nullptr, in addition to being convertible to any pointer type (but not to any integral type) also has its own type std::nullptr_t. So it is possible to have a method overload that ac...
3
Solved
I'm writing a small C++11 library in which I believe std::optional would be a nice addition in some functions which can return nullptr. However, std::optional is a C++17 feature. Since being C++11 ...
Hoitytoity asked 21/8, 2019 at 19:40
3
Solved
I'm trying to compile a source with Visual Studio 2008 Express, but I'm getting this error:
Error C2065: 'nullptr' undeclared identifier.
My code:
if (Data == nullptr) {
show("Data is null&q...
Annuitant asked 26/6, 2014 at 14:39
1
Solved
As it stands, my project correctly uses libavcodec to decode a video, where each frame is manipulated (it doesn't matter how) and output to a new video. I've cobbled this together from examples fou...
Rosa asked 19/3, 2021 at 5:38
3
Solved
When implementing my own unique_ptr( just for fun), I found it cannot pass this test file from libstdcxx:
struct A;
struct B
{
std::unique_ptr<A> a;
};
struct A
{
B* b;
~A() { VERIFY(b-...
Ocana asked 17/1, 2019 at 13:36
3
Solved
This question is based on code that I found that monitors possible memory leaks, so it contains some code that you probably don't want to see in regular programs like ordering pointers.
However, I ...
Glaze asked 7/12, 2020 at 16:40
14
Solved
We now have C++11 with many new features. An interesting and confusing one (at least for me) is the new nullptr.
Well, no need anymore for the nasty macro NULL.
int* x = nullptr;
myclass* obj = n...
2
I have a const z* zs = nullptr;
I want to convert zs to std::span
When I try to do std::span<const z>(zs) I get an error saying
error: no matching function for call to ‘std::span::span(const...
1
Solved
Given the example from cppreference on <=>, we can simplify the example code to:
struct person {
std::string name;
std::string surname;
auto operator <=> (const person& p) const...
Toughie asked 15/8, 2020 at 15:44
1
Solved
Since C++11, the Standard allows the macro NULL to either be a integer literal with value zero, or a prvalue of type std::nullptr_t.
Any Standard Library vendor deciding to change their definitio...
2
Solved
I'm using C++11 using Qt Creator.
"warning: identifier 'nullptr' is a keyword in C++11 [-Wc++0x-compat]"
"error: 'nullptr' was not declared in this scope"
This is on code that works elsewhere, t...
Neves asked 12/5, 2013 at 17:4
1
Solved
In ISO/IEC 14882:2017 (C++17), Section 5.13.7 "Pointer literals" is stated:
5.13.7 Pointer literals [lex.nullptr]
pointer-literal: nullptr
1 The pointer literal is the keyword nullptr. It...
4
Solved
Will C++11 implementations define NULLas nullptr?
Would this be prescribed by the new C++ standard?
1 Next >
© 2022 - 2024 — McMap. All rights reserved.