Paul Pluzhnikov wrote in message... > "BobR" writes: > > > Alexandru Mosoi wrote in message... > >> supposing that I have the following lines: > >> > >> long long a = 12345678901234567890LL; > >> int b = a; > >> > >> how can I make g++ (4.1.2) issue an warning because of loss of > >> precision? > >> > > > > Use -ansi -pedantic. > > int main() > { > unsigned long long a = 12345678901234567890ULL; > int b = a; > return 0; > } > > $ /usr/local/gcc-4.2.1/bin/g++ -ansi -pedantic t.c > t.c:3:28: warning: use of C99 long long integer constant > t.c: In function 'int main()': > t.c:3: error: ISO C++ does not support 'long long' > > $ /usr/local/gcc-4.2.1/bin/gcc -ansi -pedantic t.c > t.c: In function 'main': > t.c:3: warning: ISO C90 does not support 'long long' > t.c:3:28: warning: use of C99 long long integer constant > > Perhaps you should try your suggestions before suggesting them?
Using only -Wall (no -ansi or -pedantic): double c( 123.054); int d = c; // [Warning] initialization to `int' from `double' // [Warning] argument to `int' from `double' But, type 'unsigned long long' is not a 'built-in' type (maybe next ISO), so, the 'warning: use of C99 long long integer constant' is the only way I know. I always do the checks at runtime. You could do: unsigned long long a = 12345678901234567890ULL; int b(0); if( b == a ){} // [Warning] comparison between signed and unsigned integer expressions Kind of silly. If you knew to put the 'if()' there, you'd know to do it right. if( sizeof( b ) == 4 ){ b = a & 0x7FFFFFFF; if( (unsigned long long)(b) != a ){ b = 0; } } ....or whatever. You got anything? -- Bob R POVrookie _______________________________________________ help-gplusplus mailing list help-gplusplus@gnu.org http://lists.gnu.org/mailman/listinfo/help-gplusplus