J
Hello list
I have tried to migrate a program from Visual C++ version 4 to Visual C++ version 6 - and failed.
I pinpointed the failure down to the following error:
Several places make use of the ? operator in C in the following way:
a?b:c=d;
(this is a simplification of the actual code)
The idea is: depending on the value of a assign value d to either b or c. This is all following the definition of ANSI C and also following what is found in the help files provided with the compiler.
However the compiler treats this equally to:
a?b
c=d);
ie if a is true nothing happens and if a is false c will get the value of d.
the value of d is not even evaluated if a is true.
There is a simple workaround to this by changing the code to:
(a?b:c)=d;
but I would of course not want to do that in some 1000+ places and possibly miss a few one (and thereby introducing bugs) but I will probably do it if no other solution is found.
Does anyone have any other information about this?
(I have reported this in a bug report to microsoft approx a year back but I have not seen anything about this from them so far)
/Johan Bengtsson
----------------------------------------
P&L, the Academy of Automation
Box 252, S-281 23 H{ssleholm SWEDEN
Tel: +46 451 49 460, Fax: +46 451 89 833
E-mail: [email protected]
Internet: http://www.pol.se/
----------------------------------------
I have tried to migrate a program from Visual C++ version 4 to Visual C++ version 6 - and failed.
I pinpointed the failure down to the following error:
Several places make use of the ? operator in C in the following way:
a?b:c=d;
(this is a simplification of the actual code)
The idea is: depending on the value of a assign value d to either b or c. This is all following the definition of ANSI C and also following what is found in the help files provided with the compiler.
However the compiler treats this equally to:
a?b
ie if a is true nothing happens and if a is false c will get the value of d.
the value of d is not even evaluated if a is true.
There is a simple workaround to this by changing the code to:
(a?b:c)=d;
but I would of course not want to do that in some 1000+ places and possibly miss a few one (and thereby introducing bugs) but I will probably do it if no other solution is found.
Does anyone have any other information about this?
(I have reported this in a bug report to microsoft approx a year back but I have not seen anything about this from them so far)
/Johan Bengtsson
----------------------------------------
P&L, the Academy of Automation
Box 252, S-281 23 H{ssleholm SWEDEN
Tel: +46 451 49 460, Fax: +46 451 89 833
E-mail: [email protected]
Internet: http://www.pol.se/
----------------------------------------