Page 1 of 1

#define scope

Posted: 14 May 2011, 13:22 PM
by FFMan
I am using a #define to define the size of a queue for serial comms.

A function in a separate bas file needs to dimension (and initiialise) an array of the same size for recieving characters. If i try and reference the identifier declared in the main module i get a compiler error (reference to undefined identifier). if the code is not in a separate bas file i do not get the error.

i infer from this that the scope of identifiers does not extend to functions delcared in other files ?

If this is the case, what is the best way of achieving what i want without resorting to amending code in my separate source file that may be common to several main programs ?

thanks

Re: #define scope

Posted: 14 May 2011, 14:18 PM
by dkinzer
FFMan wrote:i infer from this that the scope of identifiers does not extend to functions delcared in other files ?
That is correct. The scope of a #define extends from the point at which it appears until either 1) the end of the file, or 2) a matching #undef.

For a constant value that is used in multiple modules, use a Const:

Code: Select all

Public Const MyQueueSize as Integer = 27

Posted: 14 May 2011, 14:26 PM
by FFMan
I'll use a const as well, i was trying to use an identifier for both compiler directives and dimensioning arrays, but i'll use an identifier and a const and that will be just as easy to maintain in reality.

thanks

Posted: 14 May 2011, 15:38 PM
by dkinzer
Another alternative for defining global constants is to put definitions in your .pjt file with the -D option. Such definitions are global in scope, i.e., they are known in all modules. These should be placed in the .pjt file before the modules in which you want the definition to be in effect.

Code: Select all

-DMyQueueSize=27