Library calls in GPC 
Author Message
 Library calls in GPC

Hello!

I'm trying to make use of ncurses library with GPC compiler.
I managed to use library calls that require strings as input
with

type    WINDOW=integer;
        string80=cstring;
procedure waddstr(win: WINDOW; s:string80); C;

and it works, but I can't get any C function called from Pascal
to return a string as output. Trying to call something like

procedure wgetstr(win: WINDOW; var s:string80); C;

gives a coredump. How can I make it work?

I'm using GPC:
2.1 (20020510), based on gcc-2.95.4 20011002 (Debian prerelease)

with Linux RH8.0, kernel 2.4.18
glibc-2.2.93-5
ncurses-5.2-26

Pawel



Mon, 22 Aug 2005 17:28:20 GMT  
 Library calls in GPC

Quote:

> Hello!

> I'm trying to make use of ncurses library with GPC compiler.
> I managed to use library calls that require strings as input
> with

> type       WINDOW=integer;
>    string80=cstring;
> procedure waddstr(win: WINDOW; s:string80); C;

> and it works, but I can't get any C function called from pascal
> to return a string as output. Trying to call something like

> procedure wgetstr(win: WINDOW; var s:string80); C;

I'm no GPC authorithy, but IIRC GPC has a CString type to deal with C
connectivity. Try to look it up in the manual to see how to use it.


Tue, 23 Aug 2005 21:25:49 GMT  
 Library calls in GPC

Quote:

>>Hello!

>>I'm trying to make use of ncurses library with GPC compiler.
>>I managed to use library calls that require strings as input
>>with

>>type  WINDOW=integer;
>>      string80=cstring;

                  ^^^^^^^

Quote:
>>procedure waddstr(win: WINDOW; s:string80); C;

>>and it works, but I can't get any C function called from pascal
>>to return a string as output. Trying to call something like

>>procedure wgetstr(win: WINDOW; var s:string80); C;

> I'm no GPC authorithy, but IIRC GPC has a CString type to deal with C
> connectivity. Try to look it up in the manual to see how to use it.

In fact I'm using "cstring" at the moment,
and it works well only one way: by passing string TO procedure/function,
but I can't get a string FROM procedure/function (via "var")
even with "cstring" type.

In the meantime I managed to partially solve problem by using
a little work-around with "packed array [0..80] of char",
and some support procedures, but it is not as clean as with "cstring".

Thanks

Pawel



Sun, 28 Aug 2005 19:30:55 GMT  
 Library calls in GPC
Pawel Ludwikow a crit:

Quote:
> Hello!

> I'm trying to make use of ncurses library with GPC compiler.
> I managed to use library calls that require strings as input
> with

> type    WINDOW=integer;
>     string80=cstring;
> procedure waddstr(win: WINDOW; s:string80); C;

> and it works, but I can't get any C function called from pascal
> to return a string as output. Trying to call something like

> procedure wgetstr(win: WINDOW; var s:string80); C;

> gives a coredump. How can I make it work?

> I'm using GPC:
> 2.1 (20020510), based on gcc-2.95.4 20011002 (Debian prerelease)

> with Linux RH8.0, kernel 2.4.18
> glibc-2.2.93-5
> ncurses-5.2-26

I cannot check because I have not these functions on my system (djgpp).
Did you understand that cstring is not the string itself (array of char)
but a pointer on such an array, declared as

type cstring = ^char;

(in pascal it would be better declared as
type cstring = ^array [0..maxint] of char;)

this is done so to be equivalent to C's construct
char *

It is completely different from pascal's string which is directly
the array, with some extras, length, capacity (maximum length).
This is the most confusing part for people more used to pascal
than to C.
I would prefer to note this PChar rather than Cstring,
but people who use frequently this for C system interfacing are more
used to C and prefer to be nearer to the C construct.
You can also declare
type Pchar=cstring
if you prefer ...

Maurice

--
        Maurice Lombardi
Laboratoire de  Spectrometrie Physique,
Universite Joseph Fourier de Grenoble, BP87
38402 Saint Martin d'Heres Cedex     FRANCE
Tel: 33 (0)4 76 51 47 51
Fax: 33 (0)4 76 63 54 95



Wed, 31 Aug 2005 05:05:09 GMT  
 Library calls in GPC
Pawel Ludwikow a crit:

Quote:
> Hello!

> I'm trying to make use of ncurses library with GPC compiler.
> I managed to use library calls that require strings as input
> with

> type    WINDOW=integer;
>     string80=cstring;
> procedure waddstr(win: WINDOW; s:string80); C;

> and it works, but I can't get any C function called from pascal
> to return a string as output. Trying to call something like

> procedure wgetstr(win: WINDOW; var s:string80); C;

> gives a coredump. How can I make it work?

> I'm using GPC:
> 2.1 (20020510), based on gcc-2.95.4 20011002 (Debian prerelease)

> with Linux RH8.0, kernel 2.4.18
> glibc-2.2.93-5
> ncurses-5.2-26

I cannot check because I have not these functions on my system (djgpp).
Did you understand that cstring is not the string itself (array of char)
but a pointer on such an array, declared as

type cstring = ^char;

(in pascal it would be better declared as
type cstring = ^array [0..maxint] of char;)

this is done so to be equivalent to C's construct
char *

It is completely different from pascal's string which is directly
the array, with some extras, length, capacity (maximum length).
This is the most confusing part for people more used to pascal
than to C.
I would prefer to note this PChar rather than Cstring,
but people who use frequently this for C system interfacing are more
used to C and prefer to be nearer to the C construct.
You can also declare
type Pchar=cstring
if you prefer ...

Maurice

--
        Maurice Lombardi
Laboratoire de  Spectrometrie Physique,
Universite Joseph Fourier de Grenoble, BP87
38402 Saint Martin d'Heres Cedex     FRANCE
Tel: 33 (0)4 76 51 47 51
Fax: 33 (0)4 76 63 54 95



Wed, 31 Aug 2005 05:07:12 GMT  
 Library calls in GPC

Quote:

>> ncurses-5.2-26

> I cannot check because I have not these functions on my system (djgpp).
> Did you understand that cstring is not the string itself (array of char)
> but a pointer on such an array, declared as

> type cstring = ^char;

> (in pascal it would be better declared as
> type cstring = ^array [0..maxint] of char;)

> this is done so to be equivalent to C's construct
> char *

> It is completely different from pascal's string which is directly
> the array, with some extras, length, capacity (maximum length).
> This is the most confusing part for people more used to pascal
> than to C.
> I would prefer to note this PChar rather than Cstring,
> but people who use frequently this for C system interfacing are more
> used to C and prefer to be nearer to the C construct.
> You can also declare
> type Pchar=cstring
> if you prefer ...

Pchar is a bit special. In BP compatible languages it can be overindexed,
even though it is ^char. So you can do x[5] with x being a pchar, which is
exactly similar to the c notation. Since it requires special code anyway,
you could allow it to accept a unsigned type, thus allowing the full range
of the natural pointer (and not just half of it.

Delphi extends this kind of indexing to _all_ simple types afaik.



Wed, 31 Aug 2005 06:56:19 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Calling c libraries from pascal

2. Call C code library in Pascal

3. Pascal program calling C libraries

4. check voice call or data call

5. File processing, locking with gpc and FreePascal

6. GPC: longreal, how many bits?

7. portable source (from Borland to GPC, FPC...)

8. Full-featured debugger, and pretty-printer, for GNU Pascal (gpc)

9. I need libgpc and gpc -263b

10. condensed X11 interface for GPC

11. GPC errors on Solaris

12. pascal compiler error (gpc)

 

 
Powered by phpBB® Forum Software