Abstract data types are not restricted to object-oriented languages like C++ and Java and should be created and used in C language programs as well. Abstract data types are most effective when used with private (opaque) data types and information hiding. Consequently, it is advantageous to implement abstract data types using opaque data types.
Non-Compliant Code Example
Wiki Markup |
---|
This non-compliant code example is based on the managed string library developed by CERT \[[Burch 06|AA. C References#Seacord 06]\]. In this non-compliant example, the managed string type, and functions that operate on this type, are defined in the include file {{string_m.h}} header file as follows: |
Code Block |
---|
|
struct string_mx {
size_t size;
size_t maxsize;
unsigned char strtype;
char *cstr;
};
typedef struct string_mx *string_m;
/* Function declarations */
extern errno_t strcpy_m(string_m s1, const string_m s2);
extern errno_t strcat_m(string_m s1, const string_m s2) ;
/* etc. */
|
...