code question

Ian Lance Taylor iant@google.com
Thu Sep 27 04:46:00 GMT 2012


On Wed, Sep 26, 2012 at 6:18 PM, JD <jd1008@gmail.com> wrote:
> I came across this patch which could be cause of a bug.
>
> What are possible side effects of this
> code segment if compiled under various
> non-gnu C compilers, and GCC compilers?
>
>>+inline uint32_t NS_MIN(uint32_t a, uint64_t b)
>>+{
>>+  return b < a ? b : a;
>>+}
> Nit: Please cast the 64-bit variable to 32-bit in case compilers start
> warning about it.
>
>>+      *pProgress = NS_MIN<PRUint64>(totalBytes - bytesLeft,
>> PR_UINT32_MAX);

It's very hard to determine the behaviour of an incomplete program.
It's even harder when you show us two incompatible code fragments.
You are defining a non-template function NS_MIN and calling a template
function NS_MIN.  I would expect a compiler error.  I don't know what
you are seeing.

The basic groundrules for this kind of question are: tell us precisely
what you did, tell us precisely what happened, and tell us what you
expected to happen instead.

Ian



More information about the Gcc-help mailing list