R
robert bristow-johnson
presently using linux gcc:
$ gcc -v
Using built-in specs.
Target: i386-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --
infodir=/usr/share/info --enable-shared --enable-threads=posix --
enable-checking=release --with-system-zlib --enable-__cxa_atexit --
disable-libunwind-exceptions --enable-libgcj-multifile --enable-
languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --
disable-dssi --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre
--with-cpu=generic --host=i386-redhat-linux
Thread model: posix
gcc version 4.1.1 20060525 (Red Hat 4.1.1-1)
i run it on this program:
FILE: hello.c
//
// $ gcc -Wconversion -o hello hello.c
// $ hello
//
#include <stdio.h>
main()
{
unsigned long a_ulong = 0; // 32 bit
short a_short_array[128]; // 16 bit each
a_ulong = 1234567;
a_short_array[26] = a_ulong;
printf("%d, %hx, %x, %lx \n", sizeof(a_short_array),
a_short_array[26], a_short_array[26], a_ulong);
//
// printf output is:
//
// 256, d687, ffffd687, 12d687
//
}
and am using this invocation to compile:
$ gcc -Wconversion -o hello hello.c
which results in NO WARNINGS! even though it is clear that bits are
dropped in this line of code:
a_short_array[26] = a_ulong;
isn't there a way to get this thing to complain when i do an
assignment (without explicit casting) of a 32-bit int to a 16-bit
int? we know that bits can be potentially dumped in such an
assignment. why can't i get this thing to warn me? i've been to:
http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#Warning-Options
and this seems to confirm what i think the compiler should do. i have
also tried -Wall .
please reply to both newsgroups as i don't always hang out at
comp.lang.c .
i hope someone can explain this.
thank you.
r b-j
$ gcc -v
Using built-in specs.
Target: i386-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --
infodir=/usr/share/info --enable-shared --enable-threads=posix --
enable-checking=release --with-system-zlib --enable-__cxa_atexit --
disable-libunwind-exceptions --enable-libgcj-multifile --enable-
languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --
disable-dssi --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre
--with-cpu=generic --host=i386-redhat-linux
Thread model: posix
gcc version 4.1.1 20060525 (Red Hat 4.1.1-1)
i run it on this program:
FILE: hello.c
//
// $ gcc -Wconversion -o hello hello.c
// $ hello
//
#include <stdio.h>
main()
{
unsigned long a_ulong = 0; // 32 bit
short a_short_array[128]; // 16 bit each
a_ulong = 1234567;
a_short_array[26] = a_ulong;
printf("%d, %hx, %x, %lx \n", sizeof(a_short_array),
a_short_array[26], a_short_array[26], a_ulong);
//
// printf output is:
//
// 256, d687, ffffd687, 12d687
//
}
and am using this invocation to compile:
$ gcc -Wconversion -o hello hello.c
which results in NO WARNINGS! even though it is clear that bits are
dropped in this line of code:
a_short_array[26] = a_ulong;
isn't there a way to get this thing to complain when i do an
assignment (without explicit casting) of a 32-bit int to a 16-bit
int? we know that bits can be potentially dumped in such an
assignment. why can't i get this thing to warn me? i've been to:
http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#Warning-Options
and this seems to confirm what i think the compiler should do. i have
also tried -Wall .
please reply to both newsgroups as i don't always hang out at
comp.lang.c .
i hope someone can explain this.
thank you.
r b-j