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 support@ccsinfo.com

Help needed

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



Joined: 30 Jul 2011
Posts: 4

View user's profile Send private message

Help needed
PostPosted: Wed Nov 02, 2011 10:03 am     Reply with quote

Hi all, sorry for the newbie question but I've encounter some error while trying to compile my source file.

int Ring_counts = 0;
unsigned char Input_from_porta = 0x00;

when I try to compile it, errors occur.

error 51 : A numeric expression must appear here.

Did I do something wrong in declaring a variable? Thanks in advance for the helps given. Smile
Ttelmah



Joined: 11 Mar 2010
Posts: 19249

View user's profile Send private message

PostPosted: Wed Nov 02, 2011 10:23 am     Reply with quote

Triple check the lines _in front_ of the error line.
What you post is fine, but errors like this occur on the first occasion where the result becomes impossible for the compiler. This means that an error on a line, can show as a problem several lines latter, not in the actual line where the fault is.
Also look at the placement of the lines - need to be outside the functions for global declarations, or at the start of a function segment, for others. Indeterminate errors can occur if they are in the wrong location.
Also look carefully at things like function names. If you have a function called 'Ring_counts', or one called Input_from_porta, you can't also have a variable with the same name.
If you can't see what is wrong, cut and past say the ten lines up to and including the fault ones here, and we may be able to help.

Best Wishes
Vincent112



Joined: 30 Jul 2011
Posts: 4

View user's profile Send private message

PostPosted: Wed Nov 02, 2011 10:32 am     Reply with quote

Code:
void main()
{

   while (true)
   {
      detect_count_offhook();
      play_message1();
      hangs_up ();
   }
}

void detect_count_offhook(void)
{
   set_tris_a(all_in);
   set_tris_c(all_out);
   int Ring_counts = 0;
   unsigned char Input_from_porta = 0x00;

   while (ring_counts <= max_number_of_rings)
   {
      input_from_porta = port_a;
      if ((input_from_porta & mask_bit0)== 0)
      {
      ring_counts +=1;
      delay_ms (3000);
      }
   }

   port_c = pc0_high;

}

is this sufficient enough? because I'm taking reference a sample coding from internet.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Nov 02, 2011 11:34 am     Reply with quote

Quote:
void detect_count_offhook(void)
{
set_tris_a(all_in);
set_tris_c(all_out);
int Ring_counts = 0;
unsigned char Input_from_porta = 0x00;

CCS wants variable declarations to be placed at the start of the function.
Place lines of code after that.
Ttelmah



Joined: 11 Mar 2010
Posts: 19249

View user's profile Send private message

PostPosted: Wed Nov 02, 2011 3:39 pm     Reply with quote

Not only CCS.
_C_ requires this.
It is only latter extended languages like C++, that allow 'inline' declarations like this.

Best Wishes
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