www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - void.sizeof == 1, not 0

reply simendsjo <simendsjo gmail.com> writes:
What is contained within this byte?
(T[0]).sizeof == 0, why isn't void also 0?
Jul 01 2011
parent reply Ali =?iso-8859-1?q?=C7ehreli?= <acehreli yahoo.com> writes:
On Fri, 01 Jul 2011 21:18:45 +0200, simendsjo wrote:

 What is contained within this byte?
 (T[0]).sizeof == 0, why isn't void also 0?
void* can point to any data, in which case it is considered to be pointing at the first byte of the data. Having a size of one makes it point to the next byte when incremented: int i; void * v = &i; // first byte ++v; // second byte Similarly, an empty struct has a size of one: import std.stdio; struct S {} void main() { assert(S.sizeof == 1); } But in that case it is needed to identify S objects from one another just by having different addresses. The following array's data will occupy 10 bytes: S[10] objects; assert(&(objects[0]) != &(objects[1])); Ali
Jul 01 2011
parent simendsjo <simendsjo gmail.com> writes:
On 01.07.2011 22:18, Ali Çehreli wrote:
 On Fri, 01 Jul 2011 21:18:45 +0200, simendsjo wrote:

 What is contained within this byte?
 (T[0]).sizeof == 0, why isn't void also 0?
void* can point to any data, in which case it is considered to be pointing at the first byte of the data. Having a size of one makes it point to the next byte when incremented: int i; void * v =&i; // first byte ++v; // second byte Similarly, an empty struct has a size of one: import std.stdio; struct S {} void main() { assert(S.sizeof == 1); } But in that case it is needed to identify S objects from one another just by having different addresses. The following array's data will occupy 10 bytes: S[10] objects; assert(&(objects[0]) !=&(objects[1])); Ali
Needed some time to digest your answer, but it makes sense now. Thanks.
Jul 05 2011