From: | Boszormenyi Zoltan <zb(at)cybertec(dot)at> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Michael Meskes <meskes(at)postgresql(dot)org>, pgsql-hackers(at)postgresql(dot)org, Hans-Juergen Schoenig <hs(at)cybertec(dot)at> |
Subject: | Re: Question about ECPGset_noind_null() and ECPGis_noind_null() |
Date: | 2009-11-19 20:32:51 |
Message-ID: | 4B05AB73.4070708@cybertec.at |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Tom Lane írta:
> Boszormenyi Zoltan <zb(at)cybertec(dot)at> writes:
>
>> for (; length > 0 && ptr[--length] == 0xff;);
>>
>
>
>> I suspect that GCC does the "--length" after checking
>> "length > 0" and before checking the "ptr[...] == 0xff",
>> but HP CC does it before checking "length > 0".
>>
>
> If it does, that is *unquestionably* a bug in HP's CC and should be
> reported to them.
Is it *really* a bug? I recalled a comment from my C teacher
in '92 or '93 about this exact issue, that the prefix/postfix
increment/decrement operators are executed in the
statement in an implementation-defined order, i.e. they
can be freely reordered or placed anywhere in the
expression, provided that the postfix operator's evaluation
is earlier than the usage of the variable it's used on and
evaluation is later than the variable usage in the postfix case.
This means that their usage has to be minimized so the
result is unambiguous. I.e. in the common usage:
str1[pos1++] = str2[pos2++];
these execution orders are possible and all give the same result:
1. evaluate str2[pos2]
increment pos2
assign the above value to str1[pos1]
increment pos1
or
2. evaluate str2[pos2]
assign the above value to str1[pos1]
increment pos2
increment pos1
or
3. evaluate str2[pos2]
assign the above value to str1[pos1]
increment pos1
increment pos2
In the case of
for (; length > 0 && ptr[--length] == 0xff;);
the different evaluation orders may give different
expression results.
But 17 years is a long time, the C language specification
has changed a lot. GCC definitely does the most sensible
order but I didn't know this behaviour is specified in the
C language.
> However, the code is sufficiently unreadable to
> be worth rewriting anyhow. Your suggestion is an improvement but
> personally I'd plump for
>
> int i;
>
> for (i = 0; i < length; i++)
> if (ptr[i] != 0xff)
> return false;
> return true;
>
Yes, it's better than my version.
Best regards,
Zoltán Böszörményi
> regards, tom lane
>
>
--
Bible has answers for everything. Proof:
"But let your communication be, Yea, yea; Nay, nay: for whatsoever is more
than these cometh of evil." (Matthew 5:37) - basics of digital technology.
"May your kingdom come" - superficial description of plate tectonics
----------------------------------
Zoltán Böszörményi
Cybertec Schönig & Schönig GmbH
http://www.postgresql.at/
From | Date | Subject | |
---|---|---|---|
Next Message | Boszormenyi Zoltan | 2009-11-19 20:36:29 | Re: Question about ECPGset_noind_null() and ECPGis_noind_null() |
Previous Message | James Pye | 2009-11-19 20:12:34 | Re: Python 3.1 support |