473,378 Members | 1,578 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

function prototypes and declarations

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 '06 #1
5 7288
go******@signalsguru.net 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]#
May 13 '06 #2
jacob navia schrieb:
go******@signalsguru.net 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.
May 13 '06 #3
go******@signalsguru.net 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.)

May 13 '06 #4

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

May 13 '06 #5

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 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: johny smith | last post by:
Can someone please explain to me the difference between these two: function1( const int a) function2( int const a) Both seemed to compile, but what is the difference between the two above....
21
by: Rob Somers | last post by:
Hey people, I read a good thread on here regarding the reason why we use function prototypes, and it answered most of my questions, but I wanted to double check on a couple of things, as I am...
6
by: Daniel Nichols | last post by:
I've noticed that in a C module (.c, .h file combination) that if you create a function's definition before it is used in other functions than a declaration is not necessary. I believe if the...
9
by: Grumble | last post by:
Hello everyone, I've come across some strange code. Here it is, stripped down: int main(void) { int *foo; int *bar(); foo = bar(0); return 0;
5
by: Kobu | last post by:
Does anyone know how old style function definitions differ in "behaviour" to new style function definitions? I heard the old style function definitions caused integeral promotion and floating...
12
by: TTroy | last post by:
For function definitions (not declarations/prototypes), is it necessary to put void in the emptry braces if the function is to receive no parameters? Does this turn any error checking off or cause...
73
by: Steph Barklay | last post by:
Hi, I'm currently taking a data structures course in C, and my teacher said that function prototypes are not allowed in any of our code. He also said that no professional programmers use function...
29
by: Ravishankar S | last post by:
Dear C Experts, While prepating a content for a C course,I made section on function prototypes. Could you kindly provide me your comments on its correctness. Thank you ! Q12: What is the...
28
by: Why Tea | last post by:
I seem to remember that in ANSI C, all static functions should have their function prototypes listed at the beginning of the file for better consistency (or something like that). I googled and...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.