linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* different access to structs
@ 2004-10-04 10:15 p.boehm
  2004-10-04 19:57 ` Suciu Flavius
  0 siblings, 1 reply; 3+ messages in thread
From: p.boehm @ 2004-10-04 10:15 UTC (permalink / raw)
  To: linux-c-programming

Hi,
in last time I played a little bit with structures. There are two types of access to it and I want
to know where are the differences.
Or better: when it makes sense to use type one and when type two ?

struct xy {
     int id;
     char *name;
};

struct abc {
     int id;
     char *name;
     struct xy st_name;            /* <-- type 1 ( ...via name(=address) ) */
     struct xy *st_ptr;            /* <-- type 2 ( ...via pointer(=address) ) */
};

void init_abc(struct abc *pt) {          /* pt points to ptr ... */
     pt->id=0;
     pt->name="test";

     pt->st_name.id=0;             /* <-- type 1 (access via name of variable) */
     pt->st_name.name="test";

     pt->st_ptr->id=0;             /* <-- type 2 (access via pointer) */
     pt->st_ptr->name="test";
}

void main(void) {
     struct abc ptr;               /* name of struct = ptr */

     init_abc(&ptr);               /* call init_abc(<address of ptr>) */
}

thanks in advance!
pb


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-10-04 19:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-10-04 10:15 different access to structs p.boehm
2004-10-04 19:57 ` Suciu Flavius
2004-10-04 15:00   ` Eric Bambach

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).