View previous topic :: View next topic |
Author |
Message |
JGoodman
Joined: 25 Aug 2005 Posts: 8
|
Why is my functional function not functioning??? |
Posted: Thu Aug 25, 2005 9:46 am |
|
|
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
|
|
Posted: Thu Aug 25, 2005 9:59 am |
|
|
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
|
|
Posted: Thu Aug 25, 2005 10:12 am |
|
|
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
|
|
|
rwyoung
Joined: 12 Nov 2003 Posts: 563 Location: Lawrence, KS USA
|
|
Posted: Thu Aug 25, 2005 12:03 pm |
|
|
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! |
|
|
|