M.S Chaudhari M.S Chaudhari - 1 year ago 106
C Question

Issue with auto variable

I know about storage classes in C. I am wondering about the


In the following expression,

auto int i = 0;

is the storage class specifier,
is the data type.

But if we write:

int auto i = 0;

What happens? Is
behaving as the data type?

Answer Source

The ordering of storage class specifiers (extern, static, register, auto, typedef) with respect to type specifiers (int, double, char, etc.) does not matter. Both are valid and declare the same object.

It is, however, considered a good practice to conform to a certain order. The list of specifiers which precedes the declarator consists of distinctive groups of keywords which are best used in the following order:

  • Storage class specifiers, if any: static, extern, auto, register, typedef;
  • Type qualifiers, if any: const, volatile, restrict;
  • Type modifiers, if any: signed, unsigned, short, long;
  • The type specifier: int, double, char, etc.

Following that rule would lead to more readable declarations like this:

static const volatile unsigned long int a;

Instead of (an extreme example):

unsigned volatile int static const long a;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download