warning: implicit declaration of function

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

 

  I have an odd problem with my current project in that I get the above error when I compile.

 

I have a number of different files that are included into a main.h which is then included into main.c where this error is occurring but I can call other functions from the same .c file without any problem. The code itself does actually work and the function complained about is called correctly.

 

I appreciate this is vague without code, and I can happily post code, but there's a lot of it and I'm not at all convinced that if I pare it down to an example that I'll get the same error.

 

code files:

  maps.h  >> includes spike.h, isometric-engine.h

  tiles.h  >> includes spike.h, isometric-engine.h

  spike.h

  spike.c

  isometric-engine.h  >> includes spike.h

  isometric-engine.c >> includes isometric-engine.h

  main.h  >> includes spike.h, isometric-engine.h, tiles.h, maps.h

  main.c. >> includes main.h

 

void set_viewport(int x, int y); is prototyped in isometric-engine.h, defined in isometric-engine.c and called in main.c and is the function that is causing the warning. draw_map is defined and called in exactly the same places but doesn't cause a warning!?

 

-Mike

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Check each of your functions in .h and .c to be sure each is defined the same way.

Like you changed the .c file and forgot to update the .h file after you changed "void function()" to "int function()"...

 

Just a wild guess!

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

I get that sort of error when there is a spelling difference between the header and the code file. Often, its a difference in case or an underscore that is in one but not the other. You might also check that parameters have exactly the same type declaration (in header and code file) though I think that throws a different error.

 

West Coast Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It's definitely spelt the same in all 3 places!

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A couple of times, I have had that sort of problem with no obvious difference between the spelling at the calling point, at the declaration, and at the definition.

 

It was usually solvable by copying ONE of them, then select and paste over the other two. My guess is that, somehow, a non-printing character got inserted into one. Another strategy, when I could not guess which was bad was to rewrite the declaration from scratch, being careful about keyboard entry (I am pretty bad at hitting multiple keys and such). Then I copy/paste that new declaration into each other place, editing the arguments, as needed. Then, erase or comment out the originals.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ka7ehk wrote:
It was usually solvable by copying ONE of them, then select and paste over the other two.

 

just tried that, recompiled it without the function, added it back in by copying-and-pasting the definition, recompiled and same warning reappeared. It's really strange!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ka7ehk wrote:
somehow, a non-printing character got inserted into one

 

another possibility is the guard post (ifndef xxx) in the header has been duplicated in a prior header and the contents of the second header is being ignored.  ( a copy /paste from template file error) ask me how I know this one!

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ki0bk wrote:

another possibility is the guard post (ifndef xxx) in the header has been duplicated in a prior header and the contents of the second header is being ignored. 

 

 

Ha! Got it - no duplication but one of my .h files (and ironically one I'd missed in my list above because it sits above a bunch of folders in the file list because of its name) didn't have a guard in it! Extra odd because it doesn't include any files itself or redefine anything that is already declared!

 

compiles without complaint. Thank you for your help!