Thread: Void Pointer Warnings

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    36

    Void Pointer Warnings

    Code:
    #include <stdio.h>
    #include <pthread.h>
    
    
    #define MAX_LINES 500
    #define LINE_LENGTH 80
    
    typedef struct args ARGS;
    
    char readin[MAX_LINES][LINE_LENGTH];
    
    struct args{
    
            int NumCalls;
            int NumStored;
    
    };
    
    *MakeCalls(void* params){
    //stuff cut out
    }
    
    int main(int argc, char* argv[]){
    
    //initialize an in-memory array to con
    
    int NumStored=0;
    int NumThreads=atoi(argv[1]);
    int NumCalls=atoi(argv[2]);
    int x;
    
    FILE *lines = fopen("lines.txt","r");
    pthread_t threads[NumThreads];
    
    ARGS params= {NumCalls,NumThreads};
    ARGS *argptr = &params;
    
    for(x=0;x<NumThreads;x++){
    
            pthread_create(&threads[x],NULL,MakeCalls,(void *)argptr);
    }
    now this code compiles fine, I havent tested if it works the way I want. but I was essentially wondering about parameter 3 in pthread_create since it's throwing a warning

    sample.c:80: warning: passing arg 3 of `pthread_create' from incompatible pointer type

    can someone possible explain why it's throwing a warning for argptr, or direct me to a place where I can figure it out for myself

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    *MakeCalls(void* params){
    //stuff cut out
    }
    What exactly is the return type of "MakeCalls"? It should be void. You don't have any return type here, so assuming this actually compiles, it will default to an int, which coupled with the *, gives you the return type of "int *", and not "void *".

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    36
    So what you are saying is that the method should return void, which corrects that error.

    Is there a reason as to why that would give an error though. As I understand it, the 3rd argument is expected to be a void * that is passed to the starting method for the thread.

    What would this have to do with the return type of the method?

    Either way, thx for the help.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    No, you're one off. Look at the prototype:
    Code:
    int  pthread_create(pthread_t  *  thread, pthread_attr_t *attr, void * (*start_routine)(void *), void * arg);
    That is the third argument.

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,662
    Your main() does not appear to contain C code (this being the C forum)
    It might be C99 compatible code, but it certainly isn't C89 code.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    Jan 2003
    Posts
    36
    When I say 3rd argument, I was refering to it as the "error" way, 0,1,2,3. It is the last argument I was refering to.

    and As to not including C code, if that isnt, I've never seen C code in my life before. This is an for an OS course, and we are using processes and threads in C.

    Mike

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Well you were referring to them wrong. It does not start at "0", it starts at "1". There is no argument 0. You're thinking of arrays. Case and illustrated point:
    Code:
    #include <stdio.h>
    int main( void )
    {
        printf( 10 );
        return 0;
    }
    
    caseandpoint.c: In function `main': caseandpoint.c:4: warning: passing arg 1 of `printf' makes pointer from integer without a cast
    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inserting a swf file in a windows application
    By face_master in forum Windows Programming
    Replies: 12
    Last Post: 05-03-2009, 11:29 AM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05:42 PM
  4. Replies: 3
    Last Post: 05-13-2007, 08:55 AM
  5. towers of hanoi problem
    By aik_21 in forum C Programming
    Replies: 1
    Last Post: 10-02-2004, 01:34 PM