Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   This code will NOT compile (http://www.chiefdelphi.com/forums/showthread.php?t=64197)

greatman05 15-02-2008 18:27

This code will NOT compile
 
1 Attachment(s)
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...

Joe Ross 15-02-2008 18:43

Re: This code will NOT compile
 
Code:

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.

greatman05 15-02-2008 19:03

Re: This code will NOT compile
 
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?

Joe Ross 15-02-2008 19:49

Re: This code will NOT compile
 
I noticed a few more errors in your functions.

Code:

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:
Code:

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

For a generic function, you could write

Code:

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.

greatman05 15-02-2008 19:59

Re: This code will NOT compile
 
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...

dcbrown 15-02-2008 20:27

Re: This code will NOT compile
 
2 Attachment(s)
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:

Code:

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:
Code:


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*/


purduephotog 16-02-2008 16:07

Re: This code will NOT compile
 
Quote:

Originally Posted by greatman05 (Post 699734)
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...

Actually you're missing semi colons everywhere.


All times are GMT -5. The time now is 18:26.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi