C - C言語のunsigned doubleとは何か?(80733)|teratail
より。
# include<stdio.h>
int main() {
unsigned double aa = 0.345;
signed double bb = 0.4509;
double cc = 0.472873;
printf("%f\n", aa);
printf("%f\n", bb);
printf("%f\n", cc);
}
gccではエラーになる
prog.cc: In function 'int main()':
prog.cc:4:22: error: 'signed' or 'unsigned' invalid for 'aa'
unsigned double aa = 0.345;
^~
prog.cc:5:19: error: 'signed' or 'unsigned' invalid for 'bb'
signed double bb = 0.4509;
^~
ところがvisual studio 2015 ver 14.0.25431.01 update3では
warning C4076: 'unsigned': cannot be used with type 'double'
warning C4076: 'signed': cannot be used with type 'double'
warning C4477: 'printf' : format string '%f' requires an argument of type 'double', but variadic argument 1 has type 'unsigned int'
warning C4477: 'printf' : format string '%f' requires an argument of type 'double', but variadic argument 1 has type 'int'
となる。ここでC4076の説明を読みに行こう。
Compiler Warning (level 1) C4076 | Microsoft Docs
'typemod' : can not be used with type 'typename'
A type modifier, whether it is signed orunsigned
, cannot be used with a noninteger type. typemod is ignored.
typemod is ignoredだぁ?いやそれignoreしちゃっていいのかい?明らかに意図に反するコードを作っちゃわないかい?
ここで疑問なのはこれは合法なのかということだ。
規格書を読む
調査中です、しばらくお待ちください。情報提供もお待ちしています...
C++11 規格書だと 7.1.6 (特に 7.1.6.2) が問題になりそう。
— Tsukasa #01 [要出典] (@a4lg) 2017年6月21日
まだ規格書読み途中ですが7.1.6見る限り特に制約はしていなさそうです。
この件を調べようとして long int は int long と書いても良いことを今更発見した。
— 齊藤敦志@仕事ください (@SaitoAtsushi) 2017年6月22日
unsigned doubleをunsigned intとして扱う処理系は合法か? by @yumetodo on @Qiita https://t.co/zZXnCD5syB