"Serve La" <
[email protected]> wrote:
This typedef is unnecessary and doesn't really do anything useful,
except confuse C++ people (in C++ struct ___ doesn't create a new name
space, the "struct" can be dropped.)
This isn't quite true. In C++ a (struct, class, union, or enum) tag
can be used alone as a type name, *if* the same name is not declared
in the same (or inner) scope as an ordinary identifier; in the latter
case, you must use an elaborated-type-specifier, that is the keyword
struct, class, union or enum plus the tag, just as you always do in C.
And to be clear this is only on references; the keyword is always
required on the declaration of the struct etc. itself.
I do it this way:
/* constructor/destructor */
struct ccHashTab * newCcHash (unsigned int size, int (* keyFn)(void
*));
int destroyCcHash (struct ccHashTab *table);
int clearCcHash (struct ccHashTab *table);
int iterateCcHash (struct ccHashTab *table,
int (* cb) (void * ctx, void * entry), void * ctx);
int insertCcHash (struct ccHashTab *table, void * entry);
int deleteCcHash (struct ccHashTab *table, void * entry);
void * findCcHash (struct ccHashTab *table, void * entry);
/* and other "methods" */
is put in hash.h, and the struct ccHashTab definition is only in the
hash module. Knowing that its a pointer to a struct doesn't really
ruin its opaqueness, if you don't know the structure contents.
However, it makes it clear that you cannot copy it without a copy
method.
Are you relying on a convention that the ctor is declared first, and
uses the struct tag in its return type, to avoid problems with the tag
being "confined" to prototype scope? I think I would put in a "struct
ccHashTab /*opaque*/ ;" to be more robust, and IMVHO clearer.
One of the things that's always bothered me is that I cannot put
"const" on the table declaration in the findCcHash function. The
reason is that you are returning a pointer that table is pointing to,
and thus the compiler cannot figure out whether or not you might
modify its contents.
I don't follow this. You mean you are returning a pointer *value*
stored, by a previous insert_, in the table? That should work fine
for a const tabtype * table, even if the contained and returned
pointer is not to const. (Even in C++, which allows adding const
"further away" than C does, but not the reverse of restricting
removing them.) Can you be more specific about the problem?
- David.Thompson1 at worldnet.att.net