This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: global variab­le and global function na­mes ar e the same - result­ is segfault


On 14 October 2011 20:08,  <tadam@pisem.net> wrote:
> Hi all,
> Is there any "magic" gcc option which would prevent linker&nbsp;successfully&nbsp;link the following program:
> ------------------------ file test1.c ---------------------------
> int foo;
> ------------------------ file test2.c ---------------------------
> int &nbsp;foo(int a);
> int main (int argc, char argv[]){&nbsp; &nbsp;foo(0);&nbsp; &nbsp;return 0;}
> Compilation and linking with&nbsp;gcc test1.c test2.c -o test
> and run./test
> gives segmentation fault on my Ubuntu x86 machine.
> What I see is that the linker successfully links foo global variable as a global function, which is a nonsense to me.Please advice.
> Thank you,--Adel

This is a fundamental feature of the C language.  Using C++ will
"solve" your problem, because the linker would see different symbol
names for a variable "foo" and  function "int foo(int)"


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]