home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!ira.uka.de!math.fu-berlin.de!news.th-darmstadt.de!rbg.informatik.th-darmstadt.de!misar
- From: misar@rbg.informatik.th-darmstadt.de (walter misar)
- Subject: Re: Questions about token merging and trigraphs
- Sender: news@news.th-darmstadt.de (The News System)
- Message-ID: <1992Dec14.105753@rbg.informatik.th-darmstadt.de>
- Date: Mon, 14 Dec 1992 09:57:53 GMT
- References: <42098@pprg.eece.unm.edu.pprg.unm.edu>
- Nntp-Posting-Host: rbhp60.rbg.informatik.th-darmstadt.de
- Organization: TU Darmstadt
- Lines: 63
-
- In article <42098@pprg.eece.unm.edu.pprg.unm.edu>, ele@chama.eece.unm.edu writes:
- >
- > Two questions about ANSI C:
- >
- > (1) How is the preprocessor token merging mechanism (##) supposed to
- > be used? I know, for example that if you have
- >
- > #define X(i) x ## i
- >
- > then the preprocessor will replace code like 'X(1)' with 'x1', but
- > could someone give me an example of where this (or some other use of
- > '##') would be useful?
-
- I used it once
- /* flags */
-
- #define F_C 1<<0 /* Carry */
- #define F_Z 1<<1 /* Zero */
- #define F_I 1<<2 /* Interrupt */
- #define F_D 1<<3 /* Decimal */
- #define F_B 1<<4 /* Break */
- #define F__ 1<<5 /* - unused - */
- #define F_V 1<<6 /* oVerflow */
- #define F_N 1<<7 /* Negative */
-
- #define SET(flag) (P|=(F_##flag))
- #define CLR(flag) (P&=(~F_##flag))
- #define EQU(flag,val) ((val)?SET(flag):CLR(flag))
- #define QUERY(flag) (!!(P&F_##flag))
-
- Now you can call SET(C) and it will set the C-flag (BTW this flags are 6502).
-
-
- > (2) There is a command-line switch to disable the 'trigraph' feature
- > in the gcc compiler. What are trigraphs? From the comments in the
- > gcc documentation I gather that they are something that the ANSI
- > committee has added to C and that Richard Stallman doesn't care for
- > them. If that is the case, I'm wondering what purpose the ANSI
- > committee saw for them, why anyone would object to them, and, most
- > importantly, what they are.
-
- Trigraphs are only of interest, if your machine hasn't got a full set of ASCII
- characters. All begin with ??, only following nine replacements take place:
- ??( [ ??< { ??' ^
- ??) ] ??> } ??- ~
- ??= # ??! | ??/ \
- The replacement takes effect before any other preprocessor action, thus ??/
- may be used at the end of a line to merge it with the next. In general, I can't
- see a good reason for it - I can't believe one will actually programm s.th like
- this (Yeah it's ANSI)
-
- ??=include <stdio.h>
- int main(int argc,char * argv??(??))
- ??<
- printf("Hello world !")
- return 0;
- ??>
-
- Worse, trigraph can turn otherwise correct programs into garbage (especially
- ??! is a prime candidat)
- --
- Walter Misar It is impossible to enjoy idling thoroughly
- misar@rbg.informatik.th-darmstadt.de unless one has plenty of work to do.
-