468,537 Members | 1,844 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,537 developers. It's quick & easy.

Opaque data type

Hi All,
Could you tell how to implement opaque data type
with an example ? Or link to a documentation will
be great !!

Thanks,
Labora.

Nov 14 '05 #1
1 4797

Labora wrote:
Hi All,
Could you tell how to implement opaque data type
with an example ? Or link to a documentation will
be great !!


An opaque data type is one you can only operate on
using functions or macros. So, define your data type
somewhere and provide the stuff the users need to work
with it. They do not need to know how you organised the
data.
In fact, that is the whole point: If you reorganise
the data, then the user interface will not change --
you only have to provide other definitions for the
functions and macros.

Example: FILE from <stdio.h>.
You get a FILE * at opening a file with fopen(), can use
it to read or write to file with fputs()/fprintf() or
fgets()/fscanf() and others, respectively, can
store positions with fgetpos() (in another opaque data type)
and set positions with fsetpos() (using the return value
of a previous fgetpos() call) [there also is fseek() but
this should no longer be used nowadays] or rewind(),
can delete files, and you can close the file with fclose()
-- but you never, ever directly access an entry of FILE
(say a struct member if FILE is a structure).
Cheers
Michael
--
E-Mail: Mine is a gmx dot de address.

Nov 14 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

19 posts views Thread by Capstar | last post: by
18 posts views Thread by chankl | last post: by
3 posts views Thread by Ernesto Bascón | last post: by
3 posts views Thread by Richard Weeks | last post: by
1 post views Thread by Don Taylor | last post: by
27 posts views Thread by Nate Eldredge | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.