Article View: comp.std.c
Article #67Re: Typedefing built in data types
From: Dan Drake
Date: Wed, 04 Nov 1992 18:18
Date: Wed, 04 Nov 1992 18:18
37 lines
2287 bytes
2287 bytes
jkut@diku.dk (Jonatan Kutchinsky) writes: > We are writing a program in C as a computer science project, where we > simulate a Motorola 68000 processor. We decided decided to typedef the > built in types char, short, and long to new names, BYTE, WORD, and LWORD. > > The reason why we want to do this ... [reasons omitted: that there *are* reasons is enough.] > > The problem is that our teacher has the opinion that this use of typedef is > a bad thing, and that it makes the program less readable when you do not > know that LWORD really stands for long, without looking in the header file. > ... IMO your teacher is too much wedded to knowing the internal representation of everything. After many years of assembly language programming one can get into that state, and one can see C as assembly language written horizontally rather than vertically; but there are other ways of using C. C can actually be useful in hiding implementation details where they're not needed. I'm not sure I'd do it the way you have, but ten years of using the language have moved me toward the approach you're using and away from flaunting implementation details wherever possible. Besides, it's possible that your teacher's advice is actually Bad Practice. Who says the LWORD ``really stands for'' long, or BYTE for char? If you ported your simulator to another machine, you might have to define BYTE as signed char, or something, since the characteristics of the 68000 are constant, while those of the simulating machine are not. If this kind of thing is a practical possibility, then your practice is Right, and the teacher's is Wrong. I.e., your philosophical reasons for the declarations could turn out to be entirely practical; no one, least of all a professor, should be surprised when that happens. -- Dan Drake In software, the *complete* design *is* the software! drake@Autodesk.com --Hugh Lamaster
Technical Details
Message-ID:
<17865@autodesk.COM>Path:
arc1-ca.pugleaf.net!sparky!uunet!autodesk!drakeReferences:
<1992Nov3.093404.9124@odin.diku.dk>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!autodesk!drake From: drake@Autodesk.COM (Dan Drake) Newsgroups: comp.std.c Subject: Re: Typedefing built in data types Message-ID: <17865@autodesk.COM> Date: 4 Nov 92 18:18:08 GMT References: <1992Nov3.093404.9124@odin.diku.dk> Organization: Autodesk Inc., Sausalito CA, USA Lines: 37