Turbo C++ 3.0 bugs

Holger Veit holger.veit at ais.fraunhofer.de
Wed Dec 14 06:46:29 CST 2005


woodelf wrote:

> 9000 VAX wrote:
>
>> I met a problem in Watcom C 11.0. I uses wcl which makes 8086 code.
>> The code is running on a 386. I got wired result with
>> printf("%x %x %x ",inportb(H_ADDR2), inportb(H_ADDR1), 
>> inportb(H_ADDR0));
>>
>> but the following code worked as expected,
>> printf("%x ", inportb(H_ADDR2));
>> printf("%x ",inportb(H_ADDR1));
>> printf("%x ", inportb(H_ADDR0));
>>
>> The hardware is straightforward and unlikely to have problem. I don't
>> have time to determine the real source of this problem, though.
>
The problem has to do with the evaluation order of function arguments. 
Typically, in C this is right to left, i.e.
expect an inportb(H_ADDR0) to be executed first, second the H_ADDR1, 
third the H_ADDR2.
If no the reading of H_ADDR0 influences the result on port H_ADDR1 and 
or H_ADDR2, then you get
different results compared to the triple printf. However, the compiler 
is free to evaluate subexpressions in any
order, provided they are evaluated before the final function is called. 
Thus, it is technically undefined what is
printed for instance for printf("%d %d %d", i++,i--,i -= 3);

The compiler has all rights to produce code that yields different 
results for both code fragments.

Holger




More information about the cctalk mailing list