Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

farmerdoug

macrumors 6502a
Original poster
Sep 16, 2008
541
0
The C++ made me change all my calloc statements including.

Code:
from
readyspline = calloc(waves, sizeof (struct formag*));
for ( i =0; i < waves; i++)
    readyspline[i] = calloc(1, sizeof (struct formag));

to
readyspline = (formag **)calloc(waves, sizeof (struct formag*));
for ( i =0; i < waves; i++)
    readyspline[i] = (formag*)calloc(1, sizeof (struct formag));

now my pthread_create call
Code:
 pthread_create(&qthread[slice], NULL, (void*)rotate, (void *)readyspline[slice]);

is wrong. The error says Overloaded function with no contextual type information.


help
thanks.
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
I'm not that familiar with C++, but i believe NULL is void *. Maybe try casting to const pthread_attr_t * for your second argument?

-Lee
 

farmerdoug

macrumors 6502a
Original poster
Sep 16, 2008
541
0
As has happened before, maybe I was just lucky but I had to redefine and modify my routines.
I made changes to mimic the example below. Have to change some more routines then I'll see if it runs.
Code:
struct thread_data{
   int  thread_id;
   int  sum;
   char *message;
};

struct thread_data thread_data_array[NUM_THREADS];

void *PrintHello(void *threadarg)
{
   struct thread_data *my_data;
   ...
   my_data = (struct thread_data *) threadarg;
   taskid = my_data->thread_id;
   sum = my_data->sum;
   hello_msg = my_data->message;
   ...
}

int main (int argc, char *argv[])
{
   ...
   thread_data_array[t].thread_id = t;
   thread_data_array[t].sum = sum;
   thread_data_array[t].message = messages[t];
   rc = pthread_create(&threads[t], NULL, PrintHello, 
        (void *) &thread_data_array[t]);
   ...
}

thanks
 

qtx43

macrumors 6502a
Aug 4, 2007
659
16
This is by design; a different design philosophy for C vs. C++. C will allow you to assign a (void*) to any other pointer type, and vice versa. C++ is much stricter about type conversions, you usually must use a cast. Although C++ will convert a derived class type to a base type automatically. And the C-style cast works, but it is preferred to use the C++ specific ones, usually static_cast<> or dynamic_cast<>. It's even better to use new or the standard library containers instead of malloc, and not do casts at all, but of course when you're interfacing with a C library sometimes you have to. For example, you can use a std:vector<std:vector <sometype> > and with an appropriate constructor and algorithm, not have to do an explicit loop at all to initialize the 2-dim array.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.