• Re: C function prototype was Python (was Re: I did not inhale)

    From David Brown@21:1/5 to James Harris on Sun Aug 18 19:54:19 2024
    On 18/08/2024 18:36, James Harris wrote:
    On 18/08/2024 15:55, David Brown wrote:

    ...

    What does "static" mean inside square brackets in a C function prototype?

    I know there's a better newsgroup for it but, since you brought it up
    and it does also fit here, I should say that I had no idea that a C
    program could have square brackets in a function prototype and I cannot
    think of ever seeing such a thing.


    I didn't mean we should go into detail about such features - it's just
    an example of a feature of the core language of C that most C
    programmers don't know about, and the lack of that knowledge does not
    prevent them being able to write code in C. It is not a useful feature.

    If you write "int foo(int xs[static 10]);", then it is undefined
    behaviour to call "foo" with an argument that does not point to an array
    of at least 10 elements (and it is therefore also UB to call it with a
    null pointer). In theory, this could give a few more opportunities for
    static error checking or optimisation. In practice, compilers will give
    you exactly the same checks and optimisations without the "static".

    I presume you do mean C and not some sort of compiler extension.

    Yes.


    As for static, IIRC labelling as "static" any external name (i.e. one
    not in a function) would make it private to the CU and not visible
    outside but that is just a guess.

    It is also used for local variables in functions - these then have the
    same scope as another local variable in the same place, but have
    program-static lifetime.

    But the use in array parameters is not related to either of these, and
    is IMHO a potentially confusing and basically useless additional use of
    the keyword.

    (If anyone knows of it being useful in this context, please say so!)


    Or perhaps you meant a static formal parameter. Again, not something
    I've ever come across and would be curious as to what it meant.

    Would you care to say more about what you had in mind?



    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)