1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

C++ Builder XE4 | 10.2 Tokyo > IDE > バージョンを知るマクロ > __CODEGEARC__(と__CODEGEARC_VERSION__) > 1632 : XE4と1840 : 10.2 Tokyo

1
Last updated at Posted at 2019-04-15
動作環境
C++ Builder XE4
Rad Studio 10.2 Tokyo (Update 3)

JSONのAPI

IDEのバージョンが変わると、実装も変更しないと警告が出るようになる。

IDEのバージョン

IDEのバージョンはどうやって知るのか?
C++の場合。

__CODEGEARC__: バージョン番号

__CODEGEARC_VERSION__: この内部マクロは、コンパイラのメジャー バージョン番号、マイナー バージョン番号、および内部番号をコード化した整数に展開されます。

実装例

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)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
	String infmsg = __CODEGEARC__;

	ShowMessage(infmsg);
}
//---------------------------------------------------------------------------

実行例

  • 1632 : XE4
  • 1840 : 10.2 Tokyo

マクロ判別の実装例 (ideone)

__CODEGEARC__マクロがIDEで定義されていると、それに基づきIDEのバージョンごとに実装を切替えはできる。

    #include <iostream>
    using namespace std;
     
    #define __CODEGEARC__ (1632)
     
    int main() {
    #if __CODEGEARC__ == 1632
    	cout << "XE4" << endl;
    #endif
     
    #if __CODEGEARC__ == 1840
    	cout << "10.2 Tokyo" << endl;
    #endif
    	return 0;
    }
XE4

まとめ

  • __CODEGEARC__を使うことで「XE4かそうでないか」は識別できそう
  • __CODEGEARC_VERSION__を使うまでもないかな
  • 実装切替えはできるが、「それは読みやすいコードなのか?」問題

参考

1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?