?
Solved

compiler warning.

Posted on 2003-03-13
8
Medium Priority
?
860 Views
Last Modified: 2010-04-15
Can you please give me some suggestion on how to fix these warning.
When i compile my program, it gives me these warning:

"main.c", line 21: warning: implicit function declaration: pipe
"main.c", line 24: warning: implicit function declaration: fork
"main.c", line 29: function designator is not of function type
"main.c", line 30: function designator is not of function type
"main.c", line 31: warning: implicit function declaration: client
"main.c", line 32: warning: implicit function declaration: wait
"main.c", line 33: function designator is not of function type
"main.c", line 34: function designator is not of function type
"main.c", line 39: function designator is not of function type
"main.c", line 40: function designator is not of function type
"main.c", line 41: warning: implicit function declaration: server
"main.c", line 42: function designator is not of function type
"main.c", line 43: function designator is not of function type
"main.c", line 47: cannot recover from previous errors
cc: acomp failed for main.c
--------------------------------------------------------------------------
Here is my main program:

#include <stdio.h>
#include <stdlib.h>
     
int main()
{
     
  int close;
  int childpid, pipe1[2], pipe2[2], stat;
  printf("\n\nEnter info or ctrl-c to end\n\n");
  while(1)
  {
    if ( pipe( pipe1 ) < 0 ||  pipe( pipe2 ) < 0 )  /*create pipes*/
      perror( "can't create pipes");
 
    if ( (childpid = fork() ) < 0 )
      perror( "can't fork" );

    if (childpid > 0 )    /* parent */
    {
      close( pipe1[0] );
      close( pipe2[1] );
      client( pipe2[0], pipe1[1] );
      wait( &stat );       /* wait for child */
      close( pipe1[1] );
      close( pipe2[0] );
      /*exit( EXIT_SUCCESS ); */
    }
    else                   /* child */
    {
      close( pipe1[1] );
      close( pipe2[0] );
      server( pipe1[0], pipe2[1] );
      close( pipe1[0] );
      close( pipe2[1] );
      /*exit( EXIT_SUCCESS );*/
    }
  }//end while
}//end main
0
Comment
Question by:kavvang
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 8

Expert Comment

by:mnashadka
ID: 8132681
For the functions that are outlined, you need to include the header files that define them.  For instance, close is often in unistd.h, wait is often in sys/wait.h.  Find these out, and add those header files.  Good luck.
0
 
LVL 5

Expert Comment

by:ecw
ID: 8132837
#include <unistd.h>

don't declare close as var in main, don't declare stat as var, it could confuse some people.
0
 
LVL 8

Expert Comment

by:ssnkumar
ID: 8133772
Adding the following three lines will clear those warnings:
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 30

Expert Comment

by:Mayank S
ID: 8133816
You've declared 'close' as an integer variable and are also using the close () library function - that is where the ambiguity is. Also, please include the necessary header files as others have already told you.

Mayank.
0
 

Author Comment

by:kavvang
ID: 8137721
ssnkumar, after i include those files i still have the warning as below:
---------------------------------------------------------
"main.c", line 24: warning: implicit function declaration: client
"main.c", line 34: warning: implicit function declaration: server
Undefined                       first referenced
 symbol                             in file
server                              main.o
client                              main.o
ld: fatal: Symbol referencing errors. No output written to m
-----------------------------------------------------
what can i do to fixed these warning.
0
 

Author Comment

by:kavvang
ID: 8137753
ssnkumar, after i include those files i still have the warning as below:
---------------------------------------------------------
"main.c", line 24: warning: implicit function declaration: client
"main.c", line 34: warning: implicit function declaration: server
Undefined                       first referenced
 symbol                             in file
server                              main.o
client                              main.o
ld: fatal: Symbol referencing errors. No output written to m
-----------------------------------------------------
what can i do to fixed these warning.
0
 
LVL 5

Accepted Solution

by:
ecw earned 150 total points
ID: 8140771
write client and server functions (before main) ie

or declare client and server functions and link it with the library or object containing the functions.
For example if client lives in client.o, and server lives in server.o, before (or even at the start of) main
  extern void client(int, int);
  extern void server(int, int);
and compile with
  cc -c main.c
use cc to link with
  cc -o myprog main.o client.o server.o
If you have a header files containing the extern definitions of client and server, #include those and you won't need the explicit externs in main.c
0
 
LVL 8

Expert Comment

by:ssnkumar
ID: 8149450
>after i include those files i still have the warning as below:

Where is the definition for client() and server() functions. Maybe you have defined them in another file (say in the file defs.c).
Then your command will look like this:
cc main.c defs.c

Also, add the following 2 lines before main:
void client(int, int);
void server(int, int);

If the definitions are in a .h file, then #include them in the file containing the main() function.

Hope this will solve your problem.....

-Narendra
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question