by shdown · 7y ago · 0 comments
#include <stdio.h>
int main()
{
if (((unsigned char) 255) + ((unsigned char) 255) == 510) {
puts("yes");
} else {
puts("no");
}
}
(The code outputs "yes", and it does not rely on undefined behavior.)In other words, I doubt that proper “conversion”, with all the C semantics, is feasible.
if (unsigned char then 255) + ((unsigned char) 255) = 510 then beginEx:
unsigned char a = 255;
unsigned char b = 255;
if ((a + b) == 510) {
puts("yes");
}
becomes unsigned char a = 255;
unsigned char b = 255;
if a + b then = 510 then begin
WriteLn('yes');
end;
instead of var a,b: byte;
begin
a := 255;
b := 255;
if (a + b) = 510 then begin
writeln('yes');
end;
It's also worth noting that assuming parenthetical grouping is fixed, the C code snippet should work fine; according to the online compiler I was toying around with, Pascal uses integer type promotion.