home bbs files messages ]

Just a sample of the Echomail archive

COMPOSVM:

<< oldest | < older | list | newer > | newest >> ]

 Message 263,775 of 264,034 
 =?UTF-8?Q?Arne_Vajh=C3=B8j?= to Simon Clubley 
 Re: Unsafe code blocks 
 17 Nov 25 14:22:34 
 
From: arne@vajhoej.dk

On 11/17/2025 1:56 PM, Simon Clubley wrote:
> On 2025-11-14, Arne Vajhøj  wrote:
> These two examples _appear_ to do different things.

They both stuff an integer into a char aka circumvent
strict typing.

They do it differently.

>> $ type usaf.pas

>> var
>>      c : [unsafe] char;

>>      c := 65;

> This one appears to say that _all_ writes to the variable "c" are not
> checked.

Yes.

>> $ type usaf.adb
>> with Unchecked_Conversion;

>> function i2c is new Unchecked_Conversion(Source => integer, Target =>
>> character);
>>
>> c : character;

>>       c := i2c(65);
>>       Put(c);

> However, with this one, you get to choose which writes to "c" are checked
> by Ada.

Yes.

The Pascal example is by variable. The Ada example is by assignment.

More granular control in Ada.

> Have I understood the Pascal code correctly or is there something
> I am missing ?

No.

Only thing is that [unsafe] can be used for other things - see
the hexdump example.

Arne

--- SoupGate-Win32 v1.05
 * Origin: you cannot sedate... all the things you hate (1:229/2)

<< oldest | < older | list | newer > | newest >> ]


(c) 1994,  bbs@darkrealms.ca