public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Maciej W. Rozycki" <macro@linux-mips.org>
To: Ian Lance Taylor <iant@google.com>
Cc: loody <miloody@gmail.com>, Sergei Shtylyov <sshtylyov@mvista.com>,
	       gcc-help <gcc-help@gcc.gnu.org>,
	       Linux MIPS Mailing List <linux-mips@linux-mips.org>
Subject: Re: Fwd: about udelay in mips
Date: Thu, 27 Jan 2011 21:43:00 -0000	[thread overview]
Message-ID: <alpine.LFD.2.00.1101272138520.25047@eddie.linux-mips.org> (raw)
In-Reply-To: <mcrlj26owrx.fsf@google.com>

On Thu, 27 Jan 2011, Ian Lance Taylor wrote:

> I don't know the type of HZ.  But assuming it is a constant, then the
> rules of C are that the expression
>     us * 0x000010c7 * HZ * lpj
> gets evaluated in the type "unsigned long".  The fact that you then cast
> that "unsigned long" value to "unsigned long long" does not cause the
> multiplication to be done in the type "unsigned long long".
> 
> You need to write something like
>     (unsigned long long) us * 0x000010c7 * HZ * (unsigned long long) lpj
> to get the multiplication to be done in the "unsigned long long" type.

 Though as a matter of coding style, personally I'd rather assigned "us" 
to a local variable of the "unsigned long long" type and performed all the 
calculations on it instead, avoiding any explicit casts and doubts as to 
what type is being used altogether.

  Maciej

      reply	other threads:[~2011-01-27 21:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <AANLkTinvdEPwQ=DmcF8nnTAa0Py_O=+p7x1pobcTNHom@mail.gmail.com>
     [not found] ` <AANLkTik8hQfd8cvNj=qeq5U=6zpQHw33a9hfK-q8+x1Z@mail.gmail.com>
     [not found]   ` <AANLkTikpUBtg2zz8tcbcz2rcG-O+fTFwb_pTi88uZe0h@mail.gmail.com>
     [not found]     ` <AANLkTi=zfr5YuwBCcvH2Jas50UxnUtvzp_CDyN25sT5h@mail.gmail.com>
     [not found]       ` <AANLkTim_swh58fCUxZ4e6MDrM9Lqrbm+1ufnp8W767JL@mail.gmail.com>
2011-01-27  9:20         ` loody
2011-01-27 11:29           ` Sergei Shtylyov
2011-01-27 12:28             ` loody
2011-01-27 21:38               ` Ian Lance Taylor
2011-01-27 21:43                 ` Maciej W. Rozycki [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LFD.2.00.1101272138520.25047@eddie.linux-mips.org \
    --to=macro@linux-mips.org \
    --cc=gcc-help@gcc.gnu.org \
    --cc=iant@google.com \
    --cc=linux-mips@linux-mips.org \
    --cc=miloody@gmail.com \
    --cc=sshtylyov@mvista.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).