Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > function prototypes and declarations

Reply
Thread Tools

function prototypes and declarations

 
 
goldfita@signalsguru.net
Guest
Posts: n/a
 
      05-13-2006
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.

 
Reply With Quote
 
 
 
 
jacob navia
Guest
Posts: n/a
 
      05-13-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) 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]#


 
Reply With Quote
 
 
 
 
Michael Mair
Guest
Posts: n/a
 
      05-13-2006
jacob navia schrieb:
> (E-Mail Removed) 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.
 
Reply With Quote
 
=?utf-8?B?SGFyYWxkIHZhbiBExLNr?=
Guest
Posts: n/a
 
      05-13-2006
(E-Mail Removed) 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.)

 
Reply With Quote
 
goldfita@signalsguru.net
Guest
Posts: n/a
 
      05-13-2006

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.c....h?view=markup

 
Reply With Quote
 
goldfita@signalsguru.net
Guest
Posts: n/a
 
      05-13-2006

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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
function prototypes and function addresses Syren Baran C Programming 6 01-09-2008 06:34 PM
Differing function prototypes and definitions Christopher Key C Programming 3 10-03-2007 12:39 AM
extern and function prototypes quarkLore C Programming 5 04-20-2007 08:59 PM
Include files with function prototypes and variable declaration/definition Kristian Virkus C Programming 7 02-08-2007 07:22 AM
New to Python; what about #include, extern and function prototypes Bo Jacobsen Python 6 03-07-2004 02:37 PM



Advertisments