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


Groups > comp.lang.c > #83929

Re: c is unfinished

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: c is unfinished
Date 2016-03-14 14:25 -0700
Organization None to speak of
Message-ID <lnoaagkb08.fsf@kst-u.example.com> (permalink)
References (6 earlier) <d03708ed-0f5d-4e9b-8621-fbe79c4311cc@googlegroups.com> <87h9g93ul6.fsf@bsb.me.uk> <b7278915-ee8b-4edf-b517-5ec41a09c798@googlegroups.com> <87bn6g513y.fsf@bsb.me.uk> <cb601626-bbf7-4e26-9e2b-deded93efd75@googlegroups.com>

Show all headers | View raw


Malcolm McLean <malcolm.mclean5@btinternet.com> writes:
> On Monday, March 14, 2016 at 7:08:28 PM UTC, Ben Bacarisse wrote:
>> Malcolm McLean <malcolm.mclean5@btinternet.com> writes:
>> 
>> > We call malloc with -400. Since malloc() takes a signed value,
>> > that is constrained to throw an exception, which we handle.
>> 
>> Nope, malloc takes size_t.
>> 
>> > Of course -10, -10 will be a bit problematic, you could argue 
>> > that such an image should have area (I'll leave the mathematicians 
>> > to rule on that one).
>> >
>> > I am of course assuming a superior try .. catch C with some of 
>> > the glitches taken out.
>> 
>> What about the other point?  How does try/catch help with them?
>> 
> If we're going to add arithmetical overflow error exception 
> throwing to C, then of course you mustn't pass about amounts
> of memory or index values in unsigned integers, or, alternatively,
> you could alter the C standard to specify that unsigned arithmetic
> has undefined behaviour on overflow.

That doesn't demonstrate an understanding of what "undefined behavior"
means.

What I think you're suggesting is that the behavior on overflow of a
size_t*size_t multiplication would be *defined* to throw an exception.
(If you merely want to leave it undefined and allow it to throw an
exception, then it's of no use to portable code.)

>                                      The last has implications
> for some legitimate low-level techniques, so the obvious answer is
> to deprecate size_t. 

Yeah, that's not going to happen.

> It needs one tweak to the core C standard, and a minor change to
> the standard library.  

I presume you'd want malloc() to take an int argument?  Presumably
sizeof would also yield int rather than size_t.  If so, that would
impose an additional constraint on all hosted implementations: that the
range of int must be wide enough to represent the size of any object.

Or you could require size_t to be *some* chosen signed type, not
necessarily int -- but that would mean 32-bit systems couldn't have
objects bigger than 2GB.  (I'm not sure whether that's an issue in
practice.)  That's basically what the POSIX type ssize_t is.

If we're going to add exceptions to C *and* (unlike C++) specify that
numeric overflow throws an exception, then a more reasonable approach
would be to define a new kind of integer type, similar to current
unsigned types except that overflow throws an exception rather than
wrapping.  size_t then could be a typedef for one of these types.  But
that would break existing code that uses `(size_t)-1` to denote
`SIZE_MAX` (which wasn't defined until C99).

And of course requiring integer overflow to be detected would hurt
performance.

-- 
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

c is unfinished fir <profesor.fir@gmail.com> - 2016-03-13 12:52 -0700
  Re: c is unfinished Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-03-13 13:05 -0700
    Re: c is unfinished fir <profesor.fir@gmail.com> - 2016-03-13 13:25 -0700
      Re: c is unfinished fir <profesor.fir@gmail.com> - 2016-03-13 16:28 -0700
  Re: c is unfinished Les Cargill <lcargill99@comcast.com> - 2016-03-13 15:20 -0500
    Re: c is unfinished fir <profesor.fir@gmail.com> - 2016-03-13 13:15 -0700
      Re: c is unfinished Les Cargill <lcargill99@comcast.com> - 2016-03-14 07:27 -0500
        Re: c is unfinished gazelle@shell.xmission.com (Kenny McCormack) - 2016-03-14 12:47 +0000
          Re: c is unfinished Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-03-14 06:50 -0700
            Re: c is unfinished "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-03-14 07:04 -0700
        Re: c is unfinished fir <profesor.fir@gmail.com> - 2016-03-14 07:23 -0700
  c is unfinished "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-03-13 14:17 -0700
    Re: c is unfinished "John M. Harris, Jr." <johnmh@openblox.org> - 2016-03-14 08:57 -0400
      Re: c is unfinished fir <profesor.fir@gmail.com> - 2016-03-14 07:06 -0700
        Re: c is unfinished "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-03-14 07:23 -0700
          Re: c is unfinished "John M. Harris, Jr." <johnmh@openblox.org> - 2016-03-14 10:28 -0400
            Re: c is unfinished Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-03-14 08:06 -0700
              Re: c is unfinished Richard Heathfield <rjh@cpax.org.uk> - 2016-03-14 15:26 +0000
                Re: c is unfinished Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-03-14 08:38 -0700
                Re: c is unfinished fir <profesor.fir@gmail.com> - 2016-03-14 09:15 -0700
                Re: c is unfinished fir <profesor.fir@gmail.com> - 2016-03-14 09:42 -0700
                Re: c is unfinished Richard Heathfield <rjh@cpax.org.uk> - 2016-03-14 16:23 +0000
                Re: c is unfinished Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-03-14 09:56 -0700
                Re: c is unfinished fir <profesor.fir@gmail.com> - 2016-03-14 10:03 -0700
                Re: c is unfinished Richard Heathfield <rjh@cpax.org.uk> - 2016-03-14 17:28 +0000
                Re: c is unfinished Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-03-14 11:08 -0700
                Re: c is unfinished Richard Heathfield <rjh@cpax.org.uk> - 2016-03-14 18:51 +0000
                Re: c is unfinished raltbos@xs4all.nl (Richard Bos) - 2016-03-14 22:10 +0000
                Re: c is unfinished Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-03-14 16:26 -0700
                Re: c is unfinished Richard Heathfield <rjh@cpax.org.uk> - 2016-03-14 23:55 +0000
                Re: c is unfinished supercat@casperkitty.com - 2016-03-14 22:44 -0700
                Re: c is unfinished David Brown <david.brown@hesbynett.no> - 2016-03-15 08:59 +0100
                Re: c is unfinished supercat@casperkitty.com - 2016-03-15 07:23 -0700
                Re: c is unfinished David Brown <david.brown@hesbynett.no> - 2016-03-15 15:31 +0100
                Re: c is unfinished supercat@casperkitty.com - 2016-03-15 08:02 -0700
                Re: c is unfinished David Brown <david.brown@hesbynett.no> - 2016-03-16 08:11 +0100
                Re: c is unfinished supercat@casperkitty.com - 2016-03-16 08:33 -0700
                Re: c is unfinished Ian Collins <ian-news@hotmail.com> - 2016-03-15 09:40 +1300
                Re: c is unfinished "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-03-14 14:01 -0700
                Re: c is unfinished "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-03-14 15:33 -0700
                Re: c is unfinished gazelle@shell.xmission.com (Kenny McCormack) - 2016-03-14 23:07 +0000
                Re: c is unfinished "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-03-14 16:27 -0700
                Re: c is unfinished fir <profesor.fir@gmail.com> - 2016-03-14 19:37 -0700
                Re: c is unfinished Richard Heathfield <rjh@cpax.org.uk> - 2016-03-14 21:07 +0000
                Re: c is unfinished Ian Collins <ian-news@hotmail.com> - 2016-03-15 10:16 +1300
                Re: c is unfinished Richard Heathfield <rjh@cpax.org.uk> - 2016-03-14 22:05 +0000
                Re: c is unfinished Öö Tiib <ootiib@hot.ee> - 2016-03-14 15:30 -0700
                Re: c is unfinished supercat@casperkitty.com - 2016-03-14 15:39 -0700
                Re: c is unfinished Richard Heathfield <rjh@cpax.org.uk> - 2016-03-14 23:00 +0000
                Re: c is unfinished Öö Tiib <ootiib@hot.ee> - 2016-03-14 18:09 -0700
                Re: c is unfinished Richard Heathfield <rjh@cpax.org.uk> - 2016-03-15 08:14 +0000
                Re: c is unfinished Öö Tiib <ootiib@hot.ee> - 2016-03-15 13:51 -0700
                Re: c is unfinished David Brown <david.brown@hesbynett.no> - 2016-03-15 10:01 +0100
                Re: c is unfinished Öö Tiib <ootiib@hot.ee> - 2016-03-15 17:07 -0700
                Re: c is unfinished David Brown <david.brown@hesbynett.no> - 2016-03-16 08:26 +0100
                Re: c is unfinished Öö Tiib <ootiib@hot.ee> - 2016-03-16 13:28 -0700
                Re: c is unfinished Philip Lantz <prl@canterey.us> - 2016-03-15 20:03 -0700
                Re: c is unfinished David Brown <david.brown@hesbynett.no> - 2016-03-16 08:52 +0100
                Re: c is unfinished Ian Collins <ian-news@hotmail.com> - 2016-03-16 20:39 +1300
                Re: c is unfinished David Brown <david.brown@hesbynett.no> - 2016-03-16 09:14 +0100
                Re: c is unfinished Ian Collins <ian-news@hotmail.com> - 2016-03-16 22:40 +1300
                Re: c is unfinished David Brown <david.brown@hesbynett.no> - 2016-03-16 12:46 +0100
                Re: c is unfinished Ian Collins <ian-news@hotmail.com> - 2016-03-15 14:53 +1300
                Re: c is unfinished Richard Heathfield <rjh@cpax.org.uk> - 2016-03-15 08:17 +0000
                Re: c is unfinished Ian Collins <ian-news@hotmail.com> - 2016-03-15 21:19 +1300
                Re: c is unfinished Öö Tiib <ootiib@hot.ee> - 2016-03-14 15:16 -0700
                Re: c is unfinished fir <profesor.fir@gmail.com> - 2016-03-14 19:03 -0700
              Re: c is unfinished fir <profesor.fir@gmail.com> - 2016-03-14 08:32 -0700
              Re: c is unfinished Keith Thompson <kst-u@mib.org> - 2016-03-14 08:43 -0700
              Re: c is unfinished Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-03-14 16:14 +0000
                Re: c is unfinished Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-03-14 10:01 -0700
                Re: c is unfinished Richard Heathfield <rjh@cpax.org.uk> - 2016-03-14 17:30 +0000
                Re: c is unfinished Keith Thompson <kst-u@mib.org> - 2016-03-14 10:57 -0700
                Re: c is unfinished Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-03-14 11:32 -0700
                Re: c is unfinished Keith Thompson <kst-u@mib.org> - 2016-03-14 12:12 -0700
                Re: c is unfinished Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-03-14 19:21 +0000
                Re: c is unfinished raltbos@xs4all.nl (Richard Bos) - 2016-03-14 22:16 +0000
                Re: c is unfinished supercat@casperkitty.com - 2016-03-14 15:34 -0700
                Re: c is unfinished Robert Wessel <robertwessel2@yahoo.com> - 2016-03-14 20:15 -0500
                Re: c is unfinished supercat@casperkitty.com - 2016-03-14 22:05 -0700
                Re: c is unfinished Keith Thompson <kst-u@mib.org> - 2016-03-14 22:34 -0700
                Re: c is unfinished Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-03-14 16:17 -0700
                Re: c is unfinished Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-03-15 01:10 +0000
                Re: c is unfinished supercat@casperkitty.com - 2016-03-14 12:03 -0700
                Re: c is unfinished Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-03-14 19:08 +0000
                Re: c is unfinished Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-03-14 13:01 -0700
                Re: c is unfinished supercat@casperkitty.com - 2016-03-14 13:28 -0700
                Re: c is unfinished Keith Thompson <kst-u@mib.org> - 2016-03-14 14:25 -0700
                Re: c is unfinished supercat@casperkitty.com - 2016-03-14 14:40 -0700
                Re: c is unfinished Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-03-14 14:44 -0700
                Re: c is unfinished raltbos@xs4all.nl (Richard Bos) - 2016-03-14 22:44 +0000
                Re: c is unfinished fir <profesor.fir@gmail.com> - 2016-03-14 19:26 -0700
      Re: c is unfinished "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2016-03-14 07:09 -0700
  Re: c is unfinished Jens Stuckelberger <Jens_Stuckelberger@nowhere.net> - 2016-03-13 23:34 +0000
    Re: c is unfinished fir <profesor.fir@gmail.com> - 2016-03-13 16:40 -0700
  Re: c is unfinished supercat@casperkitty.com - 2016-03-14 09:33 -0700

csiph-web