This code will NOT compile

Hello. We’re having a problem…The compiler won’t compile this, and we don’t know why…Is there anything wrong? It seems syntactically correct…

user_routines.c (15 KB)


user_routines.c (15 KB)

int cube (p1_y);
{
return p1_y * p1_y * p1_y
} 

int cube2 (p2_y);
{
return p2_y * p2_y * p2_y
}

int square (p1_y);
{
return p1_y * p1_y
}

int square2 (p2_y);
{
return p2_y * p2_y
}

You are declaring these functions inside the default_routine function. They should be outside any functions.

We didi put it outside any functions…at the top of the “user routines” file, and it still wouldn’t be compile…Where should the declarations of functions and any user code we need go?

I noticed a few more errors in your functions.

int square2 (p2_y);
{
return p2_y * p2_y
}

If you want it to take a variable you pass, you need to declare the type of variable. Also, you shouldn’t have a semicolon on the end of the declaration but should on the return statement. p2_y is a global variable, so it’s not wise to also use it as a local variable (I don’t think it will cause a compile error, but it is confusing to read).

If you want separate functions for each joystick axis, you could write it like:

int square2 ()
{
return (p2_y * p2_y);
}

For a generic function, you could write

int square2 (int variable_to_square)
{
return (variable_to_square * variable_to_square);
}

Note: It’s much easier to help if you tell us what the error message is and what code is causing it.

OK…Thanks! It basically was a syntax error, and everytime we got something to work, it had a syntax error with the “{” and/or the “}”…the file was the user_routines.c file, where I thought you were supposed to put user code…

int cube1 (unsigned char p1_y)
{
return((int)p1_y * (int)p1_y * (int)p1_y);
} 

and you’ll need to use casts to up the unsigned char to ints. Also, you can’t use p1_y as a passed argument - its defined in ifi_aliases.h:


ifi_aliases.h:30: #define p1_y        rxdata.oi_analog01

and unless you are absolutely certain of the precedence rules for applying operations - use parentheses to eliminate any questions:

 
pwm01 = cube()  - (3 * square() ) + (5 * p1_y);  /*x^3-3x^2+5x* A cubic function to regulate the sensitivity of the robot's drive*/
  pwm02 = cube2() - (3 * square2()) + (5 * p2_y); /*same thing, son*/  
 


```<br><br><a class='attachment' href='/uploads/default/original/3X/1/6/165de3045ea4924b32bb4e3d054de343053f3b15.c'>user_routines.c</a> (15.2 KB)<br><a class='attachment' href='/uploads/default/original/3X/3/1/3127c5f1834e1f11bf685808281b84efa0039e79.c'>user_routines_diff.c</a> (3.78 KB)<br><br><br><a class='attachment' href='/uploads/default/original/3X/1/6/165de3045ea4924b32bb4e3d054de343053f3b15.c'>user_routines.c</a> (15.2 KB)<br><a class='attachment' href='/uploads/default/original/3X/3/1/3127c5f1834e1f11bf685808281b84efa0039e79.c'>user_routines_diff.c</a> (3.78 KB)<br>

Actually you’re missing semi colons everywhere.