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