Comment

Comment by steiger

Wouldn't it be preferable to write only a forward declaration of the struct in the header files, and define the structs themselves at the .c files? In other words, wouldn't it be better to define them as Abstract Data Types (ADT) ?

That way, users of the library would have no direct access to the fields of the struct (e.g. hashtable->num_buckets;), they'd have to use a function declared at the correspondent header file. (e.g. get_num_buckets(hashtable);).

Direct access to member fields could break the data structure because data structures always needs to follow certain rules in insertion and deletion.

parent steiger 8 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton