Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.std.c > #6404

Re: Interaction between conditional inclusion and source file inclusion.

From Tim Rentsch <tr.17687@z991.linuxsc.com>
Newsgroups comp.std.c
Subject Re: Interaction between conditional inclusion and source file inclusion.
Date 2021-12-25 08:52 -0800
Organization A noiseless patient Spider
Message-ID <86fsqg1vbf.fsf@linuxsc.com> (permalink)
References <sq6d3o$k1l$1@dont-email.me>

Show all headers | View raw


James Kuyper <jameskuyper@alumni.caltech.edu> 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!

Back to comp.std.c | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Interaction between conditional inclusion and source file inclusion. James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-12-25 01:18 -0500
  Re: Interaction between conditional inclusion and source file inclusion. Richard Damon <Richard@Damon-Family.org> - 2021-12-25 08:23 -0500
    Re: Interaction between conditional inclusion and source file inclusion. James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-12-25 11:09 -0500
  Re: Interaction between conditional inclusion and source file inclusion. Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-12-25 08:52 -0800
    Re: Interaction between conditional inclusion and source file inclusion. James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-12-26 09:56 -0800
      Re: Interaction between conditional inclusion and source file inclusion. Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-01-17 06:47 -0800

csiph-web