View previous topic :: View next topic |
Author |
Message |
cerr
Joined: 10 Feb 2011 Posts: 241 Location: Vancouver, BC
|
problem with pointers |
Posted: Thu Feb 17, 2011 1:14 pm |
|
|
Hi There,
I think I'm running into some kind of problems with my pointers...
I defined a Code: | typedef struct {
int16 value;
char id;
} eevalues; |
and then an array of these values like this:
Code: | eevalues store[VARNUM] |
and I pass it to a function as a eevalues *data pointer but in the function i can't access the values anymore :( I only get 0s trying to access it like this:
- how come? |
|
|
jacqueskleynhans
Joined: 10 Apr 2008 Posts: 109 Location: Cape Town, South Africa
|
|
Posted: Thu Feb 17, 2011 2:43 pm |
|
|
These forums are valuable resources have a look around and also try searching for your problem elements.
http://www.ccsinfo.com/forum/viewtopic.php?t=44697&highlight=struct
This might not help but it contains some struct examples. Also I found a google search with maybe something like struct and pointer with CCS. usually narrows a search better than using ccs search.
Best of luck
Jacques _________________ "THE ONLY EASY DAY WAS YESTERDAY" |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
Re: problem with pointers |
Posted: Thu Feb 17, 2011 2:59 pm |
|
|
cerr wrote: | Hi There,
I think I'm running into some kind of problems with my pointers...
I defined a Code: | typedef struct {
int16 value;
char id;
} eevalues; |
and then an array of these values like this:
Code: | eevalues store[VARNUM] |
and I pass it to a function as a eevalues *data pointer but in the function i can't access the values anymore :( I only get 0s trying to access it like this:
- how come? |
Did you try data[0].value ??
I do this stuff all the time...
And if you look in the K&R C programming Lanuage , you'll see that your use of '->' is incorrect as -> is used when the pointed structure is a pointer... which you don't have up there.
Check page 128-131 of K&R's "The C Programming Language" for more verbose usage to help you along.
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
cerr
Joined: 10 Feb 2011 Posts: 241 Location: Vancouver, BC
|
Re: problem with pointers |
Posted: Thu Feb 17, 2011 5:03 pm |
|
|
bkamen wrote: |
And if you look in the K&R C programming Lanuage , you'll see that your use of '->' is incorrect as -> is used when the pointed structure is a pointer... which you don't have up there.
|
Exactly right, -> is used to dereference (it's the same as (*XYZ)) and i had a brain fart there and didn't realize that. But why would the code compile at all? I would ixpect it to throw an error like value is not an element of data* or similar... |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
Re: problem with pointers |
Posted: Thu Feb 17, 2011 5:04 pm |
|
|
cerr wrote: | bkamen wrote: |
And if you look in the K&R C programming Lanuage , you'll see that your use of '->' is incorrect as -> is used when the pointed structure is a pointer... which you don't have up there.
|
Exactly right, -> is used to dereference (it's the same as (*XYZ)) and i had a brain fart there and didn't realize that. But why would the code compile at all? I would ixpect it to throw an error like value is not an element of data* or similar... |
(shrug)
Cheers,
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
|