Re: void.sizeof == 1, not 0

2011-07-05 Thread simendsjo

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.


void.sizeof == 1, not 0

2011-07-01 Thread simendsjo

What is contained within this byte?
(T[0]).sizeof == 0, why isn't void also 0?


Re: void.sizeof == 1, not 0

2011-07-01 Thread Ali Çehreli
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