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

error: different level of indirection

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







error: different level of indirection
PostPosted: Thu Jul 06, 2006 9:09 am     Reply with quote

Compiling the code:

#INCLUDE <16f876>
#FUSES HS,NOWDT,NOPROTECT,NOLVP


long read[10];
long sum;

// function
void read_value (long &data)
{
data=1234;
}

// main
main()
{
int i,j;

while(1)
{
i=0;
while (i<4)
{
read_value(read[i]);
i=i+1
}
for (j=0; j<4; j++)
{
sum=sum+read[i];
}
}
}



I receive the error message: different level of indirection
Can you explain to me the meaning of that message?

Thank you
Ttelmah
Guest







PostPosted: Thu Jul 06, 2006 10:16 am     Reply with quote

You are using 'reference parameters'. This gives the ability to access a parameter 'inside' a function, as if you were talking to the parameter outside. This is done by effectively passing the address of the parameter, and then working with that address inside the function, but with this 'hidden' from you as a user. Now support fo this ability is very limited in CCS (it is a C++ extension, which CCS only supports in it's simplest form). As such, it only supports parameters that are at a fixed location in memory, which it handles efficiently, by generating a direct access. This however prevents the ability from being used to access things at varying addresses. You are tying to pass a parameter that changes location between calls.
The error message is beautifully 'non informative'...
Use the normal C command, instead of reference paramters, and code as:
Code:


// function
void read_value (long *data)
{
*data=sum;
}

//then access the value with:

       read_value(&read[i]);


Best Wishes
guest
Guest







Thank you
PostPosted: Thu Jul 06, 2006 12:01 pm     Reply with quote

Thank you

But now I don't know how to use the command

shift_left(address, number of bytes, value)

in the function.

Is it right if I write:

sdhitft_left(data,2,value)?
Ttelmah
Guest







PostPosted: Fri Jul 07, 2006 4:09 am     Reply with quote

Yes. Data is an 'address' inside the function, so can be used as you show.

Best Wishes
Ttelmah
Guest







PostPosted: Fri Jul 07, 2006 5:09 am     Reply with quote

As a general 'comment', it is worth designing your variable 'style', to make it plain when you are working with a pointer. In K&R, they tend to use variables ending in 'p', for their pointers, while Microsoft, for all their faults, use data types like 'lp' for 'long pointer'. So, if you declare something like:
Code:

// function
void read_value (long *ptrtolong_data) {
*ptrtolong_data=sum;
}

It makes it much easier when you get to something that wants an address, to 'remember' that this is allready a 'pointer', and what data type it points to.
With some care, this sort of deliberately informative style, can massively reduce latter problems.
Just worth 'bearing in mind'.

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