docs/definition: !object

ketmar ketmar at ketmar.no-ip.org
Thu Mar 8 06:08:10 UTC 2018


Nick Sabalausky (Abscissa) wrote:

> (Or does &someObject return the address of the *reference* to the object 
> rather than the address of the object?...You can see just how often I do 
> OO in D ;) )

exactly. if you want to convert object to a pointer safely, do this:

	MyObject o;
	void* p = *cast(void**)&o;

this magic construct guarantees that you won't hit `opCast()` in 
`MyObject` (yes, somebody *can* write weird `opCast` for `void*`! ;-).

doing just `&o` gives you the address of a variable (on a stack, or in a 
tls), which is, obviously, never `null`. ;-)


More information about the Digitalmars-d-learn mailing list