View unanswered posts | View active topics It is currently Tue Sep 02, 2014 12:04 pm






Reply to topic  [ 3 posts ] 
Problem: **Error**:Invalid array bound specification. 
Author Message
Rookie

Joined: Sun Mar 02, 2008 9:41 am
Posts: 25
Post Problem: **Error**:Invalid array bound specification.
Hi,

I am trying to define the following array in a function:

void environment(){
int y = TargetY * 2;
int x = TargetX * 2;
int array[y][x];
}

And i keep getting the following errors:
**Severe*:Constant Expression Expected
**Error**:Invalid array bound specification.
**Error**:Expected->';'. Found ', '
**Error**:Unexpected scanner token-> ', '
**Error**:Unexpected scanner token-> '['
*Warning*:Meaningless statement -- no code generated


Would anyone know why please?


Regards,
Giannis


Sun Mar 09, 2008 2:16 pm
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 
you may use only constant dimensions in declaration of arrays:
Code:
void environment(){
int y;
int x; // are both variables, no constants!

// int array[y][x]; // ERROR, because x, y are variables!
// declare:
const int yMax=40; // 40 or 30 or 50 or sth. else
const int xMax=40; // xMax and yMax are constants!

int array[yMax][xMax]; // works fine!

y = TargetY * 2; // where has Targetx/y been declared?
x = TargetX * 2; 

// and now use only array[0...y][0...x]

}


sort of dynamic memory allocation on the heap like the following ANSI C construct does not work in RobotC (as far as I know):
Code:
int *array;
int x;
int y;
y=TargetY*2;
x=TargetX*2; // TargetX/Y have to be defined earlier

array= (int *) malloc(y*x*sizeof(int)) ;

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Mon Mar 10, 2008 12:54 pm
Profile
Rookie

Joined: Sun Mar 02, 2008 9:41 am
Posts: 25
Post 
Hi,

Thanks for the reply.

I did try malloc but it does not work, i can confirm that.


Thanks for your reply.


Regards,
Giannis


Mon Mar 10, 2008 5:12 pm
Profile
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.