Page 106 - C-Language
P. 106

//Causes an error on the line below...
         */


        One solution is to use C99 style comments:


         // max(): Finds the largest integer in an array and returns it.
         // If the array length is less than 1, the result is undefined.
         // arr: The array of integers to search.
         // num: The number of integers in arr.
         int max(int arr[], int num)
         {
             int max = arr[0];
             for (int i = 0; i < num; i++)
                 if (arr[i] > max)
                     max = arr[i];
             return max;
         }


        Now the entire block can be commented out easily:


         /*

         // max(): Finds the largest integer in an array and returns it.
         // If the array length is less than 1, the result is undefined.
         // arr: The array of integers to search.
         // num: The number of integers in arr.
         int max(int arr[], int num)
         {
             int max = arr[0];
             for (int i = 0; i < num; i++)
                 if (arr[i] > max)
                     max = arr[i];
             return max;
         }

         */


        Another solution is to avoid disabling code using comment syntax, using #ifdef or #ifndef
        preprocessor directives instead. These directives do nest, leaving you free to comment your code
        in the style you prefer.


         #define DISABLE_MAX /* Remove or comment this line to enable max() code block */

         #ifdef DISABLE_MAX
         /*
          * max(): Finds the largest integer in an array and returns it.
          * If the array length is less than 1, the result is undefined.
          * arr: The array of integers to search.
          * num: The number of integers in arr.
          */
         int max(int arr[], int num)
         {
             int max = arr[0];
             for (int i = 0; i < num; i++)
                 if (arr[i] > max)
                     max = arr[i];


        https://riptutorial.com/                                                                               82
   101   102   103   104   105   106   107   108   109   110   111