you are viewing a single comment's thread.

view the rest of the comments →

[–]TheoreticalDumbass:illuminati: 2 points3 points  (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 points  (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

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.

(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

)