[3.2 RC5] Unable to use #define value copied from another #define

Started by Crimson Wizard, Sun 13/06/2010 20:01:16

Previous topic - Next topic

Crimson Wizard

Example:

Code: ags

#define A 1
#define B A

int a[A];
int b[B];

function F()
{
   int aa = A;
   int bb = B;
}


Compiler will show 2 errors -
1) on line "int b[ B ];" error is "Array size must be constant value"
2) on line "int bb = B;" error is "undefined symbol 'A'"


Kweepa

I don't think this has ever worked - it's not new to 3.2RC5.
You'll have to work out what B is by hand.
Still waiting for Purity of the Surf II

Joe

I think it doesn't in C++ either, since B is just replaced by A but that A is not replaced at all since it's treated as a variable name.
Copinstar © Oficial Site

Pumaman

This is a limitation of AGS's support for #define.

Ideally I want to add "const int" support instead to do this properly, but I understand why it's annoying that you have to duplicate definitions if you want two constants sourced off the same value.

Crimson Wizard

Quote from: Joe Carl on Sun 13/06/2010 22:38:21
I think it doesn't in C++ either, since B is just replaced by A but that A is not replaced at all since it's treated as a variable name.
No, that's incorrect.
The "defined" macro is being literally replaced by its value BEFORE actual compilation. Thus, in C/C++ it will work.

EDIT: Huh, I realized I explained not very clear.
What I mean is that if you have
Code: ags

#define A 1
#define B A

in C/C++, then, at first, all A instances will be replaced, and it will become like this
Code: ags

#define A 1
#define B 1

- in "temporary" code.

Joe

Hmm it's interesting to know... thanks for the info and sorry :-\
Copinstar © Oficial Site

Gilbert

I think preprocessing of the script in AGS' script compiler is limited, so that's precisely why it won't work, otherwise, things like int blah[2x4] and forward reference of functions should be possible as well.

Monsieur OUXX

So, in the end, how does it work in AGS?
Does the pre-compiler replace "A" with "1" even in the statement "#define B A"?

I don't think so, otherwise the error {int b[ B ];" error is "Array size must be constant value"} would not happen. Does that mean that AGS's pre-complier does not replace macros when they are in other macros' definitions?
 


Monsieur OUXX

Quote from: Crimson Wizard on Mon 14/06/2010 14:23:20
Quote from: Monsieur OUXX on Mon 14/06/2010 13:54:01
So, in the end, how does it work in AGS?

Quote from: Pumaman on Sun 13/06/2010 22:54:04
This is a limitation of AGS's support for #define.

It doesn't answer my question, sir, with all due respect, sir.  :)
What will cause an error? What won't? How can I reproduce the issue in advance in my not-so-powerful brain in order to anticipate its occurrence?  :)
 

Crimson Wizard

Oh, sorry.
Well, I guess then something like this is correct: "AGS's pre-complier does not replace macros when they are in other macros' definitions".  ;)

But Chris Jones knows better...  :P

Monsieur OUXX

Quote from: Crimson Wizard on Mon 14/06/2010 15:45:05
Chris Jones knows better...  :P

Chris! Where did I lose my wallet last week? And WHY won't you tell me!?! Why do you keep repeating '42'? Are you my father? Did you create AGS with the cruel goal of torturing nerds? Don't you know that great power brings great responsibility?
 

SMF spam blocked by CleanTalk