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


Groups > comp.lang.c > #20004

Re: c99 and the lack of warnings when int operations are applied to a bool

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: c99 and the lack of warnings when int operations are applied to a bool
Date 2012-04-27 11:28 -0700
Organization None to speak of
Message-ID <lnehr9vxjt.fsf@nuthaus.mib.org> (permalink)
References (5 earlier) <jncspr$on8$1@dont-email.me> <jncuh1$ls$1@dont-email.me> <jnd0fk$8vk$1@dont-email.me> <jndsiu$60v$1@dont-email.me> <4f9ad6b4$0$21924$426a74cc@news.free.fr>

Show all headers | View raw


Lanarcam <lanarcam1@yahoo.fr> writes:
> Le 27/04/2012 12:31, James Kuyper a écrit :
>> On 04/26/2012 10:32 PM, Eric Sosman wrote:
[...]
>>>       If you're looking for a language with seat belts, training
>>> wheels, airbags, and padded walls, C shouldn't be your first
>>> choice, and restrictions on arithmetic wouldn't change matters.
>>
>> A C-like language with few more barriers between conceptually distinct
>> things like numbers, characters, and bools than C has, would make it
>> slightly easier to avoid writing nonsense. Those barriers wouldn't cause
>> the loss of any truly valuable characteristic of C.
>
> I think you mean ADA.

I think *you* mean Ada (the name is not an acronym).

But one could have a C-like language with fewer implicit conversions
without going as far as Ada, which doesn't even have implicit
conversions between otherwise identical integer types.

I can imagine a C-like language with, say, the following features:

- C-like implicit conversions among all numeric types, signed, unsigned,
  and floating-point -- or maybe only allow implicit conversions within
  each of the three kinds of numeric types (yes, I'm ignoring _Complex
  for now)

- bool is treated as a scalar but non-numeric type

- Each enumerated type is treated as a scalar but non-numeric type
  (bool could be a special-case enumerated type, with false and true as
  enumerated constants)

- No implicit conversions between numeric and non-numeric types (but
  casts work as in C)

- 0 is not a null pointer constant; instead, there's a keyword (say,
  "nil") that is the language's *only* null pointer constant

- Relational and equality operators yield bool results

- Contexts that require conditions (if, for, while, do-while, !, &&, ||,
  ?:, and whatever else I've forgotten) require a bool expression

Some implications:

- The NULL macro is unnecessary, and is replaced by the nil keyword.

- You'd have to write "if (num != 0)" rather than "if (num)".

- You'd have to write "if (ptr != nil)" rather than "if (ptr)".

- There are undoubtedly more implications that would have to be worked
  out.

This hypothetical language would be closer to Ada than C is, but
it's still much closer to C than it is to Ada.  Think of a scale
with C at 0, Ada at 1, and this language at perhaps 0.05 or 0.1.

I do not suggest for a moment that C itself should be changed like this.
It would break almost all existing C code, and that's clearly unacceptable.

But personally, I think I'd like it a little better than I like C.  (And
if I ever actually invented such a thing, I'd probably also clean up the
treatment of arrays and pointers.)

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
    Will write code for food.
"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 | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

c99 and the lack of warnings when int operations are applied to a bool mathog <dmathog@gmail.com> - 2012-03-23 08:40 -0700
  Re: c99 and the lack of warnings when int operations are applied to a bool James Kuyper <jameskuyper@verizon.net> - 2012-03-23 12:07 -0400
  Re: c99 and the lack of warnings when int operations are applied to a bool jacob navia <jacob@spamsink.net> - 2012-03-23 21:45 +0100
    Re: c99 and the lack of warnings when int operations are applied to a bool Robert Wessel <robertwessel2@yahoo.com> - 2012-03-23 17:17 -0500
      Re: c99 and the lack of warnings when int operations are applied to a bool jacob navia <jacob@spamsink.net> - 2012-03-23 23:29 +0100
        Re: c99 and the lack of warnings when int operations are applied   to a bool Ian Collins <ian-news@hotmail.com> - 2012-03-24 11:48 +1300
          Re: c99 and the lack of warnings when int operations are applied   to a bool jacob navia <jacob@spamsink.net> - 2012-03-24 23:47 +0100
            Re: c99 and the lack of warnings when int operations are applied   to a bool Willem <willem@toad.stack.nl> - 2012-03-25 09:05 +0000
              Re: c99 and the lack of warnings when int operations are applied   to a bool "BartC" <bc@freeuk.com> - 2012-03-25 11:30 +0100
                Re: c99 and the lack of warnings when int operations are applied   to a bool Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-03-25 21:05 +0100
                Re: c99 and the lack of warnings when int operations are applied   to a bool Lowell Gilbert <lgusenet@be-well.ilk.org> - 2012-03-25 16:15 -0400
                Re: c99 and the lack of warnings when int operations are applied   to a bool Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-03-25 22:14 +0100
                Re: c99 and the lack of warnings when int operations are applied   to a bool James Kuyper <jameskuyper@verizon.net> - 2012-03-25 23:46 -0400
                Re: c99 and the lack of warnings when int operations are applied to a bool Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-03-26 12:05 +0100
                Re: c99 and the lack of warnings when int operations are applied to a bool Lowell Gilbert <lgusenet@be-well.ilk.org> - 2012-03-26 15:22 -0400
              Re: c99 and the lack of warnings when int operations are applied to a bool Gareth Owen <gwowen@gmail.com> - 2012-03-25 11:44 +0100
                Re: c99 and the lack of warnings when int operations are applied to a bool Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-03-25 13:06 +0100
            Re: c99 and the lack of warnings when int operations are applied to a bool Tim Rentsch <txr@alumni.caltech.edu> - 2012-03-27 11:12 -0700
        Re: c99 and the lack of warnings when int operations are applied to a bool Robert Wessel <robertwessel2@yahoo.com> - 2012-03-24 01:15 -0500
          Re: c99 and the lack of warnings when int operations are applied to a bool jacob navia <jacob@spamsink.net> - 2012-03-24 23:29 +0100
    Re: c99 and the lack of warnings when int operations are applied to a bool mathog <dmathog@gmail.com> - 2012-03-27 09:53 -0700
      Re: c99 and the lack of warnings when int operations are applied to a bool Keith Thompson <kst-u@mib.org> - 2012-03-27 11:07 -0700
      Re: c99 and the lack of warnings when int operations are applied to a bool James Kuyper <jameskuyper@verizon.net> - 2012-03-27 14:16 -0400
      Re: c99 and the lack of warnings when int operations are applied to a bool Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-04-26 07:57 -0400
        Re: c99 and the lack of warnings when int operations are applied to a bool jacob navia <jacob@spamsink.net> - 2012-04-26 14:08 +0200
        Re: c99 and the lack of warnings when int operations are applied to a bool James Kuyper <jameskuyper@verizon.net> - 2012-04-26 09:09 -0400
          Re: c99 and the lack of warnings when int operations are applied to a bool Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-04-26 21:29 -0400
            Re: c99 and the lack of warnings when int operations are applied to a bool James Kuyper <jameskuyper@verizon.net> - 2012-04-26 21:58 -0400
              Re: c99 and the lack of warnings when int operations are applied to a bool Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-04-26 22:32 -0400
                Re: c99 and the lack of warnings when int operations are applied to a bool James Kuyper <jameskuyper@verizon.net> - 2012-04-27 06:31 -0400
                Re: c99 and the lack of warnings when int operations are applied to a bool Lanarcam <lanarcam1@yahoo.fr> - 2012-04-27 19:26 +0200
                Re: c99 and the lack of warnings when int operations are applied to a bool Keith Thompson <kst-u@mib.org> - 2012-04-27 11:28 -0700
                Re: c99 and the lack of warnings when int operations are applied to a bool Lanarcam <lanarcam1@yahoo.fr> - 2012-04-27 20:51 +0200
                Re: c99 and the lack of warnings when int operations are applied to a bool ImpalerCore <jadill33@gmail.com> - 2012-04-27 12:17 -0700
                Re: c99 and the lack of warnings when int operations are applied to a bool Jens Gustedt <jens.gustedt@loria.fr> - 2012-04-28 09:17 +0200
                Re: c99 and the lack of warnings when int operations are applied to a bool Keith Thompson <kst-u@mib.org> - 2012-04-28 13:26 -0700
                Re: c99 and the lack of warnings when int operations are applied to a bool Willem <willem@toad.stack.nl> - 2012-04-27 18:11 +0000
                Re: c99 and the lack of warnings when int operations are applied to a bool ImpalerCore <jadill33@gmail.com> - 2012-04-27 12:05 -0700
                Re: c99 and the lack of warnings when int operations are applied to a bool James Kuyper <jameskuyper@verizon.net> - 2012-04-27 15:32 -0400
                Re: c99 and the lack of warnings when int operations are applied to a bool Willem <willem@toad.stack.nl> - 2012-04-27 20:16 +0000
                Re: c99 and the lack of warnings when int operations are applied to a bool James Kuyper <jameskuyper@verizon.net> - 2012-04-27 16:45 -0400
                Re: c99 and the lack of warnings when int operations are applied to a bool Rui Maciel <rui.maciel@gmail.com> - 2012-04-27 21:26 +0100
                Re: c99 and the lack of warnings when int operations are applied to a bool Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-04-27 21:18 -0400
                Re: c99 and the lack of warnings when int operations are applied to a bool Rui Maciel <rui.maciel@gmail.com> - 2012-04-27 21:33 +0100
                Re: c99 and the lack of warnings when int operations are applied to a bool Keith Thompson <kst-u@mib.org> - 2012-04-27 15:36 -0700
                Re: c99 and the lack of warnings when int operations are applied to a bool ImpalerCore <jadill33@gmail.com> - 2012-04-27 08:31 -0700

csiph-web