
C to Delphi converter (2018) - peter_d_sherman
https://github.com/WouterVanNifterick/C-To-Delphi
======
S_A_P
FL Studio is/was Delphi based but I got to believe that it’s been ported to
c/c++ in light of the Mac version that’s now available. I know there is kylix
but I can’t imagine that was the way it was ported. But maybe so. I actually
maintain a Delphi app used for trucking and logistics that the company
purchased the source code for. We have a vm sitting on our server farm that is
hosting an image of a highly customized version of Delphi that’s our “build”
server. We are going to port this to C# second half of the year. The dude made
all sorts of UI snafus, like 4 way check boxes using multi color checks for
security provisioning. To add insult to injury if you have any color blindness
you cannot perform this task- red, violet, green and blue are the options. I
don’t have any known color blindness and it’s hard for me to tell.

~~~
ebj73
I think Image-Line is still using Object Pascal actually, both for the PC and
the Mac version of FL Studio. They've been managing the Mac version by using
Free Pascal for the compilation. They also have a fair amount of inline
assembly, for the performance critical parts, and they have their own in-house
GUI and widget library, which, apparently, will compile and run equally well
using both Delphi and Free Pascal.

Edit: I notice that the post below says they're using Delphi for both the PC
and the Mac version now... It could be a recent development. Last year there
were posts on the Image-Line forums saying they were still using Free Pascal,
due to the fact that Delphi (at that point) could not produce 64 bit binaries
for Mac.

~~~
wila
Delphi still cannot produce 64 bit binaries for macOS.

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

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

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

~~~
avuxo
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.

------
raister
Where exactly is Delphi being used nowadays?

~~~
haolez
I've seen it recently being used in industrial automation. The IDE is friendly
to non-programmers, the generated binaries perform really well and the
compilation times are very fast.

From my perspective, as a developer that uses more up-to-date tools, Delphi is
not great, but it's not bad either.

~~~
syockit
My experience with Delphi-based Windows software is that they always load
quickly and and most things are snappy, in contrast to most modern programs.
I've always wondered if it's due the language itself, but then again modern
programs run in managed environment. I guess if the same program is created
using MFC they would be just as fast. Maybe if you don't have to deal with
accessibility or internationalization it's possible to create such binaries in
any compiled unmanaged language.

------
loeg
Does it know when to use 1-indices for accessing converted C strings vs
0-indices for other types? That seems to be one difficult thing to infer
dynamically, especially for non-constants. I suppose it could just always
treat C char* as dynamic arrays.

It does appear to treat C string constants as Pascal string constants, so if
those are to be indexed correctly, it must be somewhat clever.

------
v-yadli
Sounds like there’s no macro support?

Edit: in that case, better target FreePascal or Lazarus.

~~~
FartyMcFarter
Also no "typedef", "unsigned char", "unsigned long" support, nor apparently
understanding of what "char *argv[]" means as a function parameter. So don't
expect this is something you can use for arbitrary C code.

Still an interesting teaching tool, as long as the user understands it's very
limited.

------
childintime
I was pleasantly surprised, does a lot of things, very useful for when it's
needed.

It had one unexpected glitch:

    
    
        // C
        if (known_devices & BIT(0))
    
        // Pascal
        if known_devices and BIT(0 then )

------
vfclists
It seems there a quite a number of people who are not that hot on C++, Qt or
both.

The FreePascal guys though have put in some effort to create useable LCL
interfaces (the Lazarus equivalent of Delphi's VCL) to interfaces to Qt4 and
Qt5

------
int_19h
How does it compare to C2PAS?

