How can I implement opaque (abstract) data types in C?
What's the difference between these two declarations?

struct x1 { ... };
typedef struct { ... } x2;

Answer Posted / pankaj

Abstract data type in C can be implemented using structures :
struct abstract;
typedef struct abstract abstract_type;

Note that this didn't define the struct abstract fully, only an opaque struct. sizeof() can be used on it. Memory can be allocated by using some macros and typecasted into this type.

Is This Answer Correct ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the purpose of void pointer?

816


What is the use of function in c?

955


What does the c preprocessor do?

869


How do you convert a decimal number to its hexa-decimal equivalent.Give a C code to do the same

898


What does do in c?

807


What is scope and lifetime of a variable in c?

807


What does s c mean in text?

850


What is the correct code to have following output in c using nested for loop?

858


How to draw the flowchart for structure programs?

8991


What is string function in c?

767


How can I determine whether a machines byte order is big-endian or little-endian?

852


What is the use of a conditional inclusion statement in C?

857


Where does the name "C" come from, anyway?

894


What are directives in c?

755


What is static and auto variables in c?

809