|
|
View previous topic :: View next topic |
Author |
Message |
guest Guest
|
error: different level of indirection |
Posted: Thu Jul 06, 2006 9:09 am |
|
|
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
|
|
Posted: Thu Jul 06, 2006 10:16 am |
|
|
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 |
Posted: Thu Jul 06, 2006 12:01 pm |
|
|
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
|
|
Posted: Fri Jul 07, 2006 4:09 am |
|
|
Yes. Data is an 'address' inside the function, so can be used as you show.
Best Wishes |
|
|
Ttelmah Guest
|
|
Posted: Fri Jul 07, 2006 5:09 am |
|
|
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 |
|
|
|
|
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
|