gcc warning: implicit declaration of function

This is a discussion on gcc warning: implicit declaration of function within the C Programming forums, part of the General Programming Boards category; Hi all! This is my first post in here. I disliked C for a long time, but now that I'm ...

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    6

    gcc warning: implicit declaration of function

    Hi all!

    This is my first post in here. I disliked C for a long time, but now that I'm getting the hang of it, I like to do stuff with it.

    I'm getting a 'Implicit declaration of function' warning. This happens usually when the function that is being called is not defined, nor it's prototype.

    make all:
    Code:
    gcc -ansi -pedantic -Wall -c main.c
    main.c: In function 'main':
    main.c:4: warning: implicit declaration of function 'newGameArea'
    main.c:4: warning: initialization makes pointer from integer without a cast
    gcc -ansi -pedantic -Wall -c functions.c
    gcc -ansi -pedantic -Wall -c gamearea.c
    gcc -ansi -pedantic -Wall -c heightmap.c
    gcc -ansi -pedantic -Wall -c position.c
    gcc -ansi -pedantic -Wall -c tetromino.c
    gcc -o "proj2" main.o functions.o gamearea.o heightmap.o position.o tetromino.o

    main.c includes it's own header file, main.h

    main.h includes every other header file:
    Code:
    #pragma once
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include "constants.h"
    #include "functions.h"
    #include "position.h"
    #include "tetromino.h"
    #include "heightmap.h"
    #include "gamearea.h"
    main.c (line 4):
    Code:
    GameArea *gameArea = newGameArea();
    The function that is missing, is prototyped on gamearea.h:
    Code:
    GameArea* newGameArea();

    I'm really clueless on what is going on. I'd appreciate some help Thanks!

    anatoly

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,344
    Do other header files include gamearea.h ?

    Does gamearea.h have #ifndef FILE_INCLUDED type guards in it?

    Did you copy/paste those guards from another file?

    You can generally do without #pragma once, as it is not entirely portable.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I'm old school, so I never do that kind of thing. On gamearea.h, your prototype should explicitly have parameter of (void):

    GameArea* gameArea(void);


    Then:
    GameArea *gameArea;
    //when you're ready to call the function:
    gameArea = newGameArea();

    I'm not at all familiar with your compiler, but that's how I'd do it.

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    6
    Hey!

    Thanks for the quick replies.

    I (probably) accidentally solved it. Not sure what I did. I just closed the IDE in rage, and when I came back and did the makeclean-makeall thing, everything compiled without any errors or warnings.

    The target computers (that are going to compile this) are all 'equipped' with the GNU C Compiler, and currently has full support for the "#pragma once" directive. If the need arrises, I'll replace it with "#ifndef"s. I thought the GCC was one of the most popular compilers out there though, but I guess there are some that won't accept "#pragma"

    I'll clean up the whole code with your suggestions (use void instead of nothing, use ifndef instead of pragma, and split variable creation from giving it a value) - since I (try to) follow the C programming standards - if I have the time (I need to finish this within 25h 30m - caffeine levels increasing)

    Thanks again

    - anatoly

  5. #5
    Registered User
    Join Date
    Apr 2006
    Posts
    2,012
    Quote Originally Posted by anatoly View Post
    I (probably) accidentally solved it. Not sure what I did. I just closed the IDE in rage, and when I came back and did the makeclean-makeall thing, everything compiled without any errors or warnings.
    This sounds like the make file does not contain information about header dependencies. Make can automatically deduce which .c files are needed to generate a .o file. But it cannot read a .c file to figure out which headers are needed. Therefore, unless you have a script that automatically updates the make file when you add headers, when ever you change a header you need to manually recompile all the .c files that use it. Some IDEs have this problem, others are smarter. I recall DevC++ had this issue.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File Server Help
    By lautarox in forum C Programming
    Replies: 146
    Last Post: 09-24-2008, 06:32 PM
  2. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  3. Replies: 10
    Last Post: 07-10-2008, 03:45 PM
  4. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 02:49 PM
  5. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21