home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.os.vms      DEC's VAX* line of computers & VMS.      264,096 messages   

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

   Message 263,759 of 264,096   
   =?UTF-8?Q?Arne_Vajh=C3=B8j?= to All   
   Re: Unsafe code blocks   
   14 Nov 25 20:00:25   
   
   From: arne@vajhoej.dk   
      
   On 11/14/2025 1:55 PM, Arne Vajhøj wrote:   
   > On 11/14/2025 6:14 AM, Marc Van Dyck wrote:   
   >> Simon Clubley wrote :   
   >>> For example, this is how you do an unsafe conversion in Ada:   
   >>>   
   >>> https://adaic.org/resources/add_content/docs/95style/html/   
   >>> sec_5/5-9-1.html   
      
   >> IS this the same as the [unsafe] attribute in OpenVMS Pascal ?   
   >   
   > If not the same then at least similar.   
   >   
   > It disables some checks.   
   >   
   > But it seems to do a little more.   
   >   
   > Example based on example in the docs:   
      
   > procedure hexdump(v : [unsafe] packed array [b1..b2:integer] of char);   
      
   >     hexdump(257);   
   >     hexdump(1.0);   
   >     hexdump('ABCD');   
   >     hexdump(v);   
      
   >   01 01 00 00   
   >   00 00 80 3F   
   >   41 42 43 44   
   >   01 01 00 00 00 00 80 3F 41 42 43 44   
   >   
   > Cute!   
      
   An example where it is closer to Ada:   
      
   $ type saf.pas   
   program saf(input,output);   
      
   var   
       c : char;   
      
   begin   
       c := 65;   
       writeln(c);   
   end.   
   $ pas saf   
      
       c := 65;   
   .....^   
   %PASCAL-E-OPNDASSCOM, Operands are not assignment compatible   
   at line number 7 in file DKA0:[arne]saf.pas;1   
   %PASCAL-E-ENDDIAGS, PASCAL completed with 1 diagnostic   
   $ type usaf.pas   
   program usaf(input,output);   
      
   var   
       c : [unsafe] char;   
      
   begin   
       c := 65;   
       writeln(c);   
   end.   
   $ pas usaf   
   $ link usaf   
   $ run usaf   
   A   
      
   and:   
      
   $ type saf.adb   
   with Ada.Text_IO, Ada.Integer_Text_IO;   
      
   use Ada.Text_IO, Ada.Integer_Text_IO;   
      
   procedure Saf is   
      
   c : character;   
      
   begin   
        c := 65;   
        Put(c);   
        New_Line;   
   end Saf;   
   $ gnat make saf   
   gcc -c saf.adb   
   saf.adb:10:10: expected type "Standard.Character"   
   saf.adb:10:10: found type universal integer   
   gnatmake: "saf.adb" compilation error   
   $ type usaf.adb   
   with Unchecked_Conversion;   
      
   with Ada.Text_IO, Ada.Integer_Text_IO;   
      
   use Ada.Text_IO, Ada.Integer_Text_IO;   
      
   procedure USaf is   
      
   function i2c is new Unchecked_Conversion(Source => integer, Target =>   
   character);   
      
   c : character;   
      
   begin   
        c := i2c(65);   
        Put(c);   
        New_Line;   
   end USaf;   
   $ gnat make usaf   
   gcc -c usaf.adb   
   usaf.adb:9:01: warning: types for unchecked conversion have different sizes   
   gnatbind -x usaf.ali   
   gnatlink usaf.ali   
   $ run usaf   
   A   
      
   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