Accessing I6 compiler constants from Inform 7

I’d like to access certain compiler constants (namely, GOBJ_TOTAL_LENGTH and NUM_ATTR_BYTES) from an Inform 6 inclusion in Inform 7-- unfortunately there doesn’t seem to be a good way to do this?

By default, Inform 7 throws saying something like

Problem: unable to find definitions for the following name(s): NUM_ATTR_BYTES.

However, if I attempt something like

#Ifndef NUM_ATTR_BYTES;
Constant NUM_ATTR_BYTES = 7;
#Endif;

I7 compiles without complaint, but then I6 decides to complain that

File "Build/auto.inf"; Line 582	# Error:  "NUM_ATTR_BYTES" is a name already in use and may not be used as a new constant name (Defined constant "NUM_ATTR_BYTES" was defined at compiler setup).

Is there a good way to do this, or will I just have to hardcode?

1 Like

What exactly is the failure mode here?

My guess is that the complaint about not having a definition is coming from the I6-to-Inter compilation stage (because the Inter compiler doesn’t have that compiler constant) while the I6 error is coming from the I6-to-Glulx compilation stage (because the I6 compiler does have that compiler constant, plus the definition applied during the I6-to-Inter stage where the #ifndef condition was true).

If that’s the case, I’m not sure that there’s any way to write the I6 inclusion such that it will evaluate to the desired value (i.e. the actual value of the compiler constant). Can the I7 compiler decide to change this from its default? If not, maybe you don’t have to worry much about it and can just use your own constant or global with a value of 7.

1 Like

This seems sensible, yeah. I’ll hardcode it and leave a comment with instructions on what to do if the invariant changes. Thanks!

I believe the new syntax for accessing constants across kits is going to fix this problem, when the next release comes out. Right now the way that works is a big mess which means use options need to be hard-coded into the compiler(!) so that their constants can be accessed in the right places.

2 Likes

Just in case you haven’t come across it yet, there’s a bit of syntax that does work in 10.1.2 which might help a little. Something like

Use attribute bytes of at least 7 translates as (- Constant ALT_NUM_ATTR_BYTES = {N}; -).

will default to a value of 7, but still allow override at the I7 level for someone using the extension. All they have to enter is

Use attribute bytes of at least 8. [or 9 or 10 or whatever]

You’ve already gotten some workarounds, but the canonical answer is: no, Inform v10 no longer supports accessing constants specific to the I6 compiler because those would be unavailable in any other compilation target.

(Even though, effectively, nobody compiles I7 to anything else yet.)

Though, you can create a kit that specifies which compilation targets it supports, and I believe you can access the constants there.

1 Like