Resource Management... Howto?

downs default_357-line at yahoo.de
Sat Jul 7 08:45:03 PDT 2007


Deewiant wrote:
> downs wrote:
> 
>>hidden hide(Object ptr) { return cast(hidden)((cast(size_t)cast(void*)ptr)^0); } /// xor with 0 equals negation
> 
> 
> Xor with 0? That's a no-op:
> 
> version (Tango) import tango.stdc.stdio;
> 
> void main() {
> 	printf("%d\n", 0 ^ 0);
> 	printf("%d\n", 1 ^ 0);
> 	printf("%d\n", (-1) ^ 0);
> 	printf("%d\n", 2 ^ 0);
> 	printf("%d\n", (-2) ^ 0);
> 	printf("%d\n", 1000 ^ 0);
> 	printf("%d\n", (-1000) ^ 0);
> }
> 
> If you want bitwise negation, use the ~ unary operator.
> 
Stupid me.
Sorry. The reason it still worked was probably because the GC doesn't 
consider size_t something that can point somewhere, so it didn't 
consider it when searching for references.
What I meant to do was probably along the lines of ^-1.
Changed to ~. Thanks :)
  --downs


More information about the Digitalmars-d-learn mailing list