CA65 nested includes and macros.

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
CA65 nested includes and macros.
by on (#145645)
Say I have a source file, entities.asm, which is structured roughly like this:

Code:

.linecont +
.include "ndxdebug.h"
.include "entities.inc"
.include "entity.inc"

.segment "ROM05"
.include "enemy1.inc"



And in entity.inc I have a macro:

Code:

.macro my_macro

;do fun stuff with code

.endmacro



Then say my enemy1.inc includes a file called enemy1_constants.inc:

Code:

;define a bunch of constants here

;now try to use the macro from entity.inc

my_macro   ;DOES NOT COMPILE!!!




I find that in this inner include file, I can see equates and other symbols that had been previously included in entity.asm but not macros unless I re-include the header file containing the desired macro.

Does anyone understand this behavior? I did not see any comments about macros having different visibility rules within includes.

If this is known/correct behavior of CA65 it is tempting me to factor out all my macro definitions in each module into its own header file, and re-include them where needed...
Re: CA65 nested includes and macros.
by on (#145646)
It definitely shouldn't behave like that. Have you been able to make a minimal test which reproduces the behavior?
Re: CA65 nested includes and macros.
by on (#145648)
Upon trying a very minimal test with the same structure as defined above, I can definitely see a macro two includes deep. So, I'm not yet sure what is going on. I think I'll go off on a branch, add the failing code and then whittle this down til I understand the problem. I'll post back here with what I find.
Re: CA65 nested includes and macros.
by on (#145649)
Argh, nevermind. The root of the problem was that I am including my enemy_constants.inc files elsewhere (they are essentially interfaces to entities when you need information about their state logic or constants, etc.) and I didn't have the macros included in those scopes.