🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #704

Re: Question about ANSI preprocessor

#704
From: Norman Diamond
Date: Mon, 02 Oct 1989 01:41
38 lines
2036 bytes
In article <11163@smoke.BRL.MIL> gwyn@brl.arpa (Doug Gwyn) writes:

>... as a general design principle the preprocessor is not required to
>back up, apart from the quite limited case of rescanning the
>replacement buffer.

Thank you for answering my question, but I think that your answer might
be a bit too broad.  Section 3.8.3.4 (Dec. 7 '88) says that after
replacement, the replacement buffer must be rescanned WITH THE REST OF
THE SOURCE FILE'S PREPROCESSING TOKENS.

For example, consider:

  #include <stdio.h>
  #define mf1(x) printf("Hello, world.\n")
  #define m2     (z);
  main(){
    mf1 m2
  }

After "m2" changes into "(z);", it must be rescanned with the rest of
the source file's preprocessing tokens.  At this time mf1 must be
recognized as a function-like macro call.  The preprocessor MUST BACK
UP EARLIER THAN THE REPLACEMENT BUFFER.

I will bet that every pre-ANSI compiler/preprocessor would have
rejected the above program.  But ANSI requires it to print
"Hello, world.\n".

In fact I think I can construct a few perverse macros, which will make
the preprocessor take EXPONENTIAL TIME in proportion to the length of
the program.

-- 
Norman Diamond, Sony Corp. (diamond%ws.sony.junet@uunet.uu.net seems to work)
  The above opinions are inherited by your machine's init process (pid 1),
  after being disowned and orphaned.  However, if you see this at Waterloo or
  Anterior, then their administrators must have approved of these opinions.
Technical Details
Message-ID: <10893@riks.csl.sony.co.jp>
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!ginosko!uunet!kddlab!titcca!sragwa!wsgw!socslgw!diamond
References: <10879@riks.csl.sony.co.jp> <11163@smoke.BRL.MIL>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!ginosko!uunet!kddlab!titcca!sragwa!wsgw!socslgw!diamond
From: diamond@csl.sony.co.jp (Norman Diamond)
Newsgroups: comp.std.c
Subject: Re: Question about ANSI preprocessor
Message-ID: <10893@riks.csl.sony.co.jp>
Date: 2 Oct 89 01:41:54 GMT
References: <10879@riks.csl.sony.co.jp> <11163@smoke.BRL.MIL>
Reply-To: diamond@riks. (Norman Diamond)
Organization: Sony Computer Science Laboratory Inc., Tokyo, Japan
Lines: 38