I am not an expert in the field of non-object-oriented programming languages โโof a lower level, and I am in the middle of writing C code for a project at work. I'm trying to create some decent abstract data types for work, and the googling around made me realize that people use structural ADT in two ways. Some people define a data type as a structure:
typedef struct adt { //content here } adt;
and output it to the world in the header file.
Others define a data type as a pointer to a struct:
// In .c file: typedef struct adt_s { //content here } adt_s, *adt; // In .h file: typedef struct adt_s *adt;
I understand that this approach allows you to typedef a structure without providing the outside world with any knowledge of what is inside this structure, so programmers can only use the functions presented in the same header file to work with this data type.
Are there any other reasons for choosing another? Is there a general โruleโ rule for defining ADTs as structures, and when do we define them as pointers to structures?
c struct typedef abstract-data-type
Phonon
source share