• Re: Safety of casting from 'long' to 'int'

    From dave_thompson_2@dave_thompson_2@comcast.net to comp.lang.c on Sat Jun 6 17:49:53 2026
    From Newsgroup: comp.lang.c

    On Sun, 3 May 2026 00:30:01 -0000 (UTC), antispam@fricas.org (Waldek
    Hebisch) wrote:

    Bart <bc@freeuk.com> wrote:
    [about overflow]
    I tried another experiment with printing the result of 2 * 2000000000 across several languages. All these printed -294967296:

    C#
    D
    Java
    Fortran
    Kotlin

    (All run from rextester.com.) These also printed an overflowed result:

    That's only one Fortran implementation, and quite possibly a
    particular mode of it. Fortran the language, like C, does not define
    this, and I have used multiple implementations that DID trap for
    integer overflow, sometimes depending on what options you used. And
    since Fortran was designed and mostly used for applications where
    correct numerical results are important, most Fortran programmers, and
    shops, preferred this. Most, not all.

    Java OTOH does define wrapping, and Kotlin is mostly syntax sugar for
    Java so it adopts that.

    In the days when c.l.fortran was almost as active as c.l.c now -- over
    5 years ago for sure, probably over 10 -- their equivalent of nasal
    demons, i.e. canonical example for (unintended) use of something
    nonstandard, was 'starts World War III'. Given some of the application
    domains in which Fortran was popular, especially in earlier decades,
    that came closer to realism than I think most people want(ed).
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Tim Rentsch@tr.17687@z991.linuxsc.com to comp.lang.c on Sun Jun 7 18:02:29 2026
    From Newsgroup: comp.lang.c

    cross@spitfire.i.gajendra.net (Dan Cross) writes:

    In article <86a4u7s0lo.fsf@linuxsc.com>,
    Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:

    cross@spitfire.i.gajendra.net (Dan Cross) writes:

    [..I am summarizing parts in an effort to get to key aspects..]

    In article <86o6isuegr.fsf@linuxsc.com>,
    Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:

    [snip]
    It's important to understand the perspectives of different groups
    of participants in the C ecosystem. There are three main groups:

    If you're a programmer, you hate undefined behavior, and avoid it
    like the plague.

    If you're a compiler writer, you love undefined behavior, because
    it lets you do whatever you want.

    If you're a member of the ISO C standards committee (and I admit
    that to a degree I am speculating here), you think of undefined
    behavior as a balancing test, of needing to weigh the tensions
    inherent in what the first two groups would prefer.

    This, I think, is the tragedy of C ("tragedy" in the dramatic,
    Shakespearean sense).
    [long exposition on the history of C]

    My point here is that the users and developers of the language
    were the same group, [elaboration]

    But, as you pointed out, this is no longer the case. The two are
    now distinct, with very different goals. [a consequence of which
    is C usage is less uniform (my paraphrase)]

    Here, I was referring to the _groups you defined_.

    I think this is fair: pretty much no production OS is written in
    pure ISO C, if they're written in C at all: they all use compiler
    flags or custom toolchains to enable various extensions and pin
    down aspects of UB they depend on in one form or another.

    And this is the tragedy. This isn't how it started, and I don't
    think the folks who created the language wanted it to go down this
    way, but here we are. [rest omitted]

    I wouldn't call it a tragedy, in fact just the opposite.

    The tragedy I alluded to is that precisely the difference
    between two groups you yourself suggested: programmers hate UB,
    compiler writers love it. The compiler writers and programmers
    often appear to have an antagonistic relationship.

    If C had
    stayed in its original environment it never would have become as
    ubiquitous and widespread as it is today. The original ecosystem
    doesn't scale. By letting C, and also Unix, enter the public
    sphere, a great benefit accrued to the world at large.

    I said as much.

    [snip] Moreover such non-standard
    language usages are not limited to C -- the Rust language is also
    used in the linux kernel, and there too some non-standard language
    features are used in kernel code.

    Rust has no language standard, so saying that "non-standard
    language features are used in kernel code" is incorrect.

    I don't mean to compare C and Rust. My position here is only that,
    in my view, the complaints raised about C are misplaced. Others
    are welcome to their own views on the subject.

    I don't think you read my note carefully, and your response is
    to something I did not say.

    It may be that I didn't understand what you were trying to get
    at. But I did read your postings carefully, both the earlier
    one I responded to before and the one I am replying to now.
    --- Synchronet 3.22a-Linux NewsLink 1.2