Skip to content

[diff.expr] Undocumented change of 0 == 0 type from int to bool #9299

Open

Description

@eisenwave

We document in [diff.iso] that the types of string literals and character literals are changed, but we dubiously do not document that 0 == 0 (generally, equality and relatioal comparisons) produce int in C but bool in C++.

This feels like a pretty relevant difference, although it's hard to observe in practice because integer promotion gets rid of boolness in lots of cases.

Activity

  1. frederick-vs-ja commented on Sep 3, 2026

    @frederick-vs-ja
    Contributor

    Built-in && and || operators also produce int in C but bool in C++.

  2. jensmaurer commented on Sep 3, 2026

    @jensmaurer
    Member

    Do you have an example where this is observable with C-only syntax?

  3. eisenwave commented on Sep 3, 2026

    @eisenwave
    MemberAuthor
    static_assert(sizeof(0 == 0) == sizeof(bool));

    is almost certainly failing in C, but guaranteed to pass in C++.

    And obviously, you can observe it with _Generic and typeof, but that's probably less interesting for a [diff] entry.

  4. jensmaurer commented on Sep 3, 2026

    @jensmaurer
    Member

    _Generic and typeof are not valid C++.

  5. frederick-vs-ja commented on Sep 4, 2026

    @frederick-vs-ja
    Contributor

    We can observe these with auto and pointer variables. Although it seems quite hard to do so with pre-C23 constructs.

  6. Halalaluyafail3 commented on Sep 4, 2026

    @Halalaluyafail3
    Contributor

    Here is another way that it can be observed in C23 and C++26:

    #include<stdckdint.h>
    int main(){
        int x;
        ckd_add(&x,0==0,0);
    }

    ckd_add does not accept bools, so it is invalid only in C++.

  7. Halalaluyafail3 commented on Sep 4, 2026

    @Halalaluyafail3
    Contributor

    It may also be worth mentioning that some library functions such as isnormal have different return types in C++, changing from int to bool.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2-BugPresentational errors and omissions

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions