Recent

Author Topic: GCC compatibility  (Read 10611 times)

Dansa

  • Newbie
  • Posts: 3
GCC compatibility
« on: August 25, 2008, 03:01:38 pm »
Would it not be a good idea if Lazarus could be made GCC-compatible?

1. Those who prefer could then use C++ syntax and have an alternative to C++ Builder.

2. Object Pascal code could be converted on-the-fly to C++ equivalent before passing it to GCC so that Lazarus gets a second compiler option for Object Pascal code, perhaps with better optimizations etc. (Remember that Borland uses the same compiler for Object Pascal and C++.)

Leledumbo

  • Hero Member
  • *****
  • Posts: 8835
  • Programming + Glam Metal + Tae Kwon Do = Me
RE: GCC compatibility
« Reply #1 on: August 25, 2008, 03:43:38 pm »
Err...no (at least for me). What kind of advantages can we get from it?

_1 := Any '100% correct C++ -> OP converter' available?

_2 := Reverse(_1)
Quote
perhaps with better optimizations etc.

Better optimizations? I don't think so. I get 'wrong code' (something like de-optimization) more often with GCC than FPC when optimizations are enabled.
Quote
Remember that Borland uses the same compiler for Object Pascal and C++

Then we can have a reverse of it (that 'same compiler' would be FPC)! Try to implement your first suggestion.

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 1222
    • Burdjia
Re: GCC compatibility
« Reply #2 on: August 26, 2008, 10:02:19 am »
Quote from: "Dansa"
1. Those who prefer could then use C++ syntax and have an alternative to C++ Builder.
There are other free IDEs for GCC, as KDevelop, DevCPP, RHIDE, etc. I don't think that another one is needed.

By the way, the Lazarus' editor recognizes C/C++ and some other languages so you can use it to edit code. I have both FPC and GCC installed in my system; most times I use Vim to edit and GNU's make to build even Pascal applications, I use Lazarus only for complex GUI applications.

Quote from: "Dansa"
2. Object Pascal code could be converted on-the-fly to C++ equivalent before passing it to GCC so that Lazarus gets a second compiler option for Object Pascal code, perhaps with better optimizations etc. (Remember that Borland uses the same compiler for Object Pascal and C++.)
As far as I know, FPC translates the Object Pascal code to Assembler. GCC also translates the C/C++ code to Assembler before to build the object file. I don't see benefits to translate from Object Pascal to C/C++ to Assembler. I'm not an expert about compilers but optimizations applicable to Pascal might be different than optimizations applicable to C so some possible optimizations would be "lost in translation".

The "de-optimization problem" of GCC is well known on the community. Even the FSF recommends to optimize code "by hand" in those cases.
Are you interested in game programming? Join the Pascal Game Development community!
Also visit the Game Development Portal

duncanparsons

  • Jr. Member
  • **
  • Posts: 83
RE: Re: GCC compatibility
« Reply #3 on: August 27, 2008, 02:36:40 am »
...as it goes, C++Builder ships with a number of compilers - the Borland C++ compiler for compiling your c and c++ code, the Delphi compiler for any IDE related compiling you need to do, and a BASM compiler for straight asm work.

It doesn't perform any translation from C/C++ -> Object Pascal before compiling, since there are some fundamental differences in the languages which are too great to write an automatic converter for (templates for one [NB FPC's templates/generics are not the same as C++ ones]). Also, Borland have had a superb reputation for writing fantastic C and C++ compilers, so why not just compile directly?

You are right that a Delphi compiler is included in CppB, but this is purely for building IDE packages, and the full VCL is not available to it. It would perhaps be possible to use that compiler for normal Object Pascal stuff, but it is likely that Borland put certain constraints on it to prevent this (in a similar way that D6PE and D7PE compilers will refuse to compile TDataSet derived components, even if the full source is presented to it).

Still, there aren't any open source C++ equivalents of CppB AFAIK, and it may well be possible to supply an alternative compiler and fudge the switches to get lazarus to do the job of compiling stuff, but you wouldn't get any of the benefit of the LCL (being OP), and there are far more elegant ways to write C++ apps :)

DSP

Dansa

  • Newbie
  • Posts: 3
GCC compatibility
« Reply #4 on: August 27, 2008, 04:45:18 pm »
OK,
I am no GCC expert, having used it only sporadically, but their homepage says there are already frontends for:
C, C++, Objective-C, Java, Fortran and ADA...

An ObjectPascal frontend for GCC is also reported to exist and to be at least partly Delphi-compatible, see:

http://www.gnu-pascal.de/gpc/h-index.html

There are no two compilers that are 100% correct or interchangeable, but you may still prefer one or the other for different projects and with open source it is often possible to solve incompatibility problems if needed.

I am no CPP-Builder expert either, but I believe I once saw someone from Borland stating that behind the scene there is really just one compiler engine for Delphi and CPP-Builder, but "dressed" up with different frontends, libraries and of course some tweaks for marketing reasons. I could be wrong though...

If you could manage to link object files from the two languages then it was my guess that component sets derived from OP and C++ should be able to coexist in the same IDE making C++ programmers more likely to contribute with code and also eliminating the need to manually translate code units, at least in simpler non-visual cases.

But, it was just a quick idea that came up, and I hope I have not offended anyone by talking C++ in this forum...

Leledumbo

  • Hero Member
  • *****
  • Posts: 8835
  • Programming + Glam Metal + Tae Kwon Do = Me
GCC compatibility
« Reply #5 on: August 28, 2008, 06:30:04 am »
Quote
An ObjectPascal frontend for GCC is also reported to exist and to be at least partly Delphi-compatible

Yes, partly. I mean, very partly. They don't even implement class!
Quote
There are no two compilers that are 100% correct or interchangeable

Even GCC is not 100% compatible with itself between platforms.
Quote
If you could manage to link object files from the two languages ...

I don't know the latest news, but I think it's still unsupported. Currently, you can try to flatten your C++ code to C then create it's Pascal unit counterpart. Using h2pas can save you some time (or not, depending on how complex it is. Especially if you have multiline macros). See C in Free Pascal.
Quote
... I hope I have not offended anyone by talking C++ in this forum...

No, you haven't. C/C++ family has. Especially when I know that they reinvent some Pascal features using different names. From standardpascal.org:
Quote
Today Pascal is being reinvented. Java reinvented type safety. C# and .net reinvented "managed pointers". I'm sure more principles will be taken from Pascal and its successors and called a "new invention", that's the way the world works, and has always worked.

 

TinyPortal © 2005-2018