473,386 Members | 1,754 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 5039

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Capstar | last post by:
Hi NG, I've read some time ago in this NG, that when you're writing a library it can be good practice to use an opaque type to point to your structures if the user doesn't need to modify the...
2
by: Kurt Ng | last post by:
Hi, y'all. Can anyone help me on this problem? I'm working with a third-party C dll, and I'm having trouble importing into C# the dll's methods that return one of the dll's defined types,...
18
by: chankl | last post by:
Can anyone explain what's an opaque pointer and how it's implemented in C? I read about this concept in the book "C interfaces and implementations". Here's an example from the book (list.h -...
3
by: Ernesto Bascón | last post by:
Hi everybody: I have two questions: 1. I'm using opaque pointers in my classes to hide their data structures; there is a way to use opaque pointers in template classes; since the...
3
by: Richard Weeks | last post by:
I have a library of functions for operations on complex numbers and a complex type defined as a struct in a header also containing the prototypes for the library. I want to make this an opaque...
1
by: Don Taylor | last post by:
I want to build an application in Python that can show an opaque window so that you can still see and type into any window that it covers. Sort of like a software mylar transparency sheet placed...
1
by: bantunks | last post by:
Hello, I am trying to figure out the advantages and disadvantages of exposing interfaces through Opaque data types in C. I have figured/found out the following two advantages 1. Higher level of...
27
by: Nate Eldredge | last post by:
Consider the following pseudo-code: #include <opaque.h> struct foo { int a; opaque_t op; int b; };
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.