#define macros & call_other() weirdness

I am in the process of porting our current MudOS-based mud to FluffOS, and I am encountering an issue that I believe to be a bug in the driver. It occurs when you have a nested #define macro that is being used with the ‘->’ call_other() syntax. Here is what I am working with as well as the results:


#define NAHENET(str)      "/d/islands/nahenet/"+str
#define NSTD(str)         NAHENET("nstd/"+str)
#define NAHENET_D         NSTD("nahenet_d")

eval --include /d/islands/nahenet/path.h return NAHENET_D;
Result = “/d/islands/nahenet/nstd/nahenet_d”

eval --include /d/islands/nahenet/path.h return NAHENET_D->query_water_level();
Error = *Error. Could not find object: nahenet_d
(I patched the driver so that call_other() would note the object it failed to find.)

eval --include /d/islands/nahenet/path.h return (NAHENET_D)->query_water_level();
Result = 0 <-- Expected result

The only difference between the 2nd and 3rd eval tests was that the NAHENET_D macro was wrapped in parenthesis. This is unexpected behavior, and it seems to be with the preprocessor parsing, perhaps? This does not occur on our old MudOS driver. Is there a different way this should be done? On our production MUD, which is still on MudOS, we write our macros a little differently, but we had to change it because FluffOS wouldn’t parse them properly.

This is what we would normally do:

#define NAHENET(str)      "/d/islands/nahenet/str"
#define NSTD(str)         NAHENET("nstd/str")
#define NAHENET_D         NSTD("nahenet_d")

Any help or advice would be greatly appreciated. While I can go through and fix any instances that are broken by wrapping the defines in parenthesis, we have tens of thousands of files in our library, and it seems to me that something somewhere is not correct.

Thank you!

in your style 1, the preprocessor is replacing text into

"/d/island/nahenet" + "nstd/" + "nahenet_d"->query_xxx()

that’s why you are getting an object not found issue.

The correct way of writing marco with token pasting is like this

#define NAHENET(str)      "/d/islands/nahenet/" ##str
#define NSTD(str)             NAHENET("nstd/" ##str)
#define NAHENET_D       NSTD("nahenet_d")

This is the same rule as C/C++ , you can checkout https://www.geeksforgeeks.org/and-operators-in-c/ , the old style you mentioned is a backward incompatible change we can’t re-introduce. (beside that the syntax doesn’t conform to C standard)

Thank you for the quick and concise response! I have tested the syntax you provided and can confirm that this works. I appreciate you looking into this as this helps me out a lot!