Path: csiph.com!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end From: gah4 Newsgroups: comp.compilers Subject: Re: What stage should entities be resolved? Date: Thu, 17 Mar 2022 17:06:15 -0700 (PDT) Organization: Compilers Central Lines: 72 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <22-03-034@comp.compilers> References: <22-03-019@comp.compilers> <22-03-025@comp.compilers> <22-03-032@comp.compilers> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="69868"; mail-complaints-to="abuse@iecc.com" Keywords: C Posted-Date: 17 Mar 2022 20:59:45 EDT X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com In-Reply-To: <22-03-032@comp.compilers> Xref: csiph.com comp.compilers:2936 On Thursday, March 17, 2022 at 11:41:47 AM UTC-7, Roger L Costello wrote: (snip) > For instance, as I understand it a C preprocessor goes through a C program and replaces macros. With this: > #define PI 3.14 > the preprocessor will convert this: > area = PI * radius * radius; > to this: > area = 3.14 * radius * radius; > But if PI is inside a quoted string: > "Today is PI day" (You missed by a few days.) > then the preprocessor does not replace PI. As well as I know it, the early preprocessor, used by K&R C, did substitute in strings. The current standard version does not, but some versions have the --traditional option which might allow it. It is not unusual to use the C preprocessor with --traditional for Fortran programs, and some compilers will automate this. Some of the processing done by the current C standard version messes up Fortran programs too much. Note, though, that the C preprocessor is pretty good at ignoring almost anything, including mismatched quotes, between #if 0 and the matching #endif The text doesn't need to look much like C at all, and can even have mismatched quotes. It does have to properly process nested #if though. The PL/I preprocessor isn't quite as forgiving. At least in the early compilers, like early C compilers, it was implemented as a separate pass, with intermediate disk file. I suspect you can't put quite as much garbage between %IF 0 %THEN %DO and %END and especially likely not unmatched quotes. (PL/I uses apostrophes for character constants, in both the language itself and the preprocessor.) Java, on the other hand, does not have a preprocessor. The compiler is supposed to know enough not to compile statements between if(0) { and } but I suspect that they need to look a lot like Java statements. (You can also use a static final variable in such an if statement, which the compiler knows how to evaluate at compile time.)