Fixing C's Biggest Mistake

areYouSureAboutThat areYouSureAboutThat at gmail.com
Wed Jan 4 04:24:33 UTC 2023


On Wednesday, 4 January 2023 at 03:42:42 UTC, areYouSureAboutThat 
wrote:
>

another example:

/* This function searches for an integer in an array.
    If it finds the integer, it returns the index in the
    array where the integer occurs. Otherwise, it returns -1
*/

//int find (int key , array_ptr <int > a : count ( len ), int len 
) // Microsoft Checked C syntax.
int find (int key , @checked int a[] : len, int len ) // 
alternative syntax using @attributes
{
     for (int i = 0; i < len; i ++)
     {
         // NOTE: a[i] is bounds checked.
         // The checking ensures that i is between 0 and len .
         if (a[i] == key )
         {
             return i;
         }
     }
     return -1;
}




More information about the Digitalmars-d mailing list