Storage class specifier for function parameter

  • Thread starter Philipp Klaus Krause
  • Start date
P

Philipp Klaus Krause

Assume I have declared a function as follows:

void f(register int x);

does the storage clas specifier matter? I.e. does it have to be in all
declarations of the function?

Would it be ok to omit it in the definition:

int y;
void f(int x)
{
y = x;
}

What about the symmetric case:

void g(int x);

int y;
void f(register int x)
{
y = x;
}

Philipp
 
B

Ben Bacarisse

Philipp Klaus Krause said:
Assume I have declared a function as follows:

void f(register int x);

does the storage clas specifier matter? I.e. does it have to be in all
declarations of the function?

No, it is ignored except in a definition.
Would it be ok to omit it in the definition:

int y;
void f(int x)
{
y = x;
}

Yes, but the parameter would not have register storage class.
What about the symmetric case:

void g(int x);

int y;
void f(register int x)
{
y = x;
}

That's also fine and the parameter would be have storage class register.

Register is the only valid storage class for a parameter but it is
widely seen as counter-productive in modern compilers. Of course, YMMV.
 
P

Philipp Klaus Krause

Am 19.05.2010 14:49, schrieb Ben Bacarisse:
No, it is ignored except in a definition.

Do you know what the rationale for this is? I suppose requiring that all
function declarations be identical in the storage class specifiers of
the parameters wouldn't be too much of a burden on programmers, and it
would allow to e.g. let the compiler decide about parameter passing in
registers depending on the storage class specifier.

Philipp
 
B

Ben Bacarisse

Philipp Klaus Krause said:
Am 19.05.2010 14:49, schrieb Ben Bacarisse:

Do you know what the rationale for this is? I suppose requiring that all
function declarations be identical in the storage class specifiers of
the parameters wouldn't be too much of a burden on programmers, and it
would allow to e.g. let the compiler decide about parameter passing in
registers depending on the storage class specifier.

That seems unlikely. There is not much of a burden on the programmer
since there is only one possible storage class specifier and the
compiler is always allowed to decide how a parameter is passed.

You raise an interesting point, though. If the standard had insisted
that the register storage class specifier be there in all cases, then
the compiler could treat the call differently. As it is, it can only
take the keyword into account when processing the definition.
 
T

Tim Rentsch

Ben Bacarisse said:
That seems unlikely. There is not much of a burden on the programmer
since there is only one possible storage class specifier and the
compiler is always allowed to decide how a parameter is passed.

You raise an interesting point, though. If the standard had insisted
that the register storage class specifier be there in all cases, then
the compiler could treat the call differently.

A problem with doing that is added complexity in the type
space for functions (and so also for pointers-to-function).
That complexity is not trivial.
As it is, it can only
take the keyword into account when processing the definition.

Doing otherwise complicates the language, yet offers
(presumably) zero additional semantics. It's hard to
see how making such a change could produce a positive
change in costs/benefits tradeoffs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top