Hello folks,
(* This mail is somehow long. In short: I want to take
the directives `Extern', `C', and `AsmName' *out* of GPC
and extend the syntax of `External' instead. Okay? :*)
as you know (?;-), we have the directives `External', `Extern'
(same as `External'), `C', and `AsmName' in GPC for specifying
external procedures. This is especially useful when using
libraries written in C, for example:
Procedure Foo; External; (* yields "Foo" *)
Procedure ioCtl ( FilDes, Cmd: …
[View More]Integer; ... ); C; (* yields "ioctl" *)
Procedure XOpenDisplay ( Name: __CString__ );
AsmName 'XOpenDisplay';
This turned out not to be enough; we need the same for variables.
Actually we already have
Var
Foo: __external__ Integer; (* yields "foo", not "Foo"! *)
but this does not cover cases where the external variable needs a
name with a capital letter.
As an intermediate solution, I implemented
Var
Foo: __asmname__ 'foO' Integer;
(patched source is available on demand), but I think it is not the best
way to implement these things.
Now I am looking out for reasonable ideas.
Does somebody know what the ISO/ANSI Standards say about this?
My own thoughts follow.
I would suggest to define as few directives as possible and to
drop everything but `External' but extend its syntax to meet our
requirements. A first approach could be
Procedure foo; external; (* yields "Foo" *)
Var
x: Integer; external; (* yields "X" *)
and
Procedure foo; external 'foO';
Var
x: Integer; external 'my_x';
but it would crash with Borland Pascal's use of `External' where
the latter declaration would mean that Procedure foo is contained
in a shared library named `foO'.
Okay, so let's stay for the moment at Borland's syntax. In the
same context they also define
Procedure foo; external 'MySharedLib' index 42;
and
Procedure foo; external 'MySharedLib' name 'foO';
where `foO' would be the external name as defined in the shared
library.
My current idea now would be to define
Procedure foo; external; (* yields "Foo" *)
Var
x: Integer; external; (* yields "X" *)
plus
Procedure foo; external name 'foO';
Var
x: Integer; external name 'my_x';
to replace "AsmName 'foO'". Later we can extend this to allow a
name of a shared library between `external' and `name'.
Once doing this, it could also be nice to make directives out of
the other C-style storage qualifiers, too. I mean I'd like to
replace
Var
x: __static__ Integer; by x: Integer; static;
y: __volatile__ Integer; by y: Integer; volatile;
etc.. My plan is to do it in a way that things like
Var
static: Integer;
would still work.
I think it would *not* be a good idea to make
Procedure foO; external;
yield "foO", because (i) it would be difficult to implement and
(ii) Pascal is a case-insensitive language, so everything outside
string constants *must not* depend on casing at all.
Please tell me your opinion about this.
Yours,
Peter
e-mail: peter.gerwinski(a)uni-essen.de
home address: D\"usseldorfer Str. 35, 45145 Essen, Germany
WWW: http://agnes.dida.physik.uni-essen.de/~peter
[View Less]
Hi,
Is there a version of gpc built for Solaris 2.5? Or do you
have any hints on getting the lastest source to compile
under Solaris 2.5?
Thanks
Brad Zoltick
NIH
Email: brad(a)codon.nih.gov
> When I try to compile anything, even the simplest program, I get:
> /usr/i486-linux/bin/ld: cannot open crt0.o: No such file or directory
Perhaps the versions of GCC and GPC you are using don't coincide.
Please check the following:
gpc -c myprogram.pas
gcc myprogram.o -o myprogram
i.e. compile with GPC, but link with GCC.
Did you already check that crt0.o is in a directory where GPC can
find it? I remember some problems when I had crt0.o in the directory
/usr/lib/gcc-lib/i486-…
[View More]unknown-linux/2.6.3. The problems disappeared
when I moved the file to /usr/lib or /usr/local/lib.
Good luck,
Peter
e-mail: peter.gerwinski(a)uni-essen.de
home address: D\"usseldorfer Str. 35, 45145 Essen, Germany
WWW: http://agnes.dida.physik.uni-essen.de/~peter/
[View Less]
According to Berend de Boer:
> Can we not simply see a C .h file as an interface-only module? I mean I can
> simply import a c .h file which gpc parses and all symbols defined in that
> header file are exported symbols?
This would mean that GPC would have to parse C source.
Remember that #include "foo.h" or (*$include "foo.h" *) just means
that GPC treads the file `foo.h' just if its contents were written
in our source file. A Pascal program using this mechanism would
in fact look …
[View More]like the following:
Program Test;
extern int foo;
extern void ioctl (int fildes, int cmd, ...);
begin
[...]
end.
You don't actually want this. ;-)
> I don't know how far this is feasible. And it doesn't cover a.out modules
> creating using other languages (GNAT, ...). But it does cover the majority of
> cases you need externals.
You can write a C header file for everything you want to import,
independently of the language it was originally written in. Our
point is that it must also be possible to write a *Pascal* interface
for everything we want to import.
Peter
e-mail: peter.gerwinski(a)uni-essen.de
home address: D\"usseldorfer Str. 35, 45145 Essen, Germany
WWW: http://agnes.dida.physik.uni-essen.de/~peter
[View Less]
> Now I am looking out for reasonable ideas.
Can we not simply see a C .h file as an interface-only module? I mean I can
simply import a c .h file which gpc parses and all symbols defined in that
header file are exported symbols?
I don't know how far this is feasible. And it doesn't cover a.out modules
creating using other languages (GNAT, ...). But it does cover the majority of
cases you need externals.
Groetjes,
Berend.
Hello Patricio,
> I currently teaching Operative System to students who only know Pascal,
> so I'd like to know if we can use
> Unix System calls in pascal programs wirh GPC ? I mean stuff like
> 'fork()', 'exec()', etc...
You can access any function using the "external", "C", and "asmname"
directives:
Procedure fork; external;
means: there is an external Procedure "Fork" (first letter uppercase),
Procedure fork; C;
means: there is an external Procedure "fork" (…
[View More]everything lowercase), and
Procedure fork; asmname 'foO';
means: there is an external Procedure with the funny name "foO"
(last letter is uppercase in this example) which can be accessed
from Pascal via the name "fork".
Good luck,
Peter
[View Less]
Hi,
I currently teaching Operative System to students who only know Pascal,
so I'd like to know if we can use
Unix System calls in pascal programs wirh GPC ? I mean stuff like
'fork()', 'exec()', etc...
Thanks in advance,
Patricio.
Hi all. I've had this error ever since I installed gpc, and I've never
figured out why. I'm not all that experienced at unix. When I try to
compile anything, even the simplest program, I get:
/usr/i486-linux/bin/ld: cannot open crt0.o: No such file or directory
Sorry if this seems like such a stupid question. Any ideas?
-john