“multiple definition of value” when compiling C program with uninitialized global in g++ but not gcc

前端 未结 2 1946
粉色の甜心
粉色の甜心 2021-01-06 07:16

I\'m trying to understand the usage of extern and global variable declaration in header files so I came up with the following test program written in C.

The main.c f

2条回答
  •  心在旅途
    2021-01-06 07:32

    C and C++ are different languages. Case in point, the above program is a valid C program but in ill-formed C++ program. You have violated C++'s one definition rule. There is no corresponding rule in C.

    When compiling with gcc, you are compiling the above text as a C program. When compiling with g++, you are compiling the above text as a C++ program.

提交回复
热议问题