Re: What stage should entities be resolved?

gah4 <gah4@u.washington.edu>
Thu, 17 Mar 2022 17:06:15 -0700 (PDT)

          From comp.compilers

Related articles
Re: What stage should entities be resolved? christopher.f.clark@compiler-resources.com (Christopher F Clark) (2022-03-12)
Re: What stage should entities be resolved? DrDiettrich1@netscape.net (Hans-Peter Diettrich) (2022-03-14)
Re: What stage should entities be resolved? costello@mitre.org (Roger L Costello) (2022-03-15)
Re: What stage should entities be resolved? DrDiettrich1@netscape.net (Hans-Peter Diettrich) (2022-03-18)
Re: What stage should entities be resolved? gah4@u.washington.edu (gah4) (2022-03-17)
Re: What stage should entities be resolved? 480-992-1380@kylheku.com (Kaz Kylheku) (2022-03-18)
Re: What stage should entities be resolved? gah4@u.washington.edu (gah4) (2022-03-18)
Re: What stage should entities be resolved? martin@gkc.org.uk (Martin Ward) (2022-03-19)
Re: What stage should entities be resolved? matt.timmermans@gmail.com (matt.ti...@gmail.com) (2022-03-20)
| List of all articles for this month |
From: gah4 <gah4@u.washington.edu>
Newsgroups: comp.compilers
Date: Thu, 17 Mar 2022 17:06:15 -0700 (PDT)
Organization: Compilers Central
References: 22-03-019 22-03-025 22-03-032
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
In-Reply-To: 22-03-032

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.)


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.