I have to implement a linked list data structure in C. In "linked_list.h"
header file I have the following line:
typedef int ListDataType;
My question is, how can I terminate the program if ListDataType
is not equal to int
? I know that the preprocessor can't prevent my program from compiling in case this requirement is not met (because it knows nothing about typedef
s).
I code in C11, and I know about _Generic
keyword. How can I avoid writing such things as the following?
{
ListDataType q;
const bool kListDataTypeIsNotInt = _Generic(q, int: false, default: true);
if (kListDataTypeIsNotInt) {
print_error_message_and_exit("list data types other than int are not supported");
}
}
Should I use the macro (#define LIST_DATA_TYPE int
) instead?