|
|
View previous topic :: View next topic |
Author |
Message |
onionrack Guest
|
Different levels of indirection |
Posted: Sun Feb 14, 2010 4:49 pm |
|
|
I am trying to pass variable arrays from a function, but get the compile error 105 Different levels of indirection. The same code works in Visual C++. Is this me, or a compiler 4.104 fault please? I've tried PCH and PCD with same result:
Code: |
#use rs232(UART1,baud=9600,parity=N,bits=8)
int can=1;
void my_function(unsigned int &one, unsigned int *two){
one=69;
two[0]=2;
two[1]=3;
two[2]=7;
}
void main()
{
unsigned int three[4];
unsigned int two[4][8];
my_function(three[can],two[can]);
three[0]=999;
printf("%u %u %u %u %u",three[0], three[1], two[can][0], two[can][1], two[can][2]);
while(true);
}
|
Thank you! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Feb 14, 2010 8:33 pm |
|
|
Quote: | The same code works in Visual C++. |
CCS is not C++. If you compile your program as a .c file in
Visual C++ then you get errors.
I tested this with MSVC++ 6.0. |
|
|
tinley
Joined: 09 May 2006 Posts: 67
|
|
Posted: Mon Feb 15, 2010 3:07 am |
|
|
Thanks PCM P,
I am aware that C is not C++, but the syntax I have used is C ANSI/ISO according to 'C The Complete Reference', so should work.
Can you or anyone suggest a workaround to pass variable arrays please. I don't really want to re-write the function, as it is the standard can_getd() from the CCS can-dsPIC30.c
Thanks! |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Mon Feb 15, 2010 3:32 am |
|
|
You're following the bad habbit not to tell, which line of code and partial expression gives the error.
The problem occurs when the "Reference Parameter" argument unsigned int &one is supplied with a
non-constant array element, don't know why. The problem isn't specific to V4.104 however. It's no standard
C Syntax, so I don't use it in my code. You can use a C standard pointer unsigned int *one instead.
P.S.: I understand, that you're problem is in the extensive usage of "reference parameters" in the
CCS supplied can driver. Personally, I would rewrite the driver code.
Furthermore, the problem is a basic restriction of the CCS "reference parameter" concept. It doesn't work
with variable array elements, because it uses an absolute variable address in the function code
instead of a pointer. |
|
|
tinley
Joined: 09 May 2006 Posts: 67
|
|
Posted: Mon Feb 15, 2010 4:30 am |
|
|
Thanks FvM,
Your input gives good insight and at this point I shall modify the CCS can library so it does what I want! There are many badly documented aspects of this 'nearly' C compiler, especially the PCD version, so thanks to this forum and your time!
Sorry for my bad habits... oversight, not intention.
Cheers |
|
|
Ttelmah Guest
|
|
Posted: Mon Feb 15, 2010 5:26 am |
|
|
CCS, is very close to 'C' (original K&R version). What it misses (still), is getting close to 'ANSI C'....
I'd reckon that 99.5% of C constructs work with CCS, but perhaps only about 90% of ANSI C constructs, especially more 'complex' steps like reference parameters, work 'fully'....
If you stick to original C syntax, CCS is a lot easier to use!...
Some of it is still to do with hardware. In this example, CCS are trying to save complexity in the code, by 'pre-solving' at compile time, the reference parameters. Works well for constant parameters, but makes variable ones effectively a 'no-no'. Advantage smaller code size, but reduces flexibility. :(
Best Wishes |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Mon Feb 15, 2010 8:25 am |
|
|
When you say, reference parameter is an ANSI C feature, can tell which clause of the specification defines it? I couldn't find it yet. |
|
|
|
|
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
|