ホーム » Linux » コンパイルオプション -Dname=…

2019年9月
1234567
891011121314
15161718192021
22232425262728
2930  

カテゴリー

アーカイブ

ブログ統計情報

  • 80,907 アクセス



コンパイルオプション -Dname=…

コンパイル時のオプションで -DVER=2019.09 の様な指定を使いたくなったので調べてみた.
コードは次のようなもの.

#include	<iostream>
#include	<iomanip>

#ifndef	Test_Ver_F
#define	Test_Ver_F  2019.0902
#endif

int	main	(int argc,   char* argv[])
{
	{
		std::cout                            	<< Test_Ver_F  << std::endl ;
		std::cout <<  std::setprecision(20)  	<< Test_Ver_F  << std::endl ;
		}
	return	0 ;
	}
pi@raspberrypi:~/Documents/test_gcc/t_ccsw_d $ g++ t_ccsw_d.cpp 
pi@raspberrypi:~/Documents/test_gcc/t_ccsw_d $ ./a.out 
2019.09
2019.0902000000000953
pi@raspberrypi:~/Documents/test_gcc/t_ccsw_d $ g++ t_ccsw_d.cpp -DTest_Ver_F=2019.0902
pi@raspberrypi:~/Documents/test_gcc/t_ccsw_d $ ./a.out 
2019.09
2019.0902000000000953
pi@raspberrypi:~/Documents/test_gcc/t_ccsw_d $ g++ t_ccsw_d.cpp -DTest_Ver_F="2019.0902"
pi@raspberrypi:~/Documents/test_gcc/t_ccsw_d $ ./a.out 
2019.09
2019.0902000000000953
pi@raspberrypi:~/Documents/test_gcc/t_ccsw_d $ g++ t_ccsw_d.cpp -DTest_Ver_F=\"2019.0902\"
pi@raspberrypi:~/Documents/test_gcc/t_ccsw_d $ ./a.out 
2019.0902
2019.0902
pi@raspberrypi:~/Documents/test_gcc/t_ccsw_d $ g++ t_ccsw_d.cpp -DTest_Ver_F=\"2019.09.02\"
pi@raspberrypi:~/Documents/test_gcc/t_ccsw_d $ ./a.out 
2019.09.02
2019.09.02
pi@raspberrypi:~/Documents/test_gcc/t_ccsw_d $ 

g++ t_ccsw_d.cpp -DTest_Ver_F=2019.0902
2019.0902 の様な浮動小数点の指定は特に変わった所はない.
但し浮動小数点による誤差などは考慮が必要.
文字列として扱いたいときは \” で括ればよい.

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

コメントする

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

%d人のブロガーが「いいね」をつけました。