Eike Lange wrote:
Porting a library to a GNU Pascal Unit sometimes means putting a variable instead of a constant.
Like this:
foo.c:
int _c_konstant = DEFINED_CONSTANT_IN_C;
Do you mean `const int _c_konstant ...'? Otherwise, it's not a constant in C.
foo.pas:
unit Foo;
interface
{!! Treat them as constant !!} var Konstant: Integer; asmname '_c_konstant'; external;
implementation
{$L foo.c}
end.
Doing it this way means a lack of using these "constants" in a "case" statement. It would be nice to have a feature like:
const Konstant = _c_konstant;
or similar.
Better similar. ;-) Your suggested syntax would put an asmname in the place where a value is expected if I understand it correctly. Furthermore, an untyped constant won't work because somehow the Pascal compiler must know the type.
So I'd favour something like
const Konstant: Integer; external; asmname '_c_konstant';
(i.e., mostly like a variable). But maybe also something like this would be better:
var Konstant: const Integer; external; asmname '_c_konstant';
This would probably require less syntax contortions. But in both cases, I'd have to check if it causes any parsing difficulties.
Frank