On Monday, 17 July 2017 at 23:01:40 UTC, Walter Bright wrote:
On 7/16/2017 5:41 AM, Timon Gehr wrote:
struct S{
    T x;
    Bottom everything;
}

turns the entire struct into an empty type. It is therefore most natural to say that Bottom.sizeof == ∞. (It's the only choice for which S.sizeof == Bottom.sizeof.)

Another way to think about it: If something of type A* converts to something of type B* without problems, then one would expect B.sizeof <= A.sizeof. This would imply that Bottom.sizeof >= size_t.max. (Because Bottom* converts to all other pointer types.)

One small issue is that one needs to avoid overflow for the size of a struct that has multiple fields where one of them is of type Bottom.


But if Bottom does not exist, then S doesn't exist either, and hence the < size relationship has no meaning.

(Reminds me of divide by 0 discussions in calculus class.)

Strictly speaking it just shouldn't have a sizeof, because sizeof is shorthand for "size of an instance of" (types don't really have sizes, how do I store the type "int" in memory?) and Bottom has no instances.

Infinity - or the next best applicable thing size_t.max - is a reasonable standin for an invalid value, except that people will do silly things like `auto paddedSpace =
 (ReturnType!foo).sizeof + 1;` and then you're in trouble.

Better to just not define it.

Is there some magic that can be done where all code that makes reference to an instance of Bottom just isn't compiled? I.e. if there happens to be a situation where a function returns Bottom then all code that touches that return type is just ignored?

Reply via email to