Adriaan van Os wrote:
Frank Heckenbach wrote:
I'm not yet changing the fact that `asmname' implies `external' for routines -- this should be done, too, but I'd rather do it together with other incompatible changes later.
However, unless there's heavy resistance, I'd like to deprecate the `c' and `c_language' directives, and drop them in a later release. So,
procedure Foo; c;
should be turned to:
procedure Foo; external name 'foo';
Well, I think it is good use to write preprocessor macros for different cases.
I think one generally shouldn't use preprocessor macros in Pascal at all. ;-)
So, if the compiler changes, it would be a matter of changing the macro.
It's not like this syntax is supposed to change again and again -- that's why I'm trying to determine the best future syntax now. There are some changes necessary for several reasons, and I can't do them all at once, but at least I'll try to do them so that each thing will be changed at most once.
What about a plain `external' without `name' or `asmname'? Currently, this keeps the "default" asmname (first letter uppercase, the rest lowercase). Some time in the future, we'll need name mangling (for qualified identifiers and overloading), so the default asmname will be something ugly which one should not have to know about in order to write interfacing C code or such.
Of course, it would be possible to make `external' set the first-uppercase-asmname even then, but I'm not sure how useful this is. (Currently, it's chosen as the default to avoid linker conflicts with "usual" C routines, but with name mangling, this won't be an issue.)
So, to me it seems more reasonable to make a plain `external' set the asmname to all-lowercase (just like `c' and `c_language' do now). Then,
May I suggest a compiler switch --fliteral-asmnames ? It would set the asmname to match the name in the procedure/function header literally. With this switch, in the interface part of a unit the declaration
procedure myProc;
would imply
procedure myProc; asmname 'myProc'; external;
No, it wouldn't. `external' means that the procedure is defined somewhere else, while a normal interface definition means that it is defined in the implementation of the unit (mostly like a `forward' declaration).
Secondly, the letter-casing of Pascal identifiers should have no relevance to the program semantics, i.e.
procedure MYpROC; external;
and
procedure myProc; external;
must yield the same thing.
The practical background is interfacing with the MacOS Carbon toolbox. In the current situtation, I have to add a GPC-conditional "asmname 'myCarbonProc"" to 15.000 API routines
I suggest you write `external; asmname 'foo';' now, and with the next GPC you can do a simple global replacement `external; asmname' -> `external name'.
either by hand (not nice) or with a sed script (that maybe somebody has ready for me).
If the declarations are all one-liners, and the letter-casing is the same that should be used for asmnames, try this (using GNU awk -- I'm not using sed because it doesn't seem to have an easy way to match `procedure' and `function' case-insensitively, and because an awk script can be better extended if necessary):
#!/bin/sh gawk ' BEGIN { IGNORECASE = 1 } $1 == "procedure" || $1 == "function" { n = $2 sub ("[^a-z0-9_].*", "", n) print $0 " external name '"'"'" n "'"'"';" } '
Frank