Structs and pointers

T

Timur Ametov

Hi,

i know, it would be very stupid question, but i'm c-beginner and i haven't
found the answer in books. Ok, here it is.

I have:
typedef struct {
cdContext contextH;
/* stream I/O function pointers */
cdSOpen* open;
cdSClose* close;
cdSRead* read;
cdSWrite* write;
cdSSeek* seek;
cdSTell* tell;
} cdStream;

If i declare MyStream:
cdStream MyStream;
... how can i use its properties, that are pointers?

So: (*MyStream).open .. ?
Or maybe so: MyStream->open?
or so: *(MyStream.open)?
or so:MyStream.(*open)?
Or all of them are wrong?

Thanx.
 
M

Michiel.Salters

Timur said:
Hi,

i know, it would be very stupid question, but i'm c-beginner and i haven't
found the answer in books.

You're probably looking for our neighbours, comp.lang.c because C and
C++
are different languages.
The code that you included is C code, and while C++ understands it,
it's
not how you'd write these things in C++ at all.

Do check the C Faq, though, it's good.

Michiel.
 
K

Kaliven Lee

Timur Ametov дµÀ:
Hi,

i know, it would be very stupid question, but i'm c-beginner and i haven't
found the answer in books. Ok, here it is.

I have:
typedef struct {
cdContext contextH;
/* stream I/O function pointers */
cdSOpen* open;
cdSClose* close;
cdSRead* read;
cdSWrite* write;
cdSSeek* seek;
cdSTell* tell;
} cdStream;

If i declare MyStream:
cdStream MyStream;
.. how can i use its properties, that are pointers?

So: (*MyStream).open .. ?
Or maybe so: MyStream->open?
or so: *(MyStream.open)?
or so:MyStream.(*open)?
Or all of them are wrong?

Thanx.
My point of view , the usage is as below:
(Mystream.open)()
Mystream is a object of the struct.
open is one of its variable.
 
B

Bari

The way to use it dependce on the object you have:
If you defined cdStream as pointer the way to use its properties is:
cdStream->open
If cdStream is not a pointer the way to use its properties is:
cdStream.open

because open is a function to a pointer you should use it exactly like
it was a function:
cdStream->open(), or
cdStream.open().

Regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top