CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

problem with expression & constant

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
mirberti
Guest







problem with expression & constant
PostPosted: Tue Jun 01, 2004 2:41 am     Reply with quote

Hi,
I write this code but when I compile it, the compiler return me an error :

"EXPRESSION MUST EVALUATE TO A CONSTANT"

why ?? how can I resolve this problem ??

Thanks Mirko




Code:

int const PortaI[] = {PIN_B0, PIN_B1, PIN_C2, PIN_B5};

   for (i=0;i<N_INGRESSI+1;i++){
      if( input(PortaI[i]) ) Ingressi[i] = 0x01;
      else Ingressi[i] = 0x00;
   }     
Ttelmah
Guest







Re: problem with expression & constant
PostPosted: Tue Jun 01, 2004 5:42 am     Reply with quote

mirberti wrote:
Hi,
I write this code but when I compile it, the compiler return me an error :

"EXPRESSION MUST EVALUATE TO A CONSTANT"

why ?? how can I resolve this problem ??

Thanks Mirko




Code:

int const PortaI[] = {PIN_B0, PIN_B1, PIN_C2, PIN_B5};

   for (i=0;i<N_INGRESSI+1;i++){
      if( input(PortaI[i]) ) Ingressi[i] = 0x01;
      else Ingressi[i] = 0x00;
   }     

Basically, the 'input' statement (and the equivalent output one), are not normal functions. They are instructions to the compiler to access a single pin, which must not change after compile time. The compiler cannot handle these funtions receiving anything other than a fixed value. Though the individual values in your array are fixed, by selecting using a variable, you are exceeding what the compiler can do with these functions.
There are a huge number of solutions. Probably the simplest, is just to use a switch to access the required pin. Alternatively, you can just write your own I/O function using a mask (but in your case, since the required locations are on two ports, this involves more work).

Best Wishes
mirberti
Guest







Re: problem with expression & constant
PostPosted: Tue Jun 01, 2004 9:42 am     Reply with quote

thanks, but in my old firmwware there was a solution with SWITH.
Now I would write a scalable routine with I can use in all my program only changing a define or a constant.

Regards Mirko



Ttelmah wrote:
mirberti wrote:
Hi,
I write this code but when I compile it, the compiler return me an error :

"EXPRESSION MUST EVALUATE TO A CONSTANT"

why ?? how can I resolve this problem ??

Thanks Mirko




Code:

int const PortaI[] = {PIN_B0, PIN_B1, PIN_C2, PIN_B5};

   for (i=0;i<N_INGRESSI+1;i++){
      if( input(PortaI[i]) ) Ingressi[i] = 0x01;
      else Ingressi[i] = 0x00;
   }     

Basically, the 'input' statement (and the equivalent output one), are not normal functions. They are instructions to the compiler to access a single pin, which must not change after compile time. The compiler cannot handle these funtions receiving anything other than a fixed value. Though the individual values in your array are fixed, by selecting using a variable, you are exceeding what the compiler can do with these functions.
There are a huge number of solutions. Probably the simplest, is just to use a switch to access the required pin. Alternatively, you can just write your own I/O function using a mask (but in your case, since the required locations are on two ports, this involves more work).

Best Wishes
Ttelmah
Guest







Re: problem with expression & constant
PostPosted: Tue Jun 01, 2004 10:19 am     Reply with quote

mirberti wrote:
thanks, but in my old firmwware there was a solution with SWITH.
Now I would write a scalable routine with I can use in all my program only changing a define or a constant.

Regards Mirko



Ttelmah wrote:
mirberti wrote:
Hi,
I write this code but when I compile it, the compiler return me an error :

"EXPRESSION MUST EVALUATE TO A CONSTANT"

why ?? how can I resolve this problem ??

Thanks Mirko




Code:

int const PortaI[] = {PIN_B0, PIN_B1, PIN_C2, PIN_B5};

   for (i=0;i<N_INGRESSI+1;i++){
      if( input(PortaI[i]) ) Ingressi[i] = 0x01;
      else Ingressi[i] = 0x00;
   }     

Basically, the 'input' statement (and the equivalent output one), are not normal functions. They are instructions to the compiler to access a single pin, which must not change after compile time. The compiler cannot handle these funtions receiving anything other than a fixed value. Though the individual values in your array are fixed, by selecting using a variable, you are exceeding what the compiler can do with these functions.
There are a huge number of solutions. Probably the simplest, is just to use a switch to access the required pin. Alternatively, you can just write your own I/O function using a mask (but in your case, since the required locations are on two ports, this involves more work).

Best Wishes

The switch solution will still work. Adter all you only have four possible pins to be used.

Best Wishes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jun 01, 2004 11:06 am     Reply with quote

Look at the following thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=18233

Mark has posted two functions for output_high and
output_low that let you pass a CCS-style pin number
to the functions as a variable, instead of a constant.
Look for these function names in his post:
my_output_high()
my_output_low()
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group