MC logo

ADT Declarations in C

  Practice Questions

Assume we are implementing an abstract data type in C, called FrobZoid. We have a header file, frob.h, an implementation file frob.c, and a program which uses the ADT in user.c. Answer the following:
  1. Where, if anywhere, would you need #include "frob.h"?

  2. Where, if anywhere, would you need #include "frob.c"?

  3. Which files, if any, would need to be compiled?

  4. What declaration(s) or definition(s) would be needed to define a function int make_frob(int m) which was part of the user interface? Say where this/these declaration(s) or definition(s) should be placed.

  5. What happens if the ADT correctly defines int make_frob(int m) as part of the user interface, but the code in user.c incorrectly contains the call make_frob("Hi", 4.5)?

  6. What declaration(s) or definition(s) would be needed to define a function void ruminate_frob(int m) which was local to the implementation, and unknown to the user program? Say where this/these declaration(s) or definition(s) should be placed.

  7. What declaration(s) or definition(s) would be needed to define an integer frob_count which is managed by the implementation, and available to the user code? Say where this/these declaration(s) or definition(s) should be placed.

  8. What declaration(s) or definition(s) would be needed to define an integer frob_code_id which is private to the implementation, and unavailable to the user program? Say where this/these declaration(s) or definition(s) should be placed.

  9. What happens if frob.c defines a function void bogus(int i) { ... }, user.c makes a call bogus(2.5), and frob.h does not define the name bogus at all?

<<Dynamic Allocation in C Answer