function prototypes and declarations

Discussion in 'C Programming' started by goldfita, May 13, 2006.

  1. goldfita

    goldfita Guest

    I have the following two prototypes in separate source files. Both
    programs compile and work correctly.

    (1) void general_foo(void (*foo)(), int opt, ...);
    (2) static int __wait_get_general(struct ast_connection *conn, int
    (*_get)(), int opt, ...);

    When I compile the second source file, gcc says
    ast_man.c:47: warning: function declaration isn't a prototype

    There are no warnings from compiliation of the first file. I don't
    understand what the problem is. Even more confusing, I don't
    understand what's different. I'm guessing it has something to do with
    the function pointers since all the rest of my prototypes were accepted
    by the compiler. The function pointers don't declare arguments because
    the number and types are unknown until runtime.
     
    goldfita, May 13, 2006
    #1
    1. Advertisements

  2. goldfita

    jacob navia Guest

    a écrit :
    My gcc has no problems with that... Maybe you did not define the
    structure ast_connection?

    [gateway]# cat tg1.c
    struct ast_connection
    { int a;}; // Note that I define the struct ast_connection

    static int __wait_get_general(struct ast_connection *conn, int
    (*_get)(), int opt, ...);

    [gateway]# gcc -c tg1.c
    [gateway]# ls -l tg1.o
    -rw-r--r-- 1 root root 702 May 13 06:51 tg1.o
    [gateway]#
     
    jacob navia, May 13, 2006
    #2
    1. Advertisements

  3. goldfita

    Michael Mair Guest

    A forward declaration is entirely sufficient for a prototype
    declaration:
    struct ast_connection;
    as only a struct ast_connection * is passed.
    The same holds even for
    gcc -std=c89 -pedantic -Wall -O prot.c -c
    and
    gcc -std=c99 -pedantic -Wall -O prot.c -c
    which only warns about the static declaration not
    followed by a use.

    Cheers
    Michael
     
    Michael Mair, May 13, 2006
    #3
  4. goldfita

    Guest Guest

    Well, the declarations are valid (ignoring the reserved identifier
    issue), but any compiler may give warnings for any valid code; it
    doesn't mean there's an actual problem. if you have a reason to use
    non-prototyped function pointers, either tell your compiler to not
    complain about it, or ignore the warnings. (In gcc's case, this warning
    isn't enabled by default, and both generate the warning with
    -Wstrict-prototypes for me, so I'm guessing you simply used different
    compiler options for file 1 and file 2.)
     
    Guest, May 13, 2006
    #4
  5. goldfita

    goldfita Guest

    I compiled with Wall and Wstrict-prototypes (gcc 3.3.6). The struct is
    defined.

    http://svn.sourceforge.net/viewcvs.cgi/pyastman/ast_man.h?view=markup
     
    goldfita, May 13, 2006
    #5
  6. goldfita

    goldfita Guest

    Yes! That's it. Ok, so there's nothing wrong with it. That's all I
    wanted to hear.
     
    goldfita, May 13, 2006
    #6
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.