Forum > General

Can I mix pascal and C together?

(1/2) > >>

regg:
I want to make a few programs using pascal, but might need to use C for some low level stuff. How can I easily mix C and pascal together? Can I just rewrite what I want to do with C in pascal instead? I might need to interface with some hardware, that's why C might come into the picture.

MarkMLl:
Start off looking at the h2pas utility.

MarkMLl

Warfley:
Usually you can pretty easiely rewrite C to Pascal, but you can also link pascal and c code together and call C functions from pascal.

There are just a few things to keep in mind when linking pascal and C together, Pascal has managed memory (strings, dynamic arrays), C doesn't, these won't survive the transition between C and Pascal code. Also when linking C and pascal together, you should use the C memory manager from the cmem unit (must be the first unit in the uses clause of your lpr)

PascalDragon:

--- Quote from: regg on May 09, 2021, 03:10:09 pm ---I want to make a few programs using pascal, but might need to use C for some low level stuff. How can I easily mix C and pascal together? Can I just rewrite what I want to do with C in pascal instead? I might need to interface with some hardware, that's why C might come into the picture.

--- End quote ---

You can just as well use Pascal for that. Usually you only need to worry about C if you need to interface with some library written in C.

Blade:

--- Quote from: regg on May 09, 2021, 03:10:09 pm ---I want to make a few programs using pascal, but might need to use C for some low level stuff.... I might need to interface with some hardware, that's why C might come into the picture.

--- End quote ---

Pascal can do low level stuff and interface with hardware.  So you might want to be more specific.  If you are just talking in the more generalized sense and as a future possibility, probably best to just focus on Pascal for the present and immediate future.  Maybe don't worry about it until the use case shows itself.

Navigation

[0] Message Index

[#] Next page

Go to full version