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


Groups > comp.lang.c > #76706

Re: According to the standard fgetc is unsafe

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: According to the standard fgetc is unsafe
Date 2015-11-20 18:16 -0800
Organization None to speak of
Message-ID <lnwptcayhf.fsf@kst-u.example.com> (permalink)
References <e8b5ad79-1bf3-4db0-bbf4-47a42505f24a@googlegroups.com> <n2kr9r$res$2@dont-email.me> <103cea12-0558-49b4-8e5e-ec871fc59b0d@googlegroups.com> <qnhs4blc9s5kkriq8ju25vpalha0ts6r49@4ax.com>

Show all headers | View raw


Robert Wessel <robertwessel2@yahoo.com> writes:
> On Thu, 19 Nov 2015 08:41:32 -0800 (PST), Malcolm McLean
> <malcolm.mclean5@btinternet.com> wrote:
>>On Thursday, November 19, 2015 at 3:56:00 PM UTC, Nick Bowler wrote:
>>> Implementations with UCHAR_MAX > INT_MAX will be freestanding
>>> implementations, and will not provide the functions in <stdio.h>
>>> anyway (freestanding implementations are not required to do so).
>>> 
>>Actually very high end machines sometimes have 32 bit bytes and no
>>facilities at machine level for accessing smaller units of memory. 
>>
>>Someone here mentioned one which initially declared CHAR_BIT to be 32
>>or 64 (I forget which), but in a later incarnation went for 8 bit chars
>>and behind the scenes shifting and masking ops to create the illusion of
>>8 bit bytes.
>
> Certainly that was true on some of the Crays.  OTOH, I know of no*
> (even marginally) recent (general purpose) machine that are not byte
> addressed, even if the smallest unit accessible is a word.  So while
> accessing a "byte" may be clumsy, it's addressed naturally.

I've mentioned Cray vector systems here a number of times.  They have
64-bit words, and no hardware support for smaller quantities other than
by shifting and masking.  I'm not aware that they ever had a C compiler
with CHAR_BIT > 8.  But then I only used Unicos (Cray's Unix OS), not
its non-Unix predecessor(s), and POSIX requires CHAR_BIT==8.  Pre-Unicos
Cray vector systems might not even have had a C compiler, but that's
pure speculation on my part.

> There are some word-addressed DSPs still out there, but I don't think
> you'd call those "high end".

DSPs are the only modern systems I'm aware of with CHAR_BIT > 8.

> *I don't know enough about the Unisys Clearpath machine's ISA (the old
> 1100/2200 ISA), but those might be an exception.  The C implementation
> for those has a CHAR_BIT as 9, so if there is an ISA issue, it's dealt
> with by the implementation.

But CHAR_BIT==9 doesn't cause problems with fgetc(), since int must be
at least 16 bits on all systems, and at least 18 bits if CHAR_BIT==9.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

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


Thread

According to the standard fgetc is unsafe frederic.line@laposte.net - 2015-11-19 04:59 -0800
  Re: According to the standard fgetc is unsafe Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-11-19 08:32 -0500
  Re: According to the standard fgetc is unsafe Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-19 06:03 -0800
  Re: According to the standard fgetc is unsafe James Kuyper <jameskuyper@verizon.net> - 2015-11-19 10:34 -0500
  Re: According to the standard fgetc is unsafe Nick Bowler <nbowler@draconx.ca> - 2015-11-19 15:53 +0000
    Re: According to the standard fgetc is unsafe frederic.line@laposte.net - 2015-11-19 08:28 -0800
    Re: According to the standard fgetc is unsafe Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-19 08:41 -0800
      Re: According to the standard fgetc is unsafe Robert Wessel <robertwessel2@yahoo.com> - 2015-11-19 16:09 -0600
        Re: According to the standard fgetc is unsafe Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-19 14:18 -0800
        Re: According to the standard fgetc is unsafe Keith Thompson <kst-u@mib.org> - 2015-11-20 18:16 -0800
          Re: According to the standard fgetc is unsafe Robert Wessel <robertwessel2@yahoo.com> - 2015-11-21 05:19 -0600

csiph-web