rsp rsp - 1 month ago 7
C Question

Can we place "typedef" specifier anywhere in the declaration?

The syntax of

typedef
specifier :

typedef <existing_name> <alias_name>


for example:

typedef long unsigned int Int;


It's working fine.

But, If I place
typedef
anywhere in the declaration, Like this:

long unsigned typedef int Int;


Then, It's also working fine.

Why? Can we place
typedef
anywhere in the declaration?

Answer Source

First of all, quoting from §6.11.5, "Future language directions"

1 The placement of a storage-class specifier other than at the beginning of the declaration specifiers in a declaration is an obsolescent feature.

So, do not rely on this, as it may be removed in the future.


That said, to understand why this works, check the C11 standard, chapter §6.7.2:

[...] the type specifiers may occur in any order, possibly intermixed with the other declaration specifiers.

From §6.7.1, we know typedef is a storage-class specifier (one particular sort of a declaration specifier), so it can be placed after (or before) the type specifier (i.e., can be intermixed). It does not change anything.