Pass parameter to _beginthread function

1.1k Views Asked by At

I have following code to start a new thread

int number = 10;
_beginthread(ModbusReadWrite, 0, (void*)number);

The function is:

void ModbusReadWrite(void *arg)
{
    char inBuffer[BUF_SIZE];
    int PointNumber = &arg;
    ...
}

It shows an error:

error C2440: 'initializing' : cannot convert from 'void **' to 'int'

So, I need to define new parameter of type int and pass it to ModbusReadWrite() function. How can I achieve it?

1

There are 1 best solutions below

0
On BEST ANSWER

The void* parameter may be used to pass anything. But it makes no sense to take its address:

int PointNumber = (int)arg;