Dear all,
The default name for a pascal procedure does not work correctly anymore. (See the output for version number and so on below).
Explicitly declaring the name works, so a workaround is available. That can be done as follows: procedure p_routine; attribute (name='P_routine')
If I am making a mistake somewhere, I would be glad to hear.
Regards,
Marten Jan de Ruiter
% gpc --version gpc 20030830, based on gcc-3.2.1
% cat c_unit.c #include <stdio.h>
extern void c_routine(); extern void P_routine();
void c_routine() { printf("c_routine invoked\n"); P_routine(); printf("c_routine done\n"); }
% cat use_c_unit.p program test_c_unit;
(*$L c_unit.c *)
procedure c_routine; external name 'c_routine' ;
procedure p_routine; begin writeln('pascal routine invoked'); end;
begin c_routine; p_routine; end.
% gpc --automake use_c_unit.p -o use_c_unit c_unit.o: In function `c_routine': c_unit.o(.text+0x13): undefined reference to `P_routine' collect2: ld returned 1 exit status
# hmmm... does P_routine actually exist? Or does it have another name? % gpc -c --automake use_c_unit.p ; grep P_routine use_c_unit.o Binary file use_c_unit.o matches
# Now I am stuck...
On Mon, Mai 10, 2004 at 12:36:11 +0200, Marten Jan de Ruiter wrote:
Dear all, The default name for a pascal procedure does not work correctly anymore. (See the output for version number and so on below).
Following works:
program test_c_unit; (*$L c_unit.c *) procedure c_routine; external name 'c_routine' ; procedure p_routine; attribute (name = 'p_routine'); begin writeln('pascal routine invoked'); end;
begin c_routine; p_routine; end.
#include <stdio.h> extern void c_routine(); extern void p_routine();
void c_routine() { printf("c_routine invoked\n"); p_routine (); printf("c_routine done\n"); }
Eike
Marten Jan de Ruiter wrote:
The default name for a pascal procedure does not work correctly anymore. (See the output for version number and so on below).
Explicitly declaring the name works, so a workaround is available. That can be done as follows: procedure p_routine; attribute (name='P_routine')
As Eike has already stated, this is not a work-around, but the "official" way. Relying on the default linker name was never a good idea, I've been saying this for years. (And with qualified identifiers, the default linker names will (must) become different again.)
Actually, it's quite simple. If you want to link it as foo, declare it so. This way, you don't have to use these ugly first-capital names either. :-)
Frank
On Tuesday 11 May 2004 02:39, you wrote:
Marten Jan de Ruiter wrote:
The default name for a pascal procedure does not work correctly anymore. (See the output for version number and so on below).
Explicitly declaring the name works, so a workaround is available. That can be done as follows: procedure p_routine; attribute (name='P_routine')
As Eike has already stated, this is not a work-around, but the "official" way. Relying on the default linker name was never a good idea, I've been saying this for years. (And with qualified identifiers, the default linker names will (must) become different again.)
Actually, it's quite simple. If you want to link it as foo, declare it so. This way, you don't have to use these ugly first-capital names either. :-)
Frank
I agree that explicit coding is preferable to relying on default behaviour. However, for older gpc compilers, the attribute approach does not work. Of course, I could start detecting which compiler is used, set proper environment variables, and so on. A better approach seems to be to verify which compilers are used by my colleagues. It might very well be that no older compiler is used, and I am making it hard for myself unnecessarily.
Hopefully I can throw out the ugly constructs as #ifdef PASCAL #define GPC_EXTERNAL external c #define GPC_ASMNAME asmname #else #ifdef GPC_NEW #define GPC_ASMNAME external name #define GPC_EXTERNAL external #else #ifdef GPC_OLD #define GPC_ASMNAME asmname #define GPC_EXTERNAL C #else #error none of PASCAL, GPC_OLD and GPC_NEW defined #endif #endif #endif
Var X_stringtoput : string80 ; GPC_ASMNAME 'x_stringtoput' ;
Thanks for the help.
Regards,
Marten Jan de Ruiter
Marten Jan de Ruiter wrote:
I agree that explicit coding is preferable to relying on default behaviour. However, for older gpc compilers, the attribute approach does not work.
Yes, but `asmname' (except for very very old ones perhaps ;-).
Of course, I could start detecting which compiler is used, set proper environment variables, and so on.
You can test the compiler version like this. No need for extra environment variables.
{$if __GPC_RELEASE__ >= 20030303} { new external syntax } {$else} { old external syntax } {$endif}
(And `{$ifdef __GPC__}', if other compilers may be used.)
A better approach seems to be to verify which compilers are used by my colleagues. It might very well be that no older compiler is used, and I am making it hard for myself unnecessarily.
Of course, sometime you'll want to fade out the old syntax, but waiting for GPC 2.2 (e.g.) could be reasonable.
Frank
: "It would be painful to fix, but it's a lot less painful to fix _now_ : rather than later, so maybe the right thing is to just do it and : watch people scream in agony." (Linus Torvalds, LKML, 1998-10-28)