Note that int x; not (simple) declaration , definition . Thus, an error occurred after the ODR is violated, i.e. Only one definition per translation unit is allowed.
A variable declaration can be written as:
// a declaration with an extern storage class specifier and without an initializer extern int x; extern int x;
Meanwhile, int add(int, int); - This announcement (functions) for sure. Several declarations in one translation unit are excellent, ODR is not violated.
source share