🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #3772

Re: gets() and getchar

#3772
From: Richard A. O'Keefe
Date: Fri, 18 Aug 1995 08:43
58 lines
3017 bytes
Dan.Pop@mail.cern.ch (Dan Pop) writes:
>Whether you include <stdio.h> or not is irrelevant.  gets() is in the
>implementation namespace, and any attempt to redefine it invokes undefined
>behaviour, whether <stdio.h> is included or not:

>    ISO 7.1.3 Reserved Identifiers
>    ...
>    All identifiers with external linkage in any of the following clauses
>    (including future library directions) are always reserved for use as
>    identifiers with external linkage.

>This should end this thread in comp.std.c.  Things which happen to work
>on some implementations are better discussed elsewhere.

This is worth clarifying though.  I had interpreted that text "reserved
for use as identifiers with external linkage" as "you can't use such an
identifier with external linkage, because it's reserved for that, but
you _can_ use it for internal linkage or no linkage".  Your interpretation
seems to be "you can't use such an identifier at all, because it is reserved,
and what it is reserved for is external linkage".

In particular, surely
	/*----------------*/
	#define gets DONT_USE_GETS
	#include <stdlib.h>
	int main(void) { return EXIT_SUCCESS; }
is a stricly conforming program?  And so is

	#include <stdlib.h>
	int main(void) { const int gets = EXIT_SUCCESS; return gets; }

or isn't it?  If these examples _are_ as standard as I had thought them to be,
then the statement "whether you include <stdio.h> or not is irrelevant" must
be wrong.  And specifically,

	#define gets DONT_USE_GETS
	#include <stdlib.h>
	int main(void) {
	    char buffer[1];

	    return gets(buffer) ? EXIT_SUCCESS : EXIT_FAILURE;
	}

should also be ok, because it _doesn't_ use gets as an identifier with
external linkage.  It uses DONT_USE_GETS as an identifier with external
linkage, not gets.

So _if_ I have understood correctly, which I do not assert,
-Dgets=DONT_USE_GETS _is_ ok with files that don't include <stdio.h>
(waves hands a bit to cover the obvious exceptions).
I do agree that the technique only "happens" to work with files that
_do_ include <stdio.h> in some implementations, but that's why it's
a debugging technique done outside the source files.

-- 
"conventional orthography is ... a near optimal system for the
 lexical representation of English words." Chomsky & Halle, S.P.E.
Richard A. O'Keefe; http://www.cs.rmit.edu.au/~ok; RMIT Comp.Sci.
Technical Details
Message-ID: <411js7$4jo@goanna.cs.rmit.edu.au>
Path: arc1-ca.pugleaf.net!goanna.cs.rmit.edu.au!not-for-mail
References: <Pine.ULT.3.91.950807194041.19202A-100000@mars> <409hdq$ib2@goanna.cs.rmit.edu.au> <KANZE.95Aug9103309@slsvhdt.lts.sel.alcatel.de> <40s0eo$k8c@goanna.cs.rmit.edu.au> <danpop.808655822@rscernix>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!goanna.cs.rmit.edu.au!not-for-mail
From: ok@goanna.cs.rmit.edu.au (Richard A. O'Keefe)
Newsgroups: comp.std.c
Subject: Re: gets() and getchar
Date: 18 Aug 1995 18:43:51 +1000
Organization: Comp Sci, RMIT, Melbourne, Australia
Message-ID: <411js7$4jo@goanna.cs.rmit.edu.au>
References: <Pine.ULT.3.91.950807194041.19202A-100000@mars>  <409hdq$ib2@goanna.cs.rmit.edu.au> <KANZE.95Aug9103309@slsvhdt.lts.sel.alcatel.de> <40s0eo$k8c@goanna.cs.rmit.edu.au> <danpop.808655822@rscernix>
NNTP-Posting-Host: goanna.cs.rmit.edu.au
NNTP-Posting-User: ok
X-Newsreader: NN version 6.5.0 #0 (NOV)