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 CCS Technical Support

Pointers

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



Joined: 20 Jul 2004
Posts: 34

View user's profile Send private message Send e-mail

Pointers
PostPosted: Tue Mar 22, 2005 4:37 am     Reply with quote

Hi again,

Many Q's when using a new compiler ;-)

I have gotten myself into trouble when trying to use pointers to arrays in the CCS compiler. Surely I am doing someting I am not supposed to.

Example:

MyMain
{
int8 myVar[8];

myVar[0] = 0x99;
MyFunction(myVar);

}

MyFunction(*int8 my_array)
{
int8 localVar;
localVar = my_array[0];
}

Now, localVar will NOT get the value 0x99.

Obviously, the argument I am passing is not the adress as I intended it to be. Probably a very simple programmers error, would someone care to bail me out?

//Daniel
Ttelmah
Guest







PostPosted: Tue Mar 22, 2005 5:30 am     Reply with quote

Actually the argument you are passing is the address you are expecting. It is the declaration in the function, that is wrong. The syntax should be:

MyFunction(int8 *my_array)

Which says that 'my_array' is a pointer to an int8.

Best Wishes
d00dajo



Joined: 20 Jul 2004
Posts: 34

View user's profile Send private message Send e-mail

Correction
PostPosted: Tue Mar 22, 2005 6:12 am     Reply with quote

Ttelmah wrote:
Actually the argument you are passing is the address you are expecting. It is the declaration in the function, that is wrong. The syntax should be:

MyFunction(int8 *my_array)

Which says that 'my_array' is a pointer to an int8.

Best Wishes


Hi Ttelmah, thx for your response,
Sorry the syntax in the example was a typo.
Actually it was supposed to be:
MyFunction(int8* my_array)


The thing is, I have found that the function actually DOES work. But only when I am in one of the lower function calls.
More exactly:

Global: int8 array[8];

void main(void)
{
array[0]=0x99;
myFunction(array);
}
This will work fine. However, the following code WILL NOT WORK:

void main(void)
{
...
Function1();
}

void Function1()
{
...
Function2();
}

void Function2()
{
...
array[0]=0x99;
myFunction(array);
}



This seems very strange, since the dataarraystructure is global so it should not matter where in the code I make the call (since it cannot be stack-related when I set the value just prevoius to the call)

I realise this isnt really a simple question to ask, when all of the code is not known. But ideas are greatly appreciated.
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