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

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

    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

    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];
    	bzero((char *)&sin,sizeof(sin));
    		/* 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: ");
    		usleep(ICMPSLEEP);		/* For good measure */
    		retcode=sendto(sock,sendICMPpak,64,0,(struct sockaddr *)&sin,sizeof(sin));
    				perror("ICMP sendto err");
    			else fprintf(stderr,"Only wrote %d bytes",retcode);
    		else fprintf(stderr,".");
    	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);
     *	SIGALRM signal handler.  Souper simple.
    int alarmHandler(){
    	HANDLERCODE=0;		/* shame on me for using global vars */

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

    #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)

    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-14-2008 at 11:24 PM.

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

    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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    int slickPing(amount,sock,dest)
    int amount,sock;
    char *dest;
    Better to use ISO C definitions:

    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, 04:52 PM
  2. Replies: 5
    Last Post: 08-12-2007, 05:26 PM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  4. Compiler "Warnings"
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 04-24-2005, 01:09 PM
  5. Errors
    By Rhidian in forum C Programming
    Replies: 10
    Last Post: 04-04-2005, 12:22 PM

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