G-Fact 6

The C standard C99 allows inline functions and variable-length-arrays. So following functions are valid in C99 compliant compilers.

Example for inline functions

filter_none

edit
close

play_arrow

link
brightness_4
code

inline int max(int a, int b)
{
  if (a > b)
    return a;
  else
    return b;
  
a = max (x, y); 
/*
  This is now equivalent to 
  if (x > y)
    a = x;
  else
    a = y;
*/

chevron_right


Example for variable length arrays



filter_none

edit
close

play_arrow

link
brightness_4
code

float read_and_process(int n)
{
    float   vals[n];
   
    for (int i = 0; i < n; i++)
        vals[i] = read_val();
    return process(vals, n);
}

chevron_right


References:
http://en.wikipedia.org/wiki/C99
http://en.wikipedia.org/wiki/Variable-length_array
http://en.wikipedia.org/wiki/Inline_function



My Personal Notes arrow_drop_up


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.