Liste des Groupes | Revenir à cl c |
On 11/05/2025 10:21, Muttley@dastardlyhq.com wrote:...On Sat, 10 May 2025 14:29:50 -0700
Tim Rentsch <tr.17687@z991.linuxsc.com> gabbled:
The use I'm talking about here may be illustrated as follows:>
>
double
average( double values[ static 10 ] ){
double total = 0;
for( int i = 0; i < 10; i++ ){
total += values[i];
}
return total / 10;
}
>
What word would you suggest to be used in place of 'static'
there?
If I knew what the hell it was supposed to do I'd tell you.
>
Using "static" inside array parameters is, IME, extremely rare. It was
added in C99, and tells the compiler that whenever "average" is called,
the "values" parameter points to an array of at least 10 doubles. It
does not affect the signature of the function or compatibility with any
other declarations, and is AFAIK rarely checked by compilers.
In an example like the one above, it is completely useless for
compilation - it tells the compiler nothing that it does not already
know. An optimising compiler will see that you are accessing values[0]
to values[9], and if it can get better results through vectorising,
prefetching, etc., then it will do so. (You can argue that the "static
10" is still useful as an indicator to human readers, but I am not
convinced of that.)
Les messages affichés proviennent d'usenet.