Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: "usual arithmetic conversions": please explain something... Date: Wed, 01 Mar 2017 08:25:20 -0800 Organization: None to speak of Lines: 36 Message-ID: References: <448topoppn.fsf@be-well.ilk.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="40f2111bd31821bfebd41309549fe646"; logging-data="21586"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/mzXFL2mQNyKHjBFEv9vYl" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:rweNPA1b2jH2npV/xtuEAJvmuDc= sha1:+MOP1ihvbJfUdPcK7fjpkTQqM90= Xref: csiph.com comp.lang.c:105267 BartC writes: > On 01/03/2017 00:59, Keith Thompson wrote: >> BartC writes: [...] >>> Try: >>> >>> printf("%u\n", c); >> >> No, c is an int. >> >> But do try: >> >> printf("%llu\n", a * b); My mistake, I meant "%lu\n", not "%llu\n". > It doesn't make much difference. Trying this (on a machine where long is > 32 bits): Sure, if you use an incorrect format you can sometimes learn something about the value being passed to printf, or its representation -- but what's the point? c is of type int, and happens to have a negative value; printing it as if it were an unsigned int means you're lying to the compiler, and the behavior is undefined. Printing the value of a * b shows you the actual value that was converted to int. I showed how to print the actual values with their correct types. [...] -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"