5

Does a function have any storage class in C Language?

1

2 Answers 2

3

The answer is no. According to http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf (draft of C99) and http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf (draft of C11):

6.2.4 Storage durations of objects

1 An object has a storage duration that determines its lifetime.

Functions aren't objects, so they have no storage.

6.2.2 Linkages of identifiers

3 If the declaration of a file scope identifier for an object or a function contains the storage-class specifier static, the identifier has internal linkage.

This says that static applied to a function affects its linkage (there is no storage it could apply to).

Sign up to request clarification or add additional context in comments.

Comments

3

The C standard doesn't formally define the meaning of storage class.

It does define what a "storage-class specifier" is --- it is one of the keywords typedef, extern, static, _Thread_local, auto and register.

Functions can be declared with storage-class specifiers extern or static.

The standard does mention objects having "storage class" in several places, for example

If the array object has register storage class, the behavior is undefined

but it is never defined what a storage class of an object is. One could reasonably assume that this is the storage-class specifier keyword that appears in one of the declarations, but it remains unclear what happens if some declarations of the same object have a storage-class specifier and others don't. It is also never defined what is the storage class of an object that doesn't have any declaration with a storage-class specifier.

It seems that one should avoid talking about storage classes of objects or functions altogether, and instead use related notions of storage duration and linkage which are precisely defined by the standard. When necessary, use phrases like "storage-class specifier X appears in a declaration", but not "object/function has storage class X".

1 Comment

My interpretation: "has register storage class" means "was declared with the register storage class specifier", the other instances of "having storage class" in the standard are sloppy wording that should be fixed up to not mention "storage class", but the intent is clear in each case

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.