LoginSignup
0
1

More than 5 years have passed since last update.

c++ builder XE4, 10.2 Tokyo > Error: 不正な浮動小数点演算命令が出る理由

Last updated at Posted at 2016-06-12
動作環境
C++ Builder XE4
RAD Studio 10.2 Tokyo Update 2 (追記: 2017/12/27)

qiita.png

code

Unit1.cpp
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}

float __fastcall TForm1::TestFunc(void)
{

}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    TestFunc();
}
//---------------------------------------------------------------------------
Unit1.h
//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:    // IDE で管理されるコンポーネント
    TButton *Button1;
    void __fastcall Button1Click(TObject *Sender);
private:    // ユーザー宣言
    float __fastcall TestFunc(void);
public:     // ユーザー宣言
    __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

理由

TestFunc()は間違ってfloat型で宣言している (void型でなく)。

float型で宣言している関数を以下のようにコールすると「不正な浮動小数点演算命令」が出るようだ。知らなかった。

void __fastcall TForm1::Button1Click(TObject *Sender)
{
    TestFunc();
}

float型関数にreturnがない時

(追記 2016/09/13)

float __fastcall TForm1::TestFunc(void)
{

}

float型の関数においてreturnを定義していない。
この状態でTestFunc()がコールされると「不正な浮動小数点演算命令」が出るようだ。

反対に、このエラーが出た時は、関数のどこかでreturnを忘れている可能性がある。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1