NASM - The Netwide Assembler
NASM Forum => Using NASM => Topic started by: stressful on April 22, 2018, 02:40:50 AM
-
I wonder if there's any side effects that I don't know of if I declare two similar externs in the same source (besides code replication). For example;
%macro ecall 1
extern %1
call %1
%endm
Of which I use to import external functions like below, without the need to declare separate externs for each;
ecall printf
ecall scanf
ecall printf ;this one is repeating the extern
So far I been using it without any problem, but still, I am not so sure.
Thanks for clarification.
-
That code is / would be fine.
ecall printf
would expand to
extern printf
call printf
Each time you call the macro it sets up your EXTERN and CALL code.
If you want to write
ecall printf
twice, you would need to modify your macro:
%ifndef ext_%1
%define ext_%1
extern %1
endif
call %1
That way you exclude the risk of bloating your code with multiple identical externs.
-
Thanks debs3759.
My suspicion actually came from other syntaxes that do not allow such repetitive declaration. It would translate to a syntax error. I am glad that NASM does allow it, making my life easier. Like some people say, a bug can be another's feature.