Author Topic: redefining %define ?  (Read 3275 times)


  • Guest
redefining %define ?
« on: January 28, 2006, 06:11:54 AM »

I have a bunch of constants that I use in both my nasm source code and my C source code.  Currently, I keep the nasm version and the C version of the constants in separate include files (for example for nasm and myconsts.h for C).  But these are the same constants and I want to prevent the possibility for them becoming out of sync.  Is there some way of redefining the %define so that I can use one include file?  So, if I had just a C version of the constants in a file (myconsts.h) like:

#define CONST1    100
#define CONST2    101
#define CONST3    102
#define CONST4    103...etc

then I could use something like:

%define #define %define
%include "constdef.h"

Does anyone know of a way to make this work?  Or any other way of using one file to maintain constants for both NASM and C?


  • Guest
Re: redefining %define ?
« Reply #1 on: January 28, 2006, 09:07:57 AM »
I did add support for switching from '%' to '#'
in the NASM64 preprocessor. Still, there are a
number of differences between NASM and CPP; for
example, NASM counts smac arguments before ex-
panding them, while CPP does it the other way
around. That said, you might want to look into
using a third-party preprocessor (such as M4 or
ML/1) or a scripting language (such as Perl).


  • Guest
Re: redefining %define ?
« Reply #2 on: January 28, 2006, 09:46:11 AM »
Allowing an assembler to read #define's out of an .h file is an obvious idea that most assemblers missed. (Kudos to nasm64developer for getting it right!)

Johannes Kroll has written a utility to do the conversion - can be made part of your build process to keep synchronized with changing .h files. Works pretty good - not perfect. I understand that there's another version in the works - this is what I've got...



  • Guest
Re: redefining %define ?
« Reply #3 on: January 28, 2006, 06:55:21 PM »
Thanks for your help.  I look forward to NASM64 since it will be able to handle this directly.  (Forgive me for being clueless, but NASM64 is not yet available, correct?)

And thanks for your help Frank.  I'm going to give h2incn a shot.