On Wed, 05 Jan 2011 15:35:09 +0000, Sean Eskapp wrote:

> This is either a compiler bug, or outdated language documentation, but
> I'm having some freedom with @safe functions:
> 
>     * No casting from a pointer type to any type other than void*. * No
>     modification of pointer values.
>     * No taking the address of a local variable or function parameter.
> 
> I've attached code which does all three of these things, which compiles
> and runs.
> 
> Inline assembler was an error, as well as casting from integer to a
> pointer type, but I didn't test anything else.
> 
> I'm using dmd2.exe as my compiler.
> import std.stdio;
> 
> @safe void foo(int x)
> {
>       int a;
>       int* y = &a; // taking address of local variable char* z =
>       cast(char*)y; // casting pointer to non-pointer type *z = 4; // 
writing
>       using malformed pointer
>       
>       y = &x; // taking address of parameter, AND changing pointer 
value *y =
>       4; // changing value
>       
>       int b = cast(int)y; // casting from pointer type to type that 
isn't
>       void*
> }
> 
> void main()
> {
>       int x = 50;
>       foo(x);
> }

Hi! This forum is just a feed from Bugzilla, it is not meant for 
discussions. Please file a bug report at http://d.puremagic.com/issues/ 
instead.

Thanks,
Lars

Reply via email to