Search code examples
cgccgcc-warning

Strange GCC warning on storage class and type


I have a header file that looks like

header.h

int TOS;

This file is being included by just one code file

code.c

#include "header.h"
TOS=0;

When compiling code.c GCC issues a warning

code.c:3:1: warning: data definition has no type or storage class [enabled by default] code.c:3:1: warning: type defaults to ‘int’ in declaration of ‘TOS’ [enabled by default]

I fail to understand the cause of this warning. Isn't it equivalent to declaring and defining TOS in code.c? i.e.

code.c

int TOS;
TOS=0;

Solution

  • It is because you define TOS in the global scope, which need you to define the type of TOS(it is an declaration), if no type was given, by default it is int.

    This will cause an conflicting type error,

    char x;
    x = 0;