function prototypes and declarations

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

  1. 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.
    , May 13, 2006
    #1
    1. Advertising

  2. jacob navia Guest

    a écrit :
    > 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.
    >


    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. Advertising

  3. Michael Mair Guest

    jacob navia schrieb:
    > a écrit :
    >
    >> 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.
    >>

    >
    > 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


    A forward declaration is entirely sufficient for a prototype
    declaration:
    struct ast_connection;
    as only a struct ast_connection * is passed.

    >
    > 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]#


    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
    --
    E-Mail: Mine is an /at/ gmx /dot/ de address.
    Michael Mair, May 13, 2006
    #3
  4. wrote:
    > 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.


    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.)
    =?utf-8?B?SGFyYWxkIHZhbiBExLNr?=, May 13, 2006
    #4
  5. Guest

    jacob navia wrote:

    >
    > 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]#


    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
    , May 13, 2006
    #5
  6. Guest

    Harald van Dijk wrote:

    >
    > 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.)


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

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bo Jacobsen
    Replies:
    6
    Views:
    509
    David M. Cook
    Mar 7, 2004
  2. Kristian Virkus
    Replies:
    7
    Views:
    405
    Thad Smith
    Feb 8, 2007
  3. quarkLore

    extern and function prototypes

    quarkLore, Apr 19, 2007, in forum: C Programming
    Replies:
    5
    Views:
    308
  4. Christopher Key

    Differing function prototypes and definitions

    Christopher Key, Sep 28, 2007, in forum: C Programming
    Replies:
    3
    Views:
    367
    CBFalconer
    Oct 3, 2007
  5. Syren Baran

    function prototypes and function addresses

    Syren Baran, Jan 9, 2008, in forum: C Programming
    Replies:
    6
    Views:
    306
Loading...

Share This Page