Hacker Newsnew | past | comments | ask | show | jobs | submit | shdown's commentslogin

Could somebody please check how it converts the following program:

    #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.


Typecasts seem to trip it up, it replaces the check with

    if (unsigned char then 255) + ((unsigned char) 255) = 510 then  begin


I'm not particularly familiar with Delphi, but the issue here appears to be a combination of parenthetical grouping not being picked up and the program not knowing that "unsigned char" should become "byte".

Ex:

  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.


  Location: Moscow, Russia
  Remote: Yes
  Willing to relocate: No
  Technologies: Python, C, C++, Lua
  Résumé/CV: https://shdown.github.io/resume.pdf
  Email: shdownnine@gmail.com
Hello, I am Python/C/C++ developer, Google Summer of Code participant, author of a number of open-source projects. I have experience of developing infrastructure, bots and various utilites for analysis of order flow and algorithmic trading on a number of cryptocurrency exchanges for a private start-up company.

I enjoy solving challenging problems of various kinds.

I am looking for full-time as well as part-time jobs in software development.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: