I want to write a macro which should compatible with gpc version 2.1 and look like below
#define PAS_EXTERNAL_C(X) asmname 'X'
suppose if i define a macro like above, it should be preprocessed like below
Before preprocessing:
procedure Hello; PAS_EXTERNAL_C(Hello);
After preprocessing:
procedure Hello; asmname 'Hello';
I am worried why #define PAS_EXTERNAL_C(X) asmname 'X' this is not working?
Please help me
Regards Hari
__________________________________ Start your day with Yahoo! - Make it your home page! http://www.yahoo.com/r/hs
vanam srihari kumar wrote:
I want to write a macro which should compatible with gpc version 2.1 and look like below
#define PAS_EXTERNAL_C(X) asmname 'X'
suppose if i define a macro like above, it should be preprocessed like below
Before preprocessing:
procedure Hello; PAS_EXTERNAL_C(Hello);
After preprocessing:
procedure Hello; asmname 'Hello';
I am worried why #define PAS_EXTERNAL_C(X) asmname 'X' this is not working?
Macros do not replace in string literals. Currently, you can use the C-compatible "stringify" operator #, like this:
{$define PAS_EXTERNAL_C(X) asmname #X}
(I'm using here the Pascal form {$...} rather than the C form #..., BTW.)
However, note that the stringify operator is one the more obscure C-preprocessor features that is subject to change in GPC in the future. So be prepared to change it in the future.
An alternative (that many use, AFAIK), is to use a string argument to the macro:
{$define PAS_EXTERNAL_C(X) asmname X}
procedure Hello; PAS_EXTERNAL_C ('Hello');
Also note that in more recent GPC versions, "asmname" does not imply "external", and "asmname" is deprecated (will be dropped in the future) because it's not really about asm in the first place.
So you might want to write:
{$if __GPC_RELEASE__ >= 20030303} {$define PAS_EXTERNAL_C(X) external name X} {$else} {$define PAS_EXTERNAL_C(X) asmname X} {$endif}
Frank