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.