[OCLUG-devel] Single Element Structures
Christopher Smith
x at xman.org
Fri Sep 2 15:44:58 PDT 2005
Dan Stromberg wrote:
> C can do ADT's pretty well really, except for the information hiding part.
How so? I mean:
struct foo {
int (*method1)();
void (*method2)(int);
void* data;
};
may not be the prettiest thing, but it works quite well to hide the
underlying data structures.
> Two common data representations that might be used internally by a stack
> ADT (abstract data type) would be an array, or a linked list.
Yeah, but then you'd want to define it slightly differently from the
example described:
struct ll_stack;
struct array_stack;
#ifdef USE_LINKED_LIST
typedef ll_stack stack;
#else
typedef array_stack stack;
#endif
That way you can have both the array and linked list functions compiling
successfully simultaneously (because they will use array_stack or
ll_stack as their parameter types, not stack), and the stack-using code
will just automagically link to the right one.
> That way, any time I want to use a global variable
> named "foo", I instead refer to "global.foo", making it a hair less
> confusing when another programmer works on my code, or I revisit my own
> code years later. :)
Wouldn't it be simpler and just as good a hint to name the variable
"global_foo"?
--Chris
More information about the OCLUG-devel
mailing list