Can not find why this is wrong coding.

Pages: 12
My file reads in part like this:

-----------------------------------------------------------
/* Main.c for PC side of control fed to
* AVR by UART/ RS232
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <pthread.h>

void *control_updater (unsigned char rs232_control[10][10]);

void main(int argc, char **argv)
{
control_init();
----------------------------------------------------

When compiled in AVI, CodeBlocks, the following error appears:

----------------------------------------------------
/home/Dev_Plat/Desktop/Control_Course/main.c --- line 20 --- error: expected ‘;’, ‘,’ or ‘)’ before ‘{’ token|
||=== Build finished: 1 errors, 0 warnings ===|

----------------------------------------------------

I have retyped the lines, and cannot find how to correct it.

Can anyone guide me?








Please post more of the file. If you use the code tags (they show up as "<>" in the Format box to the right of the input window), line numbers will show up.

The main function must have a return type of int (according to the standards). Some compilers allow for a return type of void, but this is not good practice. And that does not seem to be the problem you are running into.

When we can see more of the code and see which is line 20, maybe we can give you more help.
The complete Main.c is posted here:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* Main.c for PC side of control fed to
* AVR by UART/ RS232
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <pthread.h>

void *control_updater (unsigned char rs232_control[10][10]);
int main(int argc, char **argv)
{                                                            // <------  This is line 20
    control_init();

    pthread_t control_thread;
    int iret, i, x;

    iret = pthread_create(&control_thread, NULL, control_updater, rs232_control);


    while (1)
    {
        printf("Control: sidewaves\n");                          // sidewaves
        sidewaves(2000,100);

        printf("Control: ripples\n");                            // ripples
        ripples(2000,100);

        printf("Control: spinwave\n");                           // spinwave
        spin(2000,100);

        printf("Control: sinewaves\n");                          // Sinelwave
        sinelines(2000,100);

        printf("Control spherical\n");                         // Spherical
        spherical1500,100);

        printf("Control: Explosive");                          // Explosive
        fireworks(7,50,1200);

     }

}

void *control_updater (unsigned char rs232_control[10][10])
{
    unsigned char send_control[10][10];

    while (1)
    {
        memcpy(send_control, rs232_control, 100);
        control_push(send_control);
    }
}



There are numerous other files.

The error message refers to the line 20 indicated. I changed the main type to int with same result
Last edited on
I'm sorry. I don't see an error in this. I can only guess at things.

I assume that the 7 missing lines (line 20 shows up as line 13) are comments or blank or something. Is there any non-comment lines that were omitted in your post?

Interestingly, you changed your include from <pthread.h> to "pthread.h". Is there a possibility that you are using your own pthread.h file that has something declared incompletely?

By the way, you control_updater function is declared to take an array of 10-char arrays, while it is defined to take an array of 8-char arrays. I don't think that's your problem, but it needs to be corrected.

Also, I don't see the definition of rs232_control as seen by the body of main(). Could it be a global array whose definition got messed up somehow?

Without seeing the entire Main.c, I can't be more specific.

Have a happy new year.

I corrected those errors with the same results. The first 13 lines were titles and other non-operative comments.
> The first 13 lines were titles and other non-operative comments.
Your first line has only a `/'
that's causing your compiler to choke.

You need to define rs232_control
You've got a `/' in the first line that is causing your compiler to choke.
Also, you need to define `rs232_control'
I defined it as a 8x8 matrix, what else is needed??
What compiler are you using? What standard are you compiling to, C90, C99, or C11? I would start by commenting out everything except:
1
2
3
4
5
6
int main(int argc, char **argv)
{


   return 0;
}


Make sure you add the return statement. If the program compiles then start uncommenting a line or two at a time and compile as you go. When the program stops compiling you may have found your problem.
Last edited on
I've found that Visual Studio 2010 doesn't like forward declarations very much. Try replacing your forward declaration of void* control_updater with the implementation.
I've found that Visual Studio 2010 doesn't like forward declarations very much.


waaaaat?
waaaaat?


Not sure if sarcasm

or

insinuation of my stupidity.
It was actually confusion. I've never had such an experience with Visual Studio and I can't imagine why you'd think it would have a problem with such a fundamentally basic part of the C++ language.
What compiler are you using?


I'm using GCC in CodeBlocks

I'm reposting the code with suggestions included and a new set of error messages. Getting this threading correct is tougher than I thought

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
 * Main for PC side of PC generated patterns fed to
 * AVR by UART
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "cube.h"
#include "draw.h"
#include "draw_3d.h"
#include "effect.h"
#include "gameoflife.h"
#include <pthread.h>


unsigned char rs232_cube[8][8];
void cube_updater(*rs232_cube);

int main(int argc, char **argv)
{

    cube_init();

    pthread_t cube_thread;
    int iret, i, x;

/*
    extern int pthread_create (pthread_t *__restrict __newthread,
			   __const pthread_attr_t *__restrict __attr,
			   void *(*__start_routine) (void *),
			   void *__restrict __arg) __THROWNL __nonnull ((1, 3));
*/

    iret = pthread_create(&cube_thread, NULL, cube_updater, rs232_cube);

 /*  Note I've modified the variable names in the code from "control" to "cube" to better reflect the current application:

 This is the last change suggested from the forum:

 iret =    pthread_create(&control_thread, ULL, control_updater,rs232_control  )                //undeclared

*/
void sidewaves(int, int);
void ripples(int, int);
void linespin(int, int);
void sinelines(int, int);
void spheremove(int, int);
void fireworks(int, int);
void gol_play(int, int);
    while (1)
    {
        printf("Effect: sidewaves\n");                          // sidewaves
        sidewaves(2000,100);

        printf("Effect: ripples\n");                            // ripples
        ripples(2000,100);

        printf("Effect: linespin\n");                           // Linespin
        linespin(2000,100);

        printf("Effect: sinelines\n");                          // Sinelines
        sinelines(2000,100);

        printf("Effect: spheremove\n");                         // Spheremove
        spheremove(1500,100);                                   // ne555

        printf("Effect: fireworks\n");                          // Fireworks
        fireworks(7,50,1200);

        printf("Effect: gol_play\n");                           // Game of Life
        for (i=0; i<10; i++)
        {
            for (x=0; x<20; x++)
                setvoxel(rand()%4,rand()%4,rand()%4);

            gol_play(50,1000);


        }
    }

}

/*void *cube_updater (void* param)                       //kbw
 // code for recasting suggestion from the forum - kbw
{
    unsigned char *rs232_cube = reinterpret_cast<unsigned char*>(param);
    unsigned char pushcube[8][8];

    while (1)
    {
        memcpy(pushcube, rs232_cube, 64);
        cube_push(pushcube)
    }

    return NULL;
}
*/



void *cube_updater (unsigned char rs232_cube[8][8])
{
    unsigned char pushcube[8][8];

    while (1)
    {
        memcpy(pushcube, rs232_cube, 64);
        cube_push(pushcube);
    }
}




Here are the error messages:


Line [17| error: conflicting types for ‘rs232_cube’|
Line |13| note: previous declaration of ‘rs232_cube’ was here|
Line |18| error: expected declaration specifiers or ‘...’ before ‘*’ token|
I
Line |35| error: ‘cube_updater’ undeclared (first use in this function)|

Line [93| error: unknown type name ‘code’|
Line |93| error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘recasting’|
Line |93| error: unknown type name ‘recasting’|
||=== Build finished: 8 errors, 7 warnings ===|


New issues are :

I declared the rs232_cube in line 17, but it seems to think I haven't declared it, and that the previous
declaration is in line 13, but there are no declarations for it in gameoflife.h. If I I do see that the
declaration is faulty, by the error message in line 18, but after numerous tries have been unable to fix it.
I've trieded the casting suggestion from kbw with and without the various changes in the declaration,
all without improvement, but a variety of different error messages. The suggestion to comment out
everything and uncomment a line at a time leads me to believe the problem is between lines 13 and 35.








[/code]
Last edited on
> you need to define `rs232_control'
>> I defined it as a 8x8 matrix
No, you don't. Learn about scope
Does your program still contain all these includes?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*
 * Main for PC side of PC generated patterns fed to
 * AVR by UART
*/

#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "cube.h"
#include "draw.h"
#include "draw_3d.h"
#include "effect.h"
#include "gameoflife.h"
#include <pthread.h>

void *cube_updater (void *rs232_cube); //respect this prototype ,because that's what pthread_create() asks for

int main(int argc, char **argv)
{

If so then you need to carefully investigate your headers. Look for simple things like a missing semicolon at the end of a class declaration etc. When dealing with errors the compiler tells you where it detects the error not necessarily exactly where the error is located. You start at that location and start back tracking until you find the problem.

If not then where have you defined things like:
control_init();
I checked the headers and found a missing " ; ". I now have one error message which I can't resolve:

The function declaration in cube.h is:


cube. h line 21: void cube_push (unsigned char data[CUBE_SIZE][CUBE_SIZE]);


The Function Call in main.c: In the function int main(int argc, char **argv is:

note: file main.c includes: line 9 #include "cube.h" (see code above)

main.c Line 21: cube_updater(*rs232_cube)

The function implimentation in main.c is:

main.c Line 92: cube_updater ( (void *)rs232_cube)


The error message is:


main.c Line 92: error: expected declaration specifiers or ‘...’ before ‘(’ token|

Last edited on
What file is this error located in? Your compiler should tell you this information.

Please post the complete error messages (all of the messages) exactly as they appear in your development environment. These messages have important information embedded within them to aid in locating and repairing the errors.

Also in future don't remove pertinent information from your files when, for example in your last posts you left out your header file includes, you only showed "standard" headers.
Last edited on
Also repost your file. The line numbers in this last past don't line up with the last file you posted, so they make no sense.

If the titles in your last post are correct, then line 92 is wrong--it should be the same as the function declaration. Also, line 21 may or may not need a *. Of course, without the full code, that's only guesses.
I've modified the description above to reflect the location of the various aspects of the function in question. Check the more complete code in earlier entries to get a better context if needed. The error message is the only error.
I'm reposting the code in main.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
 * Main for PC side of PC generated patterns fed to
 * AVR by UART
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "cube.h"
#include "draw.h"
#include "draw_3d.h"
#include "effect.h"
#include "gameoflife.h"
#include <pthread.h>


int main(int argc, char **argv)
{


    cube_updater(*rs232_cube);

    cube_init();
    pthread_t cube_thread;
    int iret, i, x;
/*  from pthread.h:    extern int pthread_create (pthread_t *__restrict __newthread,
			          __const pthread_attr_t *__restrict __attr,
			          void *(*__start_routine) (void *),
			          void *__restrict __arg) __THROWNL __nonnull ((1, 3));                       */

    iret = pthread_create(&cube_thread, NULL, *cube_updater, *rs232_cube);


    void sidewaves(int, int);
    void ripples(int, int);
    void linespin(int, int);
    void sinelines(int, int);
    void spheremove(int, int);
    void fireworks(int, int, int);
    void gol_play(int, int);
    while (1)
    {
        printf("Effect: sidewaves\n");                          // sidewaves
        sidewaves(2000,100);

        printf("Effect: ripples\n");                            // ripples
        ripples(2000,100);

        printf("Effect: linespin\n");                           // Linespin
        linespin(2000,100);

        printf("Effect: sinelines\n");                          // Sinelines
        sinelines(2000,100);

        printf("Effect: spheremove\n");                         // Spheremove
        spheremove(1500,100);                                   // ne555

        printf("Effect: fireworks\n");                          // Fireworks
        fireworks(7,50,1200);

        printf("Effect: gol_play\n");                           // Game of Life
        for (i=0; i<10; i++)
        {
            for (x=0; x<20; x++)
                setvoxel(rand()%4,rand()%4,rand()%4);

            gol_play(50,1000);


        }
    }

}
/*
void *cube_updater (void* param)                       //kbw
{
    unsigned char *rs232_cube = reinterpret_cast<unsigned char*>(param);
    unsigned char pushcube[8][8];

    while (1)
    {
        memcpy(pushcube, rs232_cube, 64);
        cube_push(pushcube);
    }

    return NULL;
}

*/
 // code before recasting suggestion from the forum - ne555

cube_updater ( (void *)rs232_cube)
{
    unsigned char pushcube[CUBE_SIZE][CUBE_SIZE];

    while (1)
    {
        memcpy(pushcube, rs232_cube, CUBE_SIZE*CUBE_SIZE);
        cube_push(pushcube);
    }
}


Last edited on
Pages: 12