J
jacob navia
Le 27/06/12 18:36, Stefan Ram a écrit :
No, the actual "List" structure mustn't be disclosed at all since you
always work with POINTERS to that incomplete type and never with
the type itself.
This is the beauty of C "private" types: they are REALLY private
and you have absolutely NO CLUE at all what they actually are.
Interface and implementation are then completely separated. I can
(and have) changed the list structure several times without ever
needing to change client code.
More: Old code that was compiled long ago when the list structure
was different will STILL WORK.
Ok, I see. LIST_SIZE must be either »sizeof List« or a
programmer-written literal, such as »104«, which is
error-prone.
(One could generate a header file »#define LIST_SIZE 104«
during the make process using means beyond the C language
only.)
However, in your code, you have:
List *L = (List *)&buffer[0];
. Doesn't this also mean that »List« must be disclosed to
the client, which, as I understand it, is the actual list
header structure?
No, the actual "List" structure mustn't be disclosed at all since you
always work with POINTERS to that incomplete type and never with
the type itself.
This is the beauty of C "private" types: they are REALLY private
and you have absolutely NO CLUE at all what they actually are.
Interface and implementation are then completely separated. I can
(and have) changed the list structure several times without ever
needing to change client code.
More: Old code that was compiled long ago when the list structure
was different will STILL WORK.