Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 915
  • Last Modified:

compiler warning.

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
kavvang
Asked:
kavvang
  • 2
  • 2
  • 2
  • +2
1 Solution
 
mnashadkaCommented:
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
 
ecwCommented:
#include <unistd.h>

don't declare close as var in main, don't declare stat as var, it could confuse some people.
0
 
ssnkumarCommented:
Adding the following three lines will clear those warnings:
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>
0
Technology Partners: 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!

 
Mayank SAssociate Director - Product EngineeringCommented:
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
 
kavvangAuthor Commented:
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
 
kavvangAuthor Commented:
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
 
ecwCommented:
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
 
ssnkumarCommented:
>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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now