The first reason is clarity. When accessing a structure instance, whose name may be anything, seeing a known prefix in the attribute helps in determining the variable's type. For example, if I see foo->sc_flags, I know that foo is an instance of some softc structure. As happens with all clarity guidelines, this is subjective.
But there is another reason, which is not more technical. Using unprefixed names pollutes the global namespace, a specially dangerous situation if the structure belongs to a public header. Why? Because of the preprocessor — that thing that should have never existed — or more specifically, the macros provided by it.
Let's see an example: consider a foo.h file that does this:
#ifndef _FOO_H_And now take the following innocent piece of code:
#define _FOO_H_
struct foo {
int locked;
};
#endif
#define locked 1Any attempt to access struct foo's locked member will fail later on because of the macro definition. Prefixing the variable mitigates this situation.
#include <foo.h>