home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ferkel.ucsb.edu!taco!rock!concert!rutgers!uwm.edu!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!emory!swrinde!news.dell.com!math.utexas.edu!ut-emx!jamshid
- From: jamshid@ut-emx.uucp (Jamshid Afshar)
- Newsgroups: comp.lang.c
- Subject: Re: Typedefing builtin... thanks.
- Message-ID: <83489@ut-emx.uucp>
- Date: 12 Nov 92 22:13:10 GMT
- References: <1992Nov9.150414.10221@odin.diku.dk>
- Reply-To: jamshid@emx.utexas.edu
- Organization: The University of Texas at Austin; Austin, Texas
- Lines: 40
-
- In article <1992Nov9.150414.10221@odin.diku.dk> jkut@diku.dk (Jonatan Kutchinsky) writes:
- >People generally tended to agree with me on the use of the names BYTE, WORD,
- >and LWORD to represent unsigned 8, 16, and 32 bit variables in my simulation
- >of a Motorola 68000 processor. Some even proposed the use of special
- >functions or macros for calculations, conversions to builtin types, and for
- >I/O. We are going to use this in our computer science project.
-
- I agree, but remember these typedefs are only appropriate because that
- is what your application is modeling. It would use these typedefs as
- another app would use HostID or SocialSecurityNumber. The rest of
- your code should use int, long, etc. I agree it would be a good idea
- to use functions/macros for performing the 68000 arithmetic operations
- instead of just writing
- WORD r1, w1, w2;
- /*...*/
- r1 = w1 * w2;
- especially since multiplication in the processor might result in a
- LWORD (?), while in C the result is the same type as the operands.
-
- >One stated that in his ideal program, builtin types were never used, and
- >names like f.x. Counter, and BigCounter would represent int and perhaps long,
- >depending on the machine used.
-
- I don't agree with this at all. That extra level of abstraction adds
- nothing and introduces its own complications (eg, what type specifier
- do you use for printf()?).
-
- >The major arguments used to justify these techniques were about portability.
- >A program is easier to port, when you can change some typedefs in a header
- >file, instead of changing a lot of ints to longs all over the code.
-
- I see your BYTE, WORD typedefs as increasing readability and providing
- data abstraction, which eases porting.
-
- In general you should not have to change your code from using 'int' to
- using 'long'. Use 'long' if the value might be larger than 16-bits,
- otherwise just use 'int'. Often you can use 'size_t'.
-
- Jamshid Afshar
- jamshid@emx.utexas.edu
-