Сложность при компиляции на c++, но не на c (gcc)

У меня проблема с многократной декларацией в C++, но не в c. Вы можете увидеть код для получения дополнительной информации.

файл main.c

#ifndef VAR
#define VAR
int var;
#endif
int main(){}

файл other.c

#ifndef VAR
#define VAR
int var;
#endif

Компилировать с помощью gcc

gcc main.c other.c
>> success

Компилировать с помощью g++

g++ main.c other.c
Output:
/tmp/ccbd0ACf.o:(.bss+0x0): multiple definition of `var'
/tmp/cc8dweC0.o:(.bss+0x0): first defined here
collect2: ld returned 1 exit status

Моя версия gcc и g++:

gcc --version
gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

g++ --version
g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
6
задан transang 8 August 2012 в 23:05
поделиться