View unanswered posts | View active topics It is currently Wed Nov 13, 2019 11:24 pm






Reply to topic  [ 2 posts ] 
Issue using Function Prototypes 
Author Message
Rookie

Joined: Wed Feb 04, 2015 7:04 am
Posts: 7
Post Issue using Function Prototypes
Hi forum,

I have been having issues with using function prototypes which pass parameters. The code does not compile, as RobotC doesn't recognise the prototype as one.
The code below shows this:

Code:
// Prototypes
int test(int);
int test_b(void);

// Variables
int q,w;

/*--------------*/
task main()
{
q=test_b();
w=test(q);
}

/*--------------*/
int test(int x)
{
return(x*x);
}

/*--------------*/
int test_b(void)
{
return(45);
}


The issue is that int test(int) is not been read as a prototype at the top of the file, and therefore is displaying errors. However the function int test_b, which has no parameters passed to it, works as expected (without errors). Now I understand that in this simple piece of code, I could just move the functions around so that the compiler knows they exist when they are called; however my larger more complex code utilises many functions and this cannot be done.
As a side note the code above compiles and builds fine in any normal C compiler.

Is this another known limitation with RobotC?

Kind Regards,
Thomas Barnett (MEng)


Fri Mar 27, 2015 9:22 am
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 722
Post Re: Issue using Function Prototypes
When you create the prototypes, you have to make sure you not only create the parameter's data type but also its name. Try changing your prototype to the code listed below, recompile, and let us know if you run into any other issues as we are more than happy to help.

Code:
int test(int x);

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our updated help documentation and the ROBOTC Forums.


Mon Mar 30, 2015 1:58 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.