0

This is not really a question, as it is already solved. But I'd like to share it here, as someone could possibly run into the same problem. And I would love to get a more profound explanation about this.

I am using Keil μvision3 to program on a C8051F340(which I think is irrelevant to this question). In my main.c I have something like:

... // accessible code
getInput();
... // not accessible after modification

and in mobile.c(ignore headers, includes, blablabla that are irrelevant):

void getInput()
{
    ...
}

And it was ok. However, after I did some modification on the code,

void getInput(struct SomeStruct *ss)
{
    ...
}

the compilation and downloading to chip finished without any errors. Although I did find a warning:

*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL

SYMBOL: GETINPUT

But I was a bit lazy and my colleagues had a lot of other warnings that made it impossible to read.(bad habit!)

Something I would like to learn:

  1. Why Keil allow such a thing to compile without error(In C it should definitely be a function not declared error)?
  2. What does REFERENCE MADE TO UNRESOLVED EXTERNAL say? It found the function with the same name but it was unable to resolve due to it having different parameters or it simply allows any function without checking its existence in the project? I couldn't find how to generate assembly code from it so I'm not perfectly sure.
Razohux
  • 79
  • 9

1 Answers1

0

In C, if you use a function that is not declared in a header file, the compiler will guess the definition (and depending on compiler flags) and issue a warning. When the compiler generates the assembler code, it no longer knows about arguments, only symbol / symbolpointers, hence the linker can not detect this (c++ can, since symbol names there include information about parameters, due to support for parameter overloading). pseduecode:

push arg1
call getInput   //the linker only sees this, does not know about stack-frame / arguments

When it comes to the GETINPUT warning, it seems like you are not including the compiled C file containing the actual symbol in the final result (Keil linker seems to put symbols in uppercase, even when the name should have been getInput, or maybe you tried to call GETINPUT aswell?)

Stian Skjelstad
  • 2,277
  • 1
  • 9
  • 19