robert bristow-johnson wrote:> // $ gcc -Wconversion -o hello hello.cWhen using gcc, I usually use -Wall -Wextra -Werror which turns on all warnings and makes all warnings into errors. Not sure if this will help in your case. Erik -- ----------------------------------------------------------------- Erik de Castro Lopo ----------------------------------------------------------------- "There are only two things wrong with C++: The initial concept and the implementation." -- Bertrand Meyer
Online · Live + on demand
February 9-11, 2027
Price goes up Jan 1: register now to lock in today's rate
Register Now →
how can i generate warnings for implicit casts that lose bits?
Started by ●June 5, 2007
Reply by ●June 5, 20072007-06-05
Reply by ●June 5, 20072007-06-05
Richard Tobin wrote:>... snip ...> > How big is an octet on ternary machines?5 ternets + "something to express 256/243 rounded up" -- <http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt> <http://www.securityfocus.com/columnists/423> <http://www.aaxnet.com/editor/edit043.html> <http://kadaitcha.cx/vista/dogsbreakfast/index.html> cbfalconer at maineline dot net -- Posted via a free Usenet account from http://www.teranews.com
Reply by ●June 5, 20072007-06-05
Richard Heathfield wrote:> Richard Tobin said:(snip)>>That is, can a six-trit word be considered to be smaller than an >>octet, defeating the claim that a byte may not be smaller than octet?> The C Standard makes no such claim. It only makes the claim that a byte > must be at least 8 bits wide. If we accept the possibility of a ternary > machine, the minimum number of trits that would do the trick is 6.C sort of expects a binary representation. Unsigned addition is module some power of two, and bitwise operators would be very slow otherwise. Fortran specifically allows any base greater than one. That would be a better place to look for a ternary machine. (Fortran has bitwise operations as intrinsic functions. It isn't so obvious what they would do on a non-binary machine.) -- glen
Reply by ●June 5, 20072007-06-05
glen herrmannsfeldt <gah@ugcs.caltech.edu> writes:> Richard Heathfield wrote: >> Richard Tobin said: > (snip) > >>>That is, can a six-trit word be considered to be smaller than an >>>octet, defeating the claim that a byte may not be smaller than octet? > >> The C Standard makes no such claim. It only makes the claim that a byte >> must be at least 8 bits wide. If we accept the possibility of a ternary >> machine, the minimum number of trits that would do the trick is 6. > > C sort of expects a binary representation. Unsigned addition is > module some power of two, and bitwise operators would be very slow > otherwise.C99 explicitly requires a binary representation. (Emulating binary on a ternary machine would be valid.) -- Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst> San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst> "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"
Reply by ●June 5, 20072007-06-05
Randy Yates wrote:>... snip ...> > I am aware of this "byte" definition since I ran into it on the TI > TMS C54x C compiler, where sizeof(int) = 1, even though an int is > 16 bits. That machine's native datapath is 16 bits wide and > incapable of representing a type smaller than 16 bits.Nit. It's capable. It just doesn't limit the numbers as much. :-) -- <http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt> <http://www.securityfocus.com/columnists/423> <http://www.aaxnet.com/editor/edit043.html> <http://kadaitcha.cx/vista/dogsbreakfast/index.html> cbfalconer at maineline dot net -- Posted via a free Usenet account from http://www.teranews.com
Reply by ●June 5, 20072007-06-05
In article <lnsl963qcr.fsf@nuthaus.mib.org>, Keith Thompson <kst-u@mib.org> wrote:>> Because they're passed to a varargs function (printf), which will try >> to access them as ints, so if they're in fact bigger than ints - >> regardless of their value - things will go horribly wrong.>Correction: things *might* go horribly wrong. Worse, they might go >horribly right.Going horribly right is just one of the ways it might go horribly wrong. -- Richard -- "Consideration shall be given to the need for as many as 32 characters in some alphabets" - X3.4, 1963.
Reply by ●June 5, 20072007-06-05
Richard Heathfield <rjh@see.sig.invalid> writes:> Richard Tobin said: > >> In article <878xay6os3.fsf@blp.benpfaff.org>, >> Ben Pfaff <blp@cs.stanford.edu> wrote: >> >>>However, the size of a byte is implementation-defined: it may be >>>larger than one octet (though not smaller). >> >> How big is an octet on ternary machines? > > The requirement is to be able to represent at least 256 discrete values. > This can be accomplished in six trits, the relevant trit pattern being > 100110.Wouldn't a "ternary digit" be a "tit"??? "How many tits are in that byte?"... -- % Randy Yates % "And all that I can do %% Fuquay-Varina, NC % is say I'm sorry, %%% 919-577-9882 % that's the way it goes..." %%%% <yates@ieee.org> % Getting To The Point', *Balance of Power*, ELO http://home.earthlink.net/~yatescr
Reply by ●June 5, 20072007-06-05
robert bristow-johnson <rbj@audioimagination.com> writes: [...]> i just wanna know what flag to set (if any) that makes the > compiler tell me i might want to check the statement that could > potentially throw away those bits. i would think, from the > description that -Wconversion or -Wall should do it, but it doesn't > and i was wondering if the hardcore C or gcc geeks might know the > magic invocation to generate such a warning.[...] Try gnu.gcc.help. -- Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst> San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst> "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"
Reply by ●June 5, 20072007-06-05
Keith Thompson wrote:> Vladimir Vassilevsky <antispam_bogus@hotmail.com> writes: >> glen herrmannsfeldt wrote: >> >>> Randy Yates wrote: >>> (snip) >>> >>>> printf("size of short = %d, size of ulong = %d\n", sizeof(short), >>>> sizeof(unsigned long)); >>> This makes the assumption that sizeof returns an int, when it >>> often returns something else. Maybe you should also test >>> sizeof(sizeof(int))==sizeof(int) >>> >> This also makes the assumption that sizeof() returns size in bytes, >> whereas sizeof returns the size in chars. Char may be bigger then one >> byte. > > No, a "byte" is by definition the size of a char. The term "byte" may > have other meanings outside the context of C, but sizeof(char) is 1 by > definition.Isn't a byte in C the larger of character, octet, or smallest addressable storage element? Jerry -- Engineering is the art of making what you want from things you can get. ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Reply by ●June 5, 20072007-06-05
Randy Yates wrote:>... snip ...> > For example, consider the statement > > printf("sizeof(int) = %d", sizeof(int)); > > and the case in which int is 16 bits and sizeof() returns 32 bits. > > Is it true that a little-endian machine will print this correctly, > while a big-endian machine will not?The cure is simple. Cast the value passed to printf to int. -- <http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt> <http://www.securityfocus.com/columnists/423> <http://www.aaxnet.com/editor/edit043.html> <http://kadaitcha.cx/vista/dogsbreakfast/index.html> cbfalconer at maineline dot net -- Posted via a free Usenet account from http://www.teranews.com







