Incompatible Pointer Type warnings

This is a discussion on Incompatible Pointer Type warnings within the C Programming forums, part of the General Programming Boards category; Hi all, I'm using a piece of code from a book (Linux Programming) which includes some IPC related excerpts I'd ...

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    28

    Incompatible Pointer Type warnings

    Hi all,

    I'm using a piece of code from a book (Linux Programming) which includes some IPC related excerpts I'd like to use (queue stuff).

    Here's some code that I'm using from the book, which produces the below compiler warnings.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <errno.h>
    #include <sys/types.h>
    #include <string.h>
    #include <sys/ipc.h>
    
    /* Get a queue DS record */
    int getQueueDs( int qid, struct msgqid_ds *qbuf ) {
    	if( msgctl( qid, IPC_STAT, qbuf) == -1) {
    		return(0);
    	}
    	return(1);
    }
    
    /* Change queue Permissions */
    int changeQueuePerms( int qid, char *mode ) {
    	struct msqid_ds tmpbuf;
    
    	/* Retrieve a current copy of the internal data structure */
    	getQueueDs(qid, &tmpbuf);
    
    	/* Change the permissions using an old trick */
    	sscanf(mode, "&#37;ho", &tmpbuf.msg_perm.mode);
    
    	/* Update the internal data structure */
    	if( msgctl( qid, IPC_SET, &tmpbuf) == -1) {
    		return(0);
    	}
    
    	return(1);
    }
    
    /* Change queue Size */
    int changeQueueSize( int qid, ushort newSize ) {
    	struct msqid_ds tmpbuf;
    
    	/* Retrieve a current copy of the internal data structure */
    	getQueueDs(qid, &tmpbuf);
    
    	/* Change the size value */
    	tmpbuf.msg_qbytes = newSize;
    
    	/* Update the internal data structure */
    	if( msgctl( qid, IPC_SET, &tmpbuf) == -1) {
    		return(0);
    	}
    
    	return(1);
    }
    
    /* Get queue info */
    int getQueueNumberOfMessages( int qid ) {
    	struct msqid_ds tmpbuf;
    
    	/* Retrieve a current copy of the internal data structure */
    	if ( getQueueDs( qid, &tmpbuf) ) {
    		return(tmpbuf.msg_qnum);
    	}
    
    	return(-1);
    }
    Compiler Warnings:-

    includes/queues.h:47: warning: `struct msgqid_ds' declared inside parameter list
    includes/queues.h:47: warning: its scope is only this definition or declaration, which is probably not what you want
    includes/queues.h: In function `getQueueDs':
    includes/queues.h:48: warning: passing arg 3 of `msgctl' from incompatible pointer type
    includes/queues.h: In function `changeQueuePerms':
    includes/queues.h:59: warning: passing arg 2 of `getQueueDs' from incompatible pointer type
    includes/queues.h: In function `changeQueueSize':
    includes/queues.h:77: warning: passing arg 2 of `getQueueDs' from incompatible pointer type
    includes/queues.h: In function `getQueueNumberOfMessages':
    includes/queues.h:95: warning: passing arg 2 of `getQueueDs' from incompatible pointer type
    I don't understand the incompatible pointer type warning as the man page tells me that these are the correct types for the msgctl function:-

    int msgctl(int msqid, int cmd, struct msqid_ds *buf);
    The "struct declared inside parameter list" warning I just don't follow at all.

    Any thoughts?

    Many thanks.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Yours: struct msgqid_ds *
    Theirs: struct msqid_ds *

    Compare and contrast.

  3. #3
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,655
    EDIT: Oooo...good eye, tabstop.
    Last edited by rags_to_riches; 06-11-2008 at 05:04 PM. Reason: tabstop nailed it...I whiffed.

  4. #4
    Registered User
    Join Date
    May 2008
    Posts
    28
    Ouch

    Thank you - great spot.......

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 04-04-2009, 04:45 AM
  2. Replies: 2
    Last Post: 04-11-2008, 03:42 AM
  3. c program error
    By cutelucks in forum C Programming
    Replies: 14
    Last Post: 12-21-2007, 11:12 PM
  4. Could somebody please help me with this C program
    By brett73 in forum C Programming
    Replies: 6
    Last Post: 11-25-2004, 02:19 AM
  5. towers of hanoi problem
    By aik_21 in forum C Programming
    Replies: 1
    Last Post: 10-02-2004, 02:34 PM

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