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

problem with pointers

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



Joined: 10 Feb 2011
Posts: 241
Location: Vancouver, BC

View user's profile Send private message

problem with pointers
PostPosted: Thu Feb 17, 2011 1:14 pm     Reply with quote

Hi There,

I think I'm running into some kind of problems with my pointers... Surprised

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:
Code:
data[0]->value
- how come? Evil or Very Mad
jacqueskleynhans



Joined: 10 Apr 2008
Posts: 109
Location: Cape Town, South Africa

View user's profile Send private message

PostPosted: Thu Feb 17, 2011 2:43 pm     Reply with quote

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

View user's profile Send private message

Re: problem with pointers
PostPosted: Thu Feb 17, 2011 2:59 pm     Reply with quote

cerr wrote:
Hi There,

I think I'm running into some kind of problems with my pointers... Surprised

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:
Code:
data[0]->value
- how come? Evil or Very Mad


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

View user's profile Send private message

Re: problem with pointers
PostPosted: Thu Feb 17, 2011 5:03 pm     Reply with quote

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

View user's profile Send private message

Re: problem with pointers
PostPosted: Thu Feb 17, 2011 5:04 pm     Reply with quote

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