[Cfp-interest] FUNCTIONS: reduc_sum prototype

Fred J. Tydeman tydeman at tybor.com
Thu Jul 8 11:37:07 PDT 2010


C99 has a feature to tell the compiler that an array
being passed is at least as big as a constant or expression.
It is the keyword 'static' used as following:

 double reduc_sum( size_t n, const double p[static n] );

In WG14 N1494 (the latest draft of C1x), it is 6.7.6.3,
paragraph 7.

These are also valid, but provide less information:
 double reduc_sum( size_t n, const double p[n] );
 double reduc_sum( size_t n, const double * p );

It is best if the size comes before the array.
If it is done as:
 double reduc_sum( const double p[n], size_t n );
Then the 'n' in p[n] refers to the the 'n' in the
outer scope, NOT the 'n' after size_t.
---
Fred J. Tydeman        Tydeman Consulting
tydeman at tybor.com      Testing, numerics, programming
+1 (775) 358-9748      Vice-chair of PL22.11 (ANSI "C")
Sample C99+FPCE tests: http://www.tybor.com
Savers sleep well, investors eat well, spenders work forever.



More information about the Cfp-interest mailing list