I am currently "playing" around in a quite big and old codebase and, quite unfortunately, it has no fixed style attached to it. So it was just made to work but that also means that quite a lot of it can be described as spaghetti code.
I came across something that I do not fully undersand. Compiler is from ARM/KEIL and it is for an embedded system.
first file:
fileA.c
// prototype
int GetSomething( int a );
// implementation
int GetSomething( int a) {
DoSomething();
}
second file:
fileB.c
// prototype
int GetSomething( int a )
void main ( void ) {
GetSomething(10);
}
There are no headers which have a declaration for the function GetSomething but the function is still correctly linked. Originally, there are a extern keyword in the second file in the declaration of GetSomething, but with or without that results in the same binary. The code has been tests and works.
I've seen Stackoverflow Question but that doesn't seem to cover my case as it seems to have nothing to do with the extern keyword.
I hope that somebody can explain that to me or tell me what is going on. Thanks.
externis default.#includethe content of the file literally is replacing#include. You can have no headers, just paste the same stuff around. Btw, you may want to start by refactoring your codebase, so the same stuff is in headers.voidfor return types or empty argument lists. When prototypes were added, it was easier to copy the declaration into the file than to create a header that did the job properly (or get someone on another part of the team responsible for the code that provided the service to create the header), so that's what people under time pressure did. And it becomes a major PITA when the function signature changes. Use headers!