0

If you will create an object of a totally empty class it's size will be >0 as guaranteed by the standard (in order two objects have different addresses). But I'm interested what is stored in this byte (some value, index, address)? Is there some way to know this?

MainstreamDeveloper00
  • 8,436
  • 15
  • 56
  • 102

4 Answers4

1

Technically, What is stored there is Unspecified.
In short it is left up to the implementation and the implementation does not need to document the behavior.

Alok Save
  • 202,538
  • 53
  • 430
  • 533
1

It has the same (unknown, undefined) content as any other filler that is used to fill gaps between for example a char and an int member. And in common with the "gap-filler", it has no purpose other than as a "make sure the placement of this data works out". If the size of an empty class was zero, an array of two such objects would take up zero bytes and both objects would have the same address, which would make things rather strange for all manner of things.

Mats Petersson
  • 126,704
  • 14
  • 140
  • 227
0

If i recall correctly the standard guarantees that an object of an empty class will occupy space. It doesn't say exactly how much space, neither what is stored there, so that is up to the implementer.

If you want to know what is in the given space, you could just reinterpret cast it and have a look.

daramarak
  • 6,115
  • 1
  • 31
  • 50
0

Nothing, it is just padding. You cannot depend on the value stored there, or even that there is any value at all, just like with any other padding.

David Rodríguez - dribeas
  • 204,818
  • 23
  • 294
  • 489