Static keyword in function parameter

2019-02-06 00:47发布

I've just found this function definition in some embedded code:

float round_float_to_4(static float inputval);

I'm familiar with other uses for static (global variables, functions and local variables), but this is the first time I see it as specifier for function parameter. I assume that this forces compiler to use fixed memory location for inputval instead of stack?

4条回答
Summer. ? 凉城
2楼-- · 2019-02-06 01:14

This is non standard. I'd guess the same thing as you, and I'm not surprised of such extension in compilers having an embedded target.

查看更多
贼婆χ
3楼-- · 2019-02-06 01:24

That's not valid. The only valid place where static may be used in a function parameter i'm aware of is in an array dimension

float round_float_to_4(float inputval[static 4]);

Saying that inputval will, in all calls to this function, point to memory providing at least 4 floats (this is a C99 addition, it doesn't appear in C89).

查看更多
Rolldiameter
4楼-- · 2019-02-06 01:29

Many embedded devices have a seriously limited stack, such a feature would be of great benefit in reducing the chances of stack overflow, while still giving you the opportunity for re entrant code.

Smaller chips don't have any opportunity to put variables on the stack, so all parameters are implicitly memory locations.

查看更多
孤傲高冷的网名
5楼-- · 2019-02-06 01:30

As per C standard,

The only storage-class specifier that shall occur in a parameter declaration is register.

查看更多
登录 后发表回答