メインコンテンツ

MISRA C++:2008 Rule 7-3-2

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

説明

ルール定義

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

根拠

一般的に、main 関数は、グローバル名前空間内に存在し、プログラムへのエントリ ポイントとして機能します。他のコンテキストでの main の使用は、開発者の期待に沿わない可能性があります。

Polyspace 実装

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

トラブルシューティング

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

すべて展開する

#include <cstdint>

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

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

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

チェック情報

グループ: Declarations
カテゴリ: 必要

バージョン履歴

R2013b で導入


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.