Undefined behaviours in D and C

Fawzi Mohamed fawzi at gmx.ch
Mon Apr 19 02:47:25 PDT 2010


On 19-apr-10, at 08:23, Pelle wrote:

> On 04/18/2010 02:46 PM, Walter Bright wrote:
>> Michel Fortin wrote:
>>> So you shouldn't be able to cast a value to a pointer. The reverse,
>>> casting a pointer to a value, makes sense in my opinion: you may  
>>> want
>>> to print the pointer value in a debug output of some sort. There's
>>> nothing unsafe with that so it should be allowed.
>>
>> These are allowed in safe functions.
>
> Just checking, this is allowed:
>
> @safe void crash_maybe() {
>    int* p = cast(int*)uniform(size_t.min, size_t.max);
>    *p = 14;
> }
>
> right?

no the opposite is safe (pointer -> size_t) but there is no way size_t- 
 >pointer can be safe...



More information about the Digitalmars-d mailing list