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 does it mean when a pointer is used in an if statement?

594


What are different types of operators?

589


Under what circumstances does a name clash occur?

682


When should you not use a type cast?

650


Is there a way to compare two structure variables?

610






What is malloc return c?

593


Why clrscr is used after variable declaration?

1032


which of the following is allowed in a "C" arithematic instruction a) [] b) {} c) () d) none of the above

1121


What is the difference between array and linked list in c?

591


Explain what are reserved words?

629


What are the different types of linkage exist in c?

603


How can I trap or ignore keyboard interrupts like control-c?

606


Explain what is the benefit of using an enum rather than a #define constant?

709


Explain what is the difference between functions abs() and fabs()?

611


How can I manipulate strings of multibyte characters?

630