Path: csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.std.c Subject: Re: Interaction between conditional inclusion and source file inclusion. Date: Sat, 25 Dec 2021 08:52:04 -0800 Organization: A noiseless patient Spider Lines: 41 Message-ID: <86fsqg1vbf.fsf@linuxsc.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="1fe31837ad76f46de1d32de2fe408cda"; logging-data="13216"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/5CXAtiHOtFB8YEkUbrXGvrHIokDe4/70=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:gnuKz5AkgQC6FCgbJPOx7rk8sgQ= sha1:kQhqFSSa0RHupI2gawUBnC8+zBk= Xref: csiph.com comp.std.c:6404 James Kuyper writes: > This discussion requires familiarity with the standard's specifications > and terminology from sections 6.10, 6.10.1 and 6.10.2. Unless you've got > those sections memorized, you might need to cross-reference them to > understand what I'm saying. > > To simplify the following discussion, I'm going to write it as if the > only conditional inclusion preprocessing directives were #if, #else, and > #endif. Code using the other conditional inclusion directives can always > be rewritten to use only those three, with essentially the same > behavior, with a minor exception in the case of #elsif, where the > subsequent occurrences of __LINE__ would have increased values. Those > other directives don't change the issue I'm discussing, they only > complicate the discussion. > > I've long understood that, during translation phase 4, as soon as a > compiler reaches the new-line at the end of a #if directive, it knows > whether the #if group will be included. It not, and there's a > corresponding #else, it knows that the #else group will be included. > Either way, as soon as it starts reading a group that will be included, > it can immediately start preprocessing that group (and this is the > important part:) while searching for the #else or #endif directive that > terminates the group. > > I've also long understood that the #if, #else (if any) and #endif > directives that make up an if-section must all occur in the same file. > I'm not sure how I reached that conclusion - it's not anything that the > standard says explicitly. [...] The first rule of grammar in 6.10 paragraph 1 says (with \sub() to mean subscript) preprocessing-file: group \sub(opt) Thus each preprocessing file must consist of an integral number of group-part, and so cannot contain any unbalanced #if/#endif directives, or any #else directive outside an #if/#endif section. Note to all: Merry Christmas!