home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / pctchnqs / 1991 / number6 / intmanip.h < prev    next >
Text File  |  1991-11-04  |  1KB  |  40 lines

  1. typedef unsigned char byte;
  2. typedef unsigned short word;
  3. typedef unsigned long dword;
  4.  
  5. #if defined(__cplusplus)
  6. // Address low byte of a word.
  7. inline byte &lowb(word &x) {
  8. return (*(byte *)&x);
  9. }
  10. // Address high byte of a word.
  11. inline byte &hib(word &x) {
  12. return (*((byte *)&x + 1));
  13. }
  14. // Address low byte of a dword.
  15. inline byte &lowb(dword &x) {
  16. return (*(byte *)&x);
  17. }
  18. // Address high byte of a dword.
  19. inline byte &hib(dword &x) {
  20. return (*((byte *)&x + 3));
  21. }
  22. // Address low word of a dword.
  23. inline word &loww(dword &x) {
  24. return (*(word *)&x);
  25. }
  26. // Address high word of a dword.
  27. inline word &hiw(dword &x) {
  28. return (*((word *)&x + 1));
  29. }
  30. #else
  31. /* Address low byte of a word or dword. */
  32. #define lowb(x)  (*(byte *)&x)
  33. /* Address high byte of a word or dword. */
  34. #define hib(x)   (*((byte *)&x + sizeof(x) - 1))
  35. /* Address low word of a dword. */
  36. #define loww(x)  (*(word *)&x)
  37. /* Address high word of a dword. */
  38. #define hiw(x)   (*((word *)&x + 1))
  39. #endif
  40.