digitalmars.D.learn - void.sizeof == 1, not 0
- simendsjo (2/2) Jul 01 2011 What is contained within this byte?
- Ali =?iso-8859-1?q?=C7ehreli?= (21/23) Jul 01 2011 void* can point to any data, in which case it is considered to be
- simendsjo (2/25) Jul 05 2011 Needed some time to digest your answer, but it makes sense now. Thanks.
What is contained within this byte? (T[0]).sizeof == 0, why isn't void also 0?
Jul 01 2011
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
On 01.07.2011 22:18, Ali Çehreli wrote:On Fri, 01 Jul 2011 21:18:45 +0200, simendsjo wrote:Needed some time to digest your answer, but it makes sense now. Thanks.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 05 2011