From: clubley@remove_me.eisner.decus.org-Earth.UFP   
      
   On 2025-11-12, Arne Vajhøj wrote:   
   >   
   > using System;   
   >   
   > namespace AAX   
   > {   
   > public class Program   
   > {   
   > public static void Main(string[] args)   
   > {   
   > int[] a = new int[4];   
   > unsafe   
   > {   
   > fixed (int* hack = &a[0])   
   > {   
   > for(int i = 0; i < 5; i++)   
   > {   
   > hack[i] = i;   
   > Console.WriteLine(i);   
   > }   
   > }   
   > }   
   > }   
   > }   
   > }   
   >   
   > 0   
   > 1   
   > 2   
   > 3   
   > 4   
   >   
   > unsafe { } clearly reveal that something fishy is going on.   
   >   
      
   The unsafe keyword is a hack implemented in languages that have not been   
   designed correctly. The Ada approach, of disabling checks on a specific   
   reference to a variable instead of disabling checks within a whole block   
   of code, is far superior.   
      
   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   
      
   Also note the availability of the 'Valid attribute to make sure that what   
   is in the variable after the unsafe conversion is actually a valid value.   
      
   Likewise, 'Unchecked_Access is a way that Ada allows you to do unsafe things   
   with pointers:   
      
   https://www.adaic.org/resources/add_content/docs/95style/html/sec_5/5-9-3.html   
      
   Simon.   
      
   --   
   Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP   
   Walking destinations on a map are further away than they appear.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|