Please note: We are aware of an issue affecting replies on the Arm Community forums, which may not be loading as expected.

We apologize for any inconvenience and appreciate your patience while we investigate and work to resolve the issue.

Thank you for your understanding.


This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

EWARM linker function redefinition problem

In one 'c' file I define the following function:

void fnTemp(int jj, int kk);

void fnTemp(int jj, int kk)

{

     ...do some stuff...

}

In a different 'c' file I have the following:

extern void fnTemp(int jj);

void fnTryIt(void)

{

    fnTemp(3);

}

This will link without any errors. How do I get the linker to tell me that I have two definitions for fnTemp()?

I know that I could put the declaration for fnTemp() in a .h file and include the .h file in both .c files which will then trigger a compiler error. But I have an instance where that can cause other issues.

Thank you for any help.

Parents
  • The C compiler and the linker cannot know that you call the function with wrong parameters. That's the nature of C.

    You might switch to C++ (even if you do not use the C++ features). C++ "decorates" the functions, so it will have a function __vfnTempII in one file and you call __vfnTempI in the other. And the linker will complain.

Reply
  • The C compiler and the linker cannot know that you call the function with wrong parameters. That's the nature of C.

    You might switch to C++ (even if you do not use the C++ features). C++ "decorates" the functions, so it will have a function __vfnTempII in one file and you call __vfnTempI in the other. And the linker will complain.

Children
No data