コンパイラの警告 (レベル 1) C4750

'identifier': ループにインライン展開されている _alloca() を含む関数です

解説

'identifier' 関数はループ内に _alloca 関数のインライン展開を強制するため、ループが実行されるときにスタック オーバーフローの可能性があります。

このエラーを解決するには

  1. 'identifier' 関数が __forceinline 指定子で変更されないことを確認します。

  2. 'identifier' 関数が、ループに含まれている _alloca 関数を含まないことを確認します。

  3. /O1/O2/Ox、または /Og コンパイル スイッチを指定しないでください。

  4. _alloca 関数を、スタック オーバーフローをキャッチする try-except ステートメント内に配置します。

次のコード例はループ内で MyFunction を呼び出し、 MyFunction_alloca 関数を呼び出します。 __forceinline 修飾子により、 _alloca 関数のインライン展開が発生します。

// c4750.cpp
// compile with: /O2 /W1 /c
#include <intrin.h>

char * volatile newstr;

__forceinline void myFunction(void) // C4750 warning
{
// The _alloca function does not require a __try/__except
// block because the example uses compiler option /c.
    newstr = (char * volatile) _alloca(1000);
}

int main(void)
{
    for (int i=0; i<50000; i++)
       myFunction();
    return 0;
}

関連項目

_alloca