Re: Problem with function pointers and structures
- From: jt@xxxxxxxxxxx (Jens Thoms Toerring)
- Date: 3 Jul 2009 00:59:07 GMT
Simon Connah <simon.connah@xxxxxxxxxxxxxx> wrote:
On 2009-07-02 21:13:20 +0100, jt@xxxxxxxxxxx (Jens Thoms Toerring) said:
As far as I understood you this should be a pointer to the structure
with the function pointers. Then you would need here
user_interface *interface;
} user;
The you can do in the C code
user_interface ifc = { add, delete, edit );
user a_user;
a_user.interface = &ifc;
a_user.interface->add( PGconn_arg1, &a_user );
etc. Is it that what you're planning to do?
Yeah that is pretty much the plan.
I'm basically looking for a way to achieve some level of data
abstraction with my library so that client applications can perform
certain tasks on data without having to know specific implementation
details specifically the layout of the structures in use.
The real issue is to expose a public interface for manipulating the
structures which is sufficiently general to allow radical redesign of
the underlying implementation without requireing programs to be
rewritten to take advantage of new or improved code.
To me it looks a bit as if you're still in a design stage of your
project. There are still a lot of words like "some level", "certain
tasks", "sufficiently general" etc. in your problem description
that make it rather difficult to decide on a certain way of how to
implement things.
While it would most likely be easier in an object orientated language,
it is more fun in C.
It looks as if you intent to use some OO techniques implemented
in C. That definitely could be a way to go. But if it is I can't
deduced from what you have posted. All what's rather clear is
that you seem to have some "users" (perhaps going to be stored in
a database if I interpret the 'PGconn' variable correctly - it
looks a bit like you intent to use PostgreSQL and, if that's the
case, you might want to think about the question if there isn't
a way to write your program to not bind on a certain database)
to be added, changed or deleted. But that's about all what one
(or at least I) can deduce from what you've posted. But I guess
what the "client application' is going to be that has to do
"certain tasks" remains a mystery for everyone but you, so
commenting on that (and especially on how exactly to do it)
is a bit difficult.
Perhaps it would be advantageous to concentrate on the design
at the moment and not to worry too much about how to implement
it in C (or another language) at this stage. You may end up not
using C if it is to be too cumbersome for what you want to do,
or arrive at questions that are easier to answer;-)
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@xxxxxxxxxxx
\__________________________ http://toerring.de
.
- Follow-Ups:
- Re: Problem with function pointers and structures
- From: Simon Connah
- Re: Problem with function pointers and structures
- References:
- Problem with function pointers and structures
- From: Simon Connah
- Re: Problem with function pointers and structures
- From: Jens Thoms Toerring
- Re: Problem with function pointers and structures
- From: Simon Connah
- Problem with function pointers and structures
- Prev by Date: Re: Problem with function pointers and structures
- Next by Date: Re: Problem with function pointers and structures
- Previous by thread: Re: Problem with function pointers and structures
- Next by thread: Re: Problem with function pointers and structures
- Index(es):
Relevant Pages
|