home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / c / 16429 < prev    next >
Encoding:
Internet Message Format  |  1992-11-12  |  2.4 KB

  1. 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
  2. From: jamshid@ut-emx.uucp (Jamshid Afshar)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Typedefing builtin... thanks.
  5. Message-ID: <83489@ut-emx.uucp>
  6. Date: 12 Nov 92 22:13:10 GMT
  7. References: <1992Nov9.150414.10221@odin.diku.dk>
  8. Reply-To: jamshid@emx.utexas.edu
  9. Organization: The University of Texas at Austin; Austin, Texas
  10. Lines: 40
  11.  
  12. In article <1992Nov9.150414.10221@odin.diku.dk> jkut@diku.dk (Jonatan Kutchinsky) writes:
  13. >People generally tended to agree with me on the use of the names BYTE, WORD,
  14. >and LWORD to represent unsigned 8, 16, and 32 bit variables in my simulation
  15. >of a Motorola 68000 processor. Some even proposed the use of special 
  16. >functions or macros for calculations, conversions to builtin types, and for
  17. >I/O. We are going to use this in our computer science project.
  18.  
  19. I agree, but remember these typedefs are only appropriate because that
  20. is what your application is modeling.  It would use these typedefs as
  21. another app would use HostID or SocialSecurityNumber.  The rest of
  22. your code should use int, long, etc.  I agree it would be a good idea
  23. to use functions/macros for performing the 68000 arithmetic operations
  24. instead of just writing
  25.     WORD r1, w1, w2;
  26.     /*...*/
  27.         r1 = w1 * w2;
  28. especially since multiplication in the processor might result in a
  29. LWORD (?), while in C the result is the same type as the operands.
  30.  
  31. >One stated that in his ideal program, builtin types were never used, and
  32. >names like f.x. Counter, and BigCounter would represent int and perhaps long,
  33. >depending on the machine used.
  34.  
  35. I don't agree with this at all.  That extra level of abstraction adds
  36. nothing and introduces its own complications (eg, what type specifier
  37. do you use for printf()?).
  38.  
  39. >The major arguments used to justify these techniques were about portability.
  40. >A program is easier to port, when you can change some typedefs in a header
  41. >file, instead of changing a lot of ints to longs all over the code.
  42.  
  43. I see your BYTE, WORD typedefs as increasing readability and providing
  44. data abstraction, which eases porting.
  45.  
  46. In general you should not have to change your code from using 'int' to
  47. using 'long'.  Use 'long' if the value might be larger than 16-bits,
  48. otherwise just use 'int'.  Often you can use 'size_t'.
  49.  
  50. Jamshid Afshar
  51. jamshid@emx.utexas.edu
  52.