home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / os / vms / 20735 < prev    next >
Encoding:
Internet Message Format  |  1993-01-11  |  1.7 KB

  1. Path: sparky!uunet!cs.utexas.edu!uwm.edu!linac!att!ucbvax!gwdgv1.dnet.gwdg.de!moeller
  2. From: moeller@gwdgv1.dnet.gwdg.de ("GWDGV1::MOELLER")
  3. Newsgroups: comp.os.vms
  4. Subject: RE: 'ASSUME' macro in VAXC?
  5. Message-ID: <9301111746.AA08569@ucbvax.Berkeley.EDU>
  6. Date: 11 Jan 93 17:41:59 GMT
  7. Sender: daemon@ucbvax.BERKELEY.EDU
  8. Distribution: world
  9. Organization: The Internet
  10. Lines: 42
  11.  
  12. Kenn Humborg <elehumborg@orbsen.ucg.ie> asks:
  13. > Does anybody know any way of implementing compile-time checking in VAXC
  14. > similar to the ASSUME macro defined in LIB.MLB (or is it STARLET?)?
  15. >
  16. > What I want to check for specifically is that the size of a certain struct
  17. > is equal to 512 bytes and if not, print a warning message.
  18. >
  19. > Say:
  20. > check sizeof(struct foo) "Error: foo is the wrong size"
  21. >
  22. > I don't really mind how kludgy the solution would have to be, as long as
  23. > it works.
  24.  
  25. No way to have the compiler issue (only) an error message of your choice,
  26. but how about this:
  27.  
  28. | #define assume(condition) { int assumption_failed[(condition) ? 1 : 0]; }
  29. |
  30. | /* example */
  31. | main()
  32. | {
  33. |    struct x { int a; } xx;
  34. |
  35. |    assume(sizeof(xx) == 512)
  36. | }
  37.  
  38. | $ cc <...>
  39. |         assume(sizeof(xx) == 512)
  40. | %CC-E-INVARRAYBOUND, The declaration of "assumption_failed" specifies
  41. |        a missing or invalid array bound.
  42. |        At line number 8 in <...>
  43. |...
  44. | %CC-I-NOBJECT, No object file produced.
  45. |...
  46.  
  47. NB. For the macro to operate correctly when the condition is satisfied,
  48. it must be invoked *within* a function.
  49.  
  50. Wolfgang J. Moeller, GWDG, D-3400 Goettingen, F.R.Germany | Disclaimer ...
  51. PSI%(0262)45050352008::MOELLER      Phone: +49 551 201516 | No claim intended!
  52. Internet: moeller@gwdgv1.dnet.gwdg.de   | This space intentionally left blank.
  53.  
  54.