メインコンテンツ

このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。

MISRA C++:2023 Rule 6.0.4

The identifier main shall not be used for a function other than the global function main

R2024b 以降

説明

ルール定義

The identifier main shall not be used for a function other than the global function main. 1

根拠

一般的に、main 関数は、グローバル名前空間内に存在し、プログラムへのエントリ ポイントとして機能します。他のコンテキストでの main の使用は想定外であり、混乱を招きます。

Polyspace 実装

ルール チェッカーは、グローバル名前空間以外の名前空間で識別子 main が使用された場合に違反を報告します。

トラブルシューティング

ルール違反が想定されるものの、Polyspace® から報告されない場合は、コーディング規約違反が想定どおりに表示されない理由の診断を参照してください。

すべて展開する

#include <cstdint>

class ExampleA {
public:
    void main(void) {}      //Noncompliant
};

int32_t main() {            //Compliant
    //...
    return 0;
}

namespace Backups {
    int32_t main() {        //Noncompliant
        //...
        return 0;
    }
}

グローバル名前空間以外の名前空間で main を使用すると、ルール違反になります。

チェック情報

グループ: Basic Concepts
カテゴリ: Required

バージョン履歴

R2024b で導入


1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.

The MISRA coding standards referenced in the Polyspace Bug Finder™ documentation are from the following MISRA standards:

  • MISRA C:2004

  • MISRA C:2012

  • MISRA C:2023

  • MISRA C++:2008

  • MISRA C++:2023

MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.