ゲーム作りは楽しい

なんか書く

0=1の証明

本日のギャグです。


こちらのコードを見てください。

#include <cctype>
#include <iostream>
int main()
{
    using namespace std;

    int32_t x = 0;
    if (x = x + 1)
        std::cout << "true";
}

C++で以下のコードを実行したら「true」と出力されたので、 「x = x + 1」はtrueになります。
したがって、x = 0より「0 = 1」である。


...

これは間違いですよね、、

C++で等値判定は「==」にしないといけないので正しくは以下のようにしないと判定できません。

- if (x = x + 1)
+ if (x == x + 1)

「=」にした場合はifの条件評価時にxにx + 1が代入されて「1」になるのでif文を通ったわけです。


では、「==」にして再確認してみましょう。以下のコードの実行はどうでしょうか?

#include <cctype>
#include <iostraem>
int main()
{
    using namespace std;

    int32_t x = 0;
    if (x == x + 1)
        std::cout << "true";
}

なんとこれも「true」と表示されました。

やっぱり「0 == 1」なんですね!

ネタバレ

iostraemに以下のコードを書いています。

#pragma once
#include <iostream>
struct kuso
{
    constexpr kuso(){}
    constexpr kuso(int){}
    constexpr kuso operator + (int)const {return {};}
    constexpr bool operator == (kuso)const {return true;}
};
#define int32_t kuso

くそすぎ