Can not find why this is wrong coding.

Pages: 12
In the following snippet:
cube_updater ( (void *)rs232_cube)
    unsigned char pushcube[CUBE_SIZE][CUBE_SIZE];

    while (1)
        memcpy(pushcube, rs232_cube, CUBE_SIZE*CUBE_SIZE);

What is this function going to return? You need to specify the return type.

Next you don't want to surround the void* with parentheses. By using the parentheses you are indicating a cast operation. So this function prototype and function implementation should look like:
void cube_updater( void* rs232_cube)
This saying that this function will not return anything and it takes one parameter (a void pointer).

With this implementation:

line 92 void cube_updater ( (void*) rs232_cube )

I get the following error message:

/home/bruce/Desktop/.../main.c line 92 error: expected declaration specifiers or ‘...’ before ‘(’ token|
||=== Build finished: 1 errors, 0 warnings ===|

When I make jib's change:

Line 92 void cube_updater ( void* rs232_cube )

I get this error message:

/home/bruce/Desktop/.../main.c line 92 error: conflicting types for ‘cube_updater’|
/home/bruce/Desktop/.../cube.h line14 note: previous declaration of ‘cube_updater’ was here|
||=== Build finished: 2 errors, 1 warnings ===|

The declaration in cube.h is:

line 14 void *cube_updater(void* );

If this declaration in cube.h is changed to match the usage in main.c :

line 14 void cube_updater( void* );

The following Linking error is the result:

/home/bruce/Desktop/.../main.c||In function ‘main’:|
/home/bruce/Desktop/.../main.c|31|warning: passing argument 3 of ‘pthread_create’ from incompatible pointer type [enabled by default]|

/usr/include/pthread.h line 225 note: expected ‘void * (*)(void *)’ but argument is of type ‘void (*)(void *)’|

||=== Build finished: 1 errors, 1 warnings ===|

If I change that declaration the code is in conflict withthe implementation in libpthread. I seem to be going around in circles.

Last edited on
It looks as though jlb assumed that you wanted your function to return nothing. A perfectly natural assumption, since your function doesn't return anything, and doesn't specify a return type!

What that error message is telling you is that your function needs to return a void*, because the pthread library expects that. So you need to give your function that return type in both the prototype and the implementation, and make it return the appropriate pointer.

Last edited on
Thank you all... MikeyBoy led me home.... 0 errors ... Thanks so much for paying forward.
You're welcome :)
Topic archived. No new replies allowed.
Pages: 12