View unanswered posts | View active topics It is currently Thu Oct 23, 2014 6:08 am






Reply to topic  [ 3 posts ] 
Why doesn't this code work for all data types? 
Author Message
Expert
User avatar

Joined: Mon Oct 06, 2008 6:30 pm
Posts: 176
Location: Netherlands
Post Why doesn't this code work for all data types?
Hi,

I'm trying to make a small array. I wrapped it into a struct to be able to pass it to functions. But it doesn't work for all data types. If the array is of type int or float this code compiles just fine. If I change the type of the array from int to char, byte or bool I get an error message:
Code:
 **Error**:Procedure call Parameters don't match declaration for 'resetWorld(tworld & world)'

What is wrong in this code?
Code:
const int XgridSize=99;
const int YgridSize=69;

typedef struct{
   int pos[XgridSize][YgridSize];
} tworld;

void resetWorld(tworld &world)
{
}

task main()
{
  tworld world;
  resetWorld(world);
}

_________________
My most recent blog: A grain of sugar


Sun Oct 19, 2008 6:39 pm
Profile WWW
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 615
Post Re: Why doesn't this code work for all data types?
This is a bug in the ROBOTC compiler that applies when matching function parameters against calling code. The bug only applies when passing 'struct' as a parameter. There was an compiler variable that was uninitialized for this case. The fix will appear in the next release of ROBOTC.

There is an alternative that you should / could use to pass array arguments to functions. Use a typedef to declare the array, but not a struct. Modification of your sample is below. I also changed XgridSize to 50 because 100 seems to exceed the limit of total allocated variables.

Code:
const int XgridSize=50;
const int YgridSize=69;

typedef byte TwoDimensionArrayParm[XgridSize][YgridSize];

void resetWorldTypedef(TwoDimensionArrayParm &world)
{
}

task main()
{
  TwoDimensionArrayParm world2;

  resetWorldTypedef(world2);
}


Mon Oct 20, 2008 4:01 pm
Profile
Expert
User avatar

Joined: Mon Oct 06, 2008 6:30 pm
Posts: 176
Location: Netherlands
Post Re: Why doesn't this code work for all data types?
Dick,

Thanks, this solves my problem. Now I can use a byte array instead of an int array to free some memory.

Aswin

_________________
My most recent blog: A grain of sugar


Mon Oct 20, 2008 6:00 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 3 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.