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

Why is my functional function not functioning???

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



Joined: 25 Aug 2005
Posts: 8

View user's profile Send private message

Why is my functional function not functioning???
PostPosted: Thu Aug 25, 2005 9:46 am     Reply with quote

Hello,

The compiler is giving me a bunch of strange errors for a function which I see no problem with. I even compiled it with gcc and it worked fine! Could someone tell me what I am doing wrong?

Here's my code:

Code:

// This function is used to compare two arrays of equal length.
// Returns '1' if arrays are identical, returns '0' if not

short compare_array(int length, int array1[], int array2[])
{
 length=(length-1);
 int num=length;      // (This is line 45)
 int result=1;
 
 while(num>=0)
 {
  if(array1[num]!=array2[num])
  {
   result=0;
  }
  num--;
 }
  return result;
}



Now here is what the compiler had to say:

Code:

*** Error 51 "E:\picprojects\pic c\menu_data.c" Line 45(2,5): A numeric expression must appear here
*** Error 51 "E:\picprojects\pic c\menu_data.c" Line 46(2,5): A numeric expression must appear here
*** Error 12 "E:\picprojects\pic c\menu_data.c" Line 48(8,11): Undefined identifier   num
*** Error 12 "E:\picprojects\pic c\menu_data.c" Line 50(13,16): Undefined identifier   num
*** Error 12 "E:\picprojects\pic c\menu_data.c" Line 52(4,10): Undefined identifier   result
*** Error 12 "E:\picprojects\pic c\menu_data.c" Line 54(3,6): Undefined identifier   num
*** Error 12 "E:\picprojects\pic c\menu_data.c" Line 56(10,16): Undefined identifier   result
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Aug 25, 2005 9:59 am     Reply with quote

Change it to the following:
Code:
short compare_array(int length, int array1[], int array2[])
{
int num;       
int result=1;

length=(length-1);
num=length;


Also, just to make sure you know it, in CCS a "short" is one bit,
and an "int" is an 8-bit unsigned value.
JGoodman



Joined: 25 Aug 2005
Posts: 8

View user's profile Send private message

PostPosted: Thu Aug 25, 2005 10:12 am     Reply with quote

Thank you,

This fixed it.

Could you explain why the ccs compliler is particular about this and gcc is not?

Thanks.

-J Goodman
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Aug 25, 2005 10:28 am     Reply with quote

The following review may help explain. The review is somewhat out of
date, for example, CCS now reports more than one error.
http://www.ccsinfo.com/forum/viewtopic.php?t=1773
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Thu Aug 25, 2005 12:03 pm     Reply with quote

JGoodman wrote:
Thank you,

This fixed it.

Could you explain why the ccs compliler is particular about this and gcc is not?

Thanks.

-J Goodman


Prior to C++ (which GCC uses by default if I remember correctly) all declarations had to occur prior to executable instructions. Good ol' C requires this. If you turn off the C++ support in GCC it would throw errors/warnings too.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
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