Re: Why not auto?



On Tue, 10 May 2005 14:04:05 +0100, Lawrence Kirby
<lknews@xxxxxxxxxxxxxxx> wrote:

> On Mon, 09 May 2005 20:04:38 +0100, Chris Croughton wrote:
>
>> On Mon, 09 May 2005 13:29:27 GMT, Richard Bos
>> <rlb@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>>
>>> No storage class specifier except register can be used for function
>>> parameters declarations. Not auto, but not static, extern or typedef
>>> either. The reason, I suppose, is that declaring a function parameter to
>>> be extern or auto makes even less sense than declaring it register.
>>> Consider: whatever would it mean, a static function parameter?
>>
>> Treat it as a suggestion (like register) that the value should be held
>> in 'static' memory rather than stack, for optimisation? For instance,
>> on a system where stack space is limited declaring all local variables
>> including parameters as static (knowing that the function wouldn't be
>> reentrant) might be useful.
>
> This really boils down to a promise that the function won't be called
> recursively, or concurrently from a signal handler. This would make more
> sense as a attribute for the function as a whole rather than for
> particular parameters.

It might be needed only for certain parameters (long doubles and large
structs for instance) with others being in registers:

int doSomething(register int action, static struct data);

I agree that a function attribute would also be useful. It can't be yet
another use of static, though, how about restrict? That has a similar
meaning (promise the compiler that you aren't going to do something
'clever' and non-optimisable):

restrict int wellBehavedFunction(int x, double y);

(Some compilers used for embedded systems have had their own extensions
to do similar things...)

Chris C
.



Relevant Pages

  • Re: Why not auto?
    ... No storage class specifier except register can be used for function ... Not auto, but not static, extern or typedef ... The reason, I suppose, is that declaring a function parameter to ... be extern or auto makes even less sense than declaring it register. ...
    (comp.lang.c)
  • Re: Why not auto?
    ... The reason, I suppose, is that declaring a function parameter to be extern or auto makes even less sense than declaring it register. ... meaning (promise the compiler that you aren't going to do something ...
    (comp.lang.c)
  • Re: Why not auto?
    ... >> be extern or auto makes even less sense than declaring it register. ...
    (comp.lang.c)
  • Re: i want to use functions that dont return int, without declaring them
    ... >> This is undefined behavior, ... > handle parameter passing. ... >> into the floating point register, ...
    (comp.lang.c)
  • Re: Why not auto?
    ... > be extern or auto makes even less sense than declaring it register. ...
    (comp.lang.c)