Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Crimson Wizard on Sun 13/06/2010 20:01:16

Title: [3.2 RC5] Unable to use #define value copied from another #define
Post by: Crimson Wizard on Sun 13/06/2010 20:01:16
Example:


#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'"

Title: Re: [3.2 RC5] Unable to use #define value copied from another #define
Post by: Kweepa on Sun 13/06/2010 20:20:11
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.
Title: Re: [3.2 RC5] Unable to use #define value copied from another #define
Post by: Joe 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.
Title: Re: [3.2 RC5] Unable to use #define value copied from another #define
Post by: Pumaman on Sun 13/06/2010 22:54:04
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.
Title: Re: [3.2 RC5] Unable to use #define value copied from another #define
Post by: Crimson Wizard on Sun 13/06/2010 22:58:32
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

#define A 1
#define B A

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

#define A 1
#define B 1

- in "temporary" code.
Title: Re: [3.2 RC5] Unable to use #define value copied from another #define
Post by: Joe on Sun 13/06/2010 23:17:29
Hmm it's interesting to know... thanks for the info and sorry :-\
Title: Re: [3.2 RC5] Unable to use #define value copied from another #define
Post by: Gilbert on Mon 14/06/2010 02:30:28
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.
Title: Re: [3.2 RC5] Unable to use #define value copied from another #define
Post by: Monsieur OUXX on Mon 14/06/2010 13:54:01
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?
Title: Re: [3.2 RC5] Unable to use #define value copied from another #define
Post by: 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.
Title: Re: [3.2 RC5] Unable to use #define value copied from another #define
Post by: Monsieur OUXX on Mon 14/06/2010 15:28:40
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?  :)
Title: Re: [3.2 RC5] Unable to use #define value copied from another #define
Post by: Crimson Wizard on Mon 14/06/2010 15:45:05
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
Title: Re: [3.2 RC5] Unable to use #define value copied from another #define
Post by: Monsieur OUXX on Mon 14/06/2010 16:11:13
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?