🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #3763

Re: gets() and getchar

#3763
From: Dan Pop
Date: Thu, 17 Aug 1995 10:37
42 lines
2348 bytes
In <40s0eo$k8c@goanna.cs.rmit.edu.au> ok@goanna.cs.rmit.edu.au (Richard A. O'Keefe) writes:

>I mentioned
>    cc .... -Dgets=DONT_USE_GETS
>
>kanze@lts.sel.alcatel.de (James Kanze US/ESC 60/3/141 #40763) writes:
>>An excellent idea.  But wouldn't it be better if it gave the error
>>message at compile time (with a line number so you could find and
>>correct it easily)?  Say:
>
>>	-Dgets='DONT_USE_GETS!'
>
>No.  Reason:  a program that _doesn't_ use gets() may still #include <stdio.h>
>in order to correctly use fgets().  With your suggestion the prototype for
>gets() in <stdio.h> -- assuming of course a C implementation which uses text
>files for stdio.h, I know it needn't -- would be in error.
>
>Note that the definition is OUTSIDE the C sources.  It is not something that
>I would dream of including in C code that is supposed to be portable, because
>if you #include <stdio.h> you aren't supposed to mess with reserved names like
>gets.  This is done _outside_ the C code _for debugging_ only on systems where
>it is known (by experiment) to work.

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.

Dan
--
Dan Pop
CERN, CN Division
Email: Dan.Pop@mail.cern.ch 
Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
Technical Details
Message-ID: <danpop.808655822@rscernix>
Path: arc1-ca.pugleaf.net!CERN.ch!rscernix!danpop
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>

Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c
Path: arc1-ca.pugleaf.net!CERN.ch!rscernix!danpop
From: Dan.Pop@mail.cern.ch (Dan Pop)
Subject: Re: gets() and getchar
X-Nntp-Posting-Host: ues5.cern.ch
Message-ID: <danpop.808655822@rscernix>
Sender: news@news.cern.ch (USENET News System)
Organization: CERN European Lab for Particle Physics
X-Newsreader: NN version 6.5.0 #9 (NOV)
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>
Date: Thu, 17 Aug 1995 10:37:02 GMT