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

Different levels of indirection

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







Different levels of indirection
PostPosted: Sun Feb 14, 2010 4:49 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Feb 14, 2010 8:33 pm     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Mon Feb 15, 2010 3:07 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Feb 15, 2010 3:32 am     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Mon Feb 15, 2010 4:30 am     Reply with quote

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







PostPosted: Mon Feb 15, 2010 5:26 am     Reply with quote

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!... Smile
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

View user's profile Send private message

PostPosted: Mon Feb 15, 2010 8:25 am     Reply with quote

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.
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