Recent

Author Topic: inline c code  (Read 11955 times)

Emil_Halim

  • New member
  • *
  • Posts: 9
inline c code
« on: June 19, 2015, 12:12:18 pm »
Hi all,

does Fpc supports inline c code just like inline asm ?

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: inline c code
« Reply #1 on: June 19, 2015, 12:19:21 pm »
It is not. You should use static linking of object files in this case, as many fpc library bindings do

Emil_Halim

  • New member
  • *
  • Posts: 9
Re: inline c code
« Reply #2 on: June 19, 2015, 12:45:47 pm »
Ok thanks ,

does it is in todo list ?

Laksen

  • Hero Member
  • *****
  • Posts: 802
    • J-Software
Re: inline c code
« Reply #3 on: June 19, 2015, 01:02:52 pm »
No

Leledumbo

  • Hero Member
  • *****
  • Posts: 8835
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: inline c code
« Reply #4 on: June 19, 2015, 03:04:17 pm »
and will never be

Emil_Halim

  • New member
  • *
  • Posts: 9
Re: inline c code
« Reply #5 on: June 19, 2015, 04:21:24 pm »
and will never be

so why even Fpc supports static linking of c object files , and why there is  a tool h2paspp.exe

if you do not like  c/c++ , sometimes you need some c code , so instead of compile externally it with gcc , you can inline it with your free pascal code.

i think it is not  a bad idea.
 

Edited

BTW that is your own opinion , it is open source code , so i can make it by myself.
 
« Last Edit: June 19, 2015, 04:24:38 pm by Emil_Halim »

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: inline c code
« Reply #6 on: June 19, 2015, 04:34:00 pm »
BTW that is your own opinion , it is open source code , so i can make it by myself.
You mean writing your own C compiler? yes, that's possible.

Once done, you can submit it as a patch to FPC.

Septe

  • Jr. Member
  • **
  • Posts: 68
Re: inline c code
« Reply #7 on: June 19, 2015, 05:06:43 pm »
Let's reverse the question.  Would you agree that C/C++ should have inline Pascal code?

The only reason why we have inline asm is that assembler is much closer to the machine.  The only way to get even closer is to write machine language.  No one is going to write in machine language unless they absolutely have to.  As for Pascal and C/C++, both are considered high level languages which makes no sense in creating inline (your favorite high level language).  If you want your favorite high level language, just use that language.   :D

As for Leledumbo's opinion that it'll never happen.  Consider it a very highly educated opinion which I happen to agree with.

Emil_Halim

  • New member
  • *
  • Posts: 9
Re: inline c code
« Reply #8 on: June 19, 2015, 05:14:31 pm »
yes,  i am talking about something like this

Code: [Select]

program  MyPrg;

{$ASMMODE intel}

procedure GetTen;assembler;
asm
    mov eax, 10
    ret
end;


{$MODE C_code}
int strLen(char* p)
{
   char* s=p;
   while(*p++!=0);
   return s-p;
}

{$MODE FPC_code}

var
     Mystr : String;
     len    : longint;
Begin
     
     Mystr := "combing pascal and c like c++builder is good";
     len := strLen(@Mystr);
end.

the point here is ,you have a good function in c code , instead of reinvent the wheel , just put it in fpc code.

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: inline c code
« Reply #9 on: June 19, 2015, 05:34:44 pm »
ah. For that you should be using "fpcc" rather than "fpc".
"fpcc" parses your pascal input files strips C-sources off.
Compiles C-sources generating object files.
Then it compiles pascal files using "fpc", without inline C-code, linking the object files.
"fpcc" can be easily plugged into Lazarus.

Emil_Halim

  • New member
  • *
  • Posts: 9
Re: inline c code
« Reply #10 on: June 19, 2015, 05:42:17 pm »
thank you skalogryz,

where can i find information about fpcc.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8835
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: inline c code
« Reply #11 on: June 19, 2015, 06:20:17 pm »
so why even Fpc supports static linking of c object files
Object files are not linked to language. You can perfectly link with object files produced by any compiler for any language, as long as the format is compatible.
and why there is  a tool h2paspp.exe
It's for h2pas to run, to help converting C header files to Pascal units.
if you do not like  c/c++ , sometimes you need some c code , so instead of compile externally it with gcc , you can inline it with your free pascal code.

i think it is not  a bad idea.
It's a really damn bad idea, it complicates the compiler, it introduces additional dependencies to external tools (OK, we have this feature, people with no C compiler then try it, then it doesn't work, what would they say? ship C compiler with FPC installation? nuts!). It's not just an opinion, it's an objection! :P

Emil_Halim

  • New member
  • *
  • Posts: 9
Re: inline c code
« Reply #12 on: June 19, 2015, 06:48:48 pm »
It's not just an opinion, it's an objection! :P

your objection is nothing for me , and does not make any sens.

i will go on my way.

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: inline c code
« Reply #13 on: June 19, 2015, 06:51:59 pm »
where can i find information about fpcc.
it doesn't exist. Someone (you?) need to write it.

Emil_Halim

  • New member
  • *
  • Posts: 9
Re: inline c code
« Reply #14 on: June 19, 2015, 06:59:19 pm »
ok i will thank you very much for your help.

 

TinyPortal © 2005-2018