Path: utzoo!utgpu!water!watmath!clyde!att!rutgers!apple!bloom-beacon!husc6!xait!g-rh From: g-rh@XAIT.Xerox.COM (Richard Harter) Newsgroups: comp.lang.c Subject: Re: Abstract Data Types in C Keywords: Abstract Data Types ADT modules Message-ID: <35136@XAIT.Xerox.COM> Date: 16 Oct 88 00:02:02 GMT References: <116@capshaw.UUCP> Reply-To: g-rh@XAIT.Xerox.COM (Richard Harter) Organization: Xerox Corporation, Cambridge, Massachusetts Lines: 47 In article <116@capshaw.UUCP> sdc@capshaw.UUCP (Dan Capshaw) writes: >A friend that does a lot of program development in PASCAL has >found that using Abstract Data Types (ADTs) significantly >increases his productivity by minimizing his debugging time... >One reason my friend doesn't like C is because he doesn't feel >ADTs can be used effectively in C. But to me, it seems like he is >just describing standard function calls where the interface is defined >but how the function performs its job may not be. So...I don't see >the advantage of ADTs and how they are superior to the structured >programming techniques that I have been using for years. >Is anyone out there using ADTs in C? If so, am I missing something >here? And finally, if ADTs are not as I have described them, what >are they, and how can they be used in C (if in fact they should be used >in C)? Your friend is full of hooey -- you can do ADT's in C just as readily as you can in P****L. On the other hand an ADT is somewhat more than your description. The point of an abstract data type is that you can create types that are not originally part of the language. A language which supports ADT's lets you, in effect, extend the language by adding types. For a simple example, suppose that you wanted to extend C to add complex variables. You would want to be able to declare things as complex, extract the real and imaginary parts, do arithmetic operations and so. Now in a language which has complex variables you can do all these things without knowing the details of how the compiler handles your code; indeed you can't get at the details. How would you go about setting this up in C? Well, you would create an include file with a typedef for COMPLEX as a struct of a pair of doubles, and define macros for the sundry arithmetic operators. If you wanted a more complicated type, linked lists for example, you might need some functions, so you would create a package. This would consist of an include file that has the public declarations and macros, and an implementation file that has the associated functions and private variables. The advantage of abstract data types (and related concepts) is that you can operate at a higher level of generality -- implementation details can be taken care of once instead of being replicated from instance to instance. The idea is more general than that of a black box function. As to whether it is worthwhile in C or any other LLHLL (lower level high level language) is a matter of the application and your approach to software. -- In the fields of Hell where the grass grows high Are the graves of dreams allowed to die. Richard Harter, SMDS Inc.