C
Chris Croughton
Does a translation unit have to have at least one externally visible
declaration or function definition to be valid? As I read the standard,
it doesn't: it must have at least one declaration or function definition,
but they can be static, extern or even a typedef.
6.9 External definitions
1 translation-unit:
external-declaration
translation-unit external-declaration
external-declaration:
function-definition
declaration
6.9.1 Function definitions
1 function-definition:
declaration-specifiers declarator declaration-list(opt)
compound-statement
6.7 Declarations
1 declaration:
declaration-specifiers init-declarator-listopt ;
declaration-specifiers:
storage-class-specifier declaration-specifiers(opt)
type-specifier declaration-specifiers(opt)
type-qualifier declaration-specifiers(opt)
function-specifier declaration-specifiers(opt)
6.7.1 Storage-class specifiers
1 storage-class-specifier:
typedef
extern
static
auto
register
So as I read the standard a translation unit consisting of only
typedef int fred;
would be valid, and a conforming compiler shouldn't complain about it.
Is this correct, or have I missed something?
Chris C
declaration or function definition to be valid? As I read the standard,
it doesn't: it must have at least one declaration or function definition,
but they can be static, extern or even a typedef.
6.9 External definitions
1 translation-unit:
external-declaration
translation-unit external-declaration
external-declaration:
function-definition
declaration
6.9.1 Function definitions
1 function-definition:
declaration-specifiers declarator declaration-list(opt)
compound-statement
6.7 Declarations
1 declaration:
declaration-specifiers init-declarator-listopt ;
declaration-specifiers:
storage-class-specifier declaration-specifiers(opt)
type-specifier declaration-specifiers(opt)
type-qualifier declaration-specifiers(opt)
function-specifier declaration-specifiers(opt)
6.7.1 Storage-class specifiers
1 storage-class-specifier:
typedef
extern
static
auto
register
So as I read the standard a translation unit consisting of only
typedef int fred;
would be valid, and a conforming compiler shouldn't complain about it.
Is this correct, or have I missed something?
Chris C