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

Where local variables are stored in c?

747


What is c variable?

799


How are structure passing and returning implemented?

776


Write a program to print all permutations of a given string.

941


What is void pointers in c?

779


about c language

1799


How can I ensure that integer arithmetic doesnt overflow?

834


Explain the use of function toupper() with and example code?

866


why to assign a pointer to null sometimes??how can a pointer we declare get assigned with a garbage value by default???

1722


How can I do peek and poke in c?

845


What is s or c?

797


Why isnt there a numbered, multi-level break statement to break out

815


I have a varargs function which accepts a float parameter?

797


4-Take two sets of 5 numbers from user in two arrays. Sort array 1 in ascending and array 2 in descending order. Perform sorting by passing array to a function mySort(array, sortingOrder). Then multiply both the arrays returned from function, using metric multiplication technique in main. Print result in metric format.

1963


What does 3 mean in texting?

826