warning: passing argument 2 of ‘signal’ from incompatible pointer type

This is a discussion on warning: passing argument 2 of ‘signal’ from incompatible pointer type within the C Programming forums, part of the General Programming Boards category; hello, why i am getting this warning? how can i solve this............ warning: passing argument 2 of ‘signal’ from incompatible ...

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    20

    Post warning: passing argument 2 of ‘signal’ from incompatible pointer type

    hello,
    why i am getting this warning? how can i solve this............

    warning: passing argument 2 of ‘signal’ from incompatible pointer type
    getting warning in redline

    Code:
    int slickPing(amount,sock,dest)
    int amount,sock;
    char *dest;
    {
    
    	int alarmHandler();
    	unsigned nameResolve(char *);
    	
    	register int retcode,j=0;
    	struct icmphdr *icmp;
    	struct sockaddr_in sin;
    	unsigned char sendICMPpak[MAXPAK]={0};
    	unsigned short pakID=getpid()&0xffff;
    
    	struct ippkt{
       		struct iphdr ip;
       		struct icmphdr icmp;
       		char buffer[MAXPAK];
    	}pkt;
    
    	bzero((char *)&sin,sizeof(sin));
    	sin.sin_family=AF_INET;
    	sin.sin_addr.s_addr=nameResolve(dest);
    
    		/* ICMP Packet assembly  */
    	/* We let the kernel create our IP header as it is legit */
    
    	icmp=(struct icmphdr *)sendICMPpak;
    	icmp->type=ICMP_ECHO;			/* Requesting an Echo */
    	icmp->code=0;				/* 0 for ICMP ECHO/ECHO_REPLY */
    	icmp->un.echo.id=pakID;			/* To identify upon return */	
    	icmp->un.echo.sequence=0;		/* Not used for us */
    	icmp->checksum=in_cksum((unsigned short *)icmp,64);
    
    	fprintf(stderr,"sending ICMP_ECHO packets: ");
    	for(;j<amount;j++){
    		usleep(ICMPSLEEP);		/* For good measure */
    		retcode=sendto(sock,sendICMPpak,64,0,(struct sockaddr *)&sin,sizeof(sin));
    		if(retcode<0||retcode!=64)
    			if(retcode<0){
    				perror("ICMP sendto err");
    				exit(1);
    			}
    			else fprintf(stderr,"Only wrote %d bytes",retcode);
    		else fprintf(stderr,".");
    	}
    	HANDLERCODE=1;
    	signal(SIGALRM,alarmHandler);	/* catch the ALARM and handle it */
    	fprintf(stderr,"\nSetting alarm timeout for 10 seconds...\n");
    	alarm(10);	/* ALARM is set b/c read() will block forever if no */
    	while(1){	/* packets arrive...   (which is what we want....)  */
    		read(sock,(struct ippkt *)&pkt,MAXPAK-1);
      		if(pkt.icmp.type==ICMP_ECHOREPLY&&icmp->un.echo.id==pakID){
    			if(!HANDLERCODE)return(0);
    			return(1);
    		}
      	}	
    }
    
    
    /* 
     *	SIGALRM signal handler.  Souper simple.
     */ 
    int alarmHandler(){
    
    	HANDLERCODE=0;		/* shame on me for using global vars */
    	alarm(0);
    	signal(SIGALRM,SIG_DFL);
    	return(0);
    }

  2. #2
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,758
    From Russia: http://psb.sbras.ru/cgi-bin/www/unix...x-man?signal+3

    SYNOPSIS
    #include <signal.h>

    void (*
    signal(int sig, void (*func)(int)))(int);

    or in FreeBSD's equivalent but easier to read typedef'd version:

    typedef void (*sig_t) (int)

    sig_t
    signal(int sig, sig_t func);
    It's clear that your handler function has the wrong prototype; pass something compatible (a sig_t).
    Last edited by whiteflags; 04-15-2008 at 12:24 AM.

  3. #3
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    it means that alarmHandler has to have following prototype:

    Code:
    void alarmHandler(int param);
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,985
    Code:
    int slickPing(amount,sock,dest)
    int amount,sock;
    char *dest;
    {
    Better to use ISO C definitions:

    Code:
    int slickPing(int amount, int sock, char* dest)
    {
    And the warning is because it really shouldn't compile because you are passing a pointer to a function that doesn't match what signal wants or expects.
    Vart points out the correct solution there.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointers, structures, and malloc
    By lugnut in forum C Programming
    Replies: 24
    Last Post: 10-09-2008, 05:52 PM
  2. Replies: 5
    Last Post: 08-12-2007, 06:26 PM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-30-2005, 12:21 AM
  4. Compiler "Warnings"
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 04-24-2005, 02:09 PM
  5. Errors
    By Rhidian in forum C Programming
    Replies: 10
    Last Post: 04-04-2005, 01:22 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21