Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
User name:
Password:
Save Password
Forgot your password?

 All Forums
 Visual Assist
 Technical Support
 Parsing problem: Defining symbol using macro
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

KirillMueller
Ketchup Master

72 Posts

Posted - Jul 10 2009 :  04:32:54 AM  Show Profile  Reply with Quote
In the following sample (.cpp file), the symbols STR_1 and STR_2 are not recognized correctly (IntelliSense, coloring, ...).


#ifdef RC_INVOKED

#define DECLARE_TEXT(NUM, STR, TEXT) NUM TEXT
STRINGTABLE FIXED PURE
BEGIN

#else

#define DECLARE_TEXT(NUM, STR, TEXT) STR = NUM,
enum StringIds {

#endif

DECLARE_TEXT(1, STR_1, "My string 1")
DECLARE_TEXT(2, STR_2, "My string 2")


#ifdef RC_INVOKED

END

#else

};

#endif
#undef DECLARE_TEXT



int main()
{
   return STR_1;
}


Things change if the logic of the first preprocessor construct is reversed:


#ifndef RC_INVOKED

#define DECLARE_TEXT(NUM, STR, TEXT) STR = NUM,
enum StringIds {

#else

#define DECLARE_TEXT(NUM, STR, TEXT) NUM TEXT
STRINGTABLE FIXED PURE
BEGIN

#endif

DECLARE_TEXT(1, STR_1, "My string 1")
DECLARE_TEXT(2, STR_2, "My string 2")


#ifndef RC_INVOKED

};

#else

END

#endif
#undef DECLARE_TEXT



int main()
{
   return STR_1;
}


Obviously, VAX blindly enters the #if alternative, without recognizing that RC_INVOKED most probably isn't defined in C++ files. Is this by design, or just a missing feature?

feline
Whole Tomato Software

United Kingdom
19022 Posts

Posted - Jul 10 2009 :  3:44:25 PM  Show Profile  Reply with Quote
VA is designed to parse and be active in both branches of a #if #else #endif statement, and in all #if #endif statements, even if they are "inactive".

Partly this is so that you will get help from VA when working on "inactive" code. Partly this is because it is sometimes impossible for VA to work out which code is actually active and which is inactive.

So re-ordering the code should help. If you only have a few situations like this you could try adding the "official" macro version to VA's stdAfx.h file:

http://docs.wholetomato.com?W302

so our parser will realise this is the version you want to use.

zen is the art of being at one with the two'ness
Go to Top of Page

KirillMueller
Ketchup Master

72 Posts

Posted - Jul 10 2009 :  3:56:35 PM  Show Profile  Reply with Quote
Please check my understanding of VAX's logic:

VAX basically ignores preprocessor conditionals when parsing. When a macro is defined multiple times, VAX uses the first definition. This is the reason why reordering has helped in the example above.

Edited by - KirillMueller on Jul 10 2009 3:57:16 PM
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19022 Posts

Posted - Jul 10 2009 :  4:02:03 PM  Show Profile  Reply with Quote
This is normally correct, yes. The fist macro seen is the one that should be used.

If the macro's are defined in several different ways, in several different files, in several different libraries then you can get more complex results, since VA might find them in a different order on different days.

zen is the art of being at one with the two'ness
Go to Top of Page

KirillMueller
Ketchup Master

72 Posts

Posted - Jul 10 2009 :  4:19:42 PM  Show Profile  Reply with Quote
Thank you. Reordering is a workaround I can live with :-)

However, have you considered not evaluating conditional branches where the result of the evaluation of the conditional is known, like in the example above? Or using _both_ definitions of a macro, at least in simple cases where the macro does not invoke other macros? Only suggestions...
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19022 Posts

Posted - Jul 13 2009 :  09:50:54 AM  Show Profile  Reply with Quote
First the #if statements, consider two simple examples:

#ifdef DEBUG

and

#ifdef WIN32

these are things VA will probably know, but if your solution is set to build release mode while you are editing code for debug mode, or you are editing code that will be executed on a different OS you are still likely to want help from VA.

You can always find examples to argue this both ways, but since we want VA to help as much as possible, as often as possible, our design makes sense.

I am not sure how using both macro definitions would work. If a macro is involved in defining the type of a variable, which is very common, using both macro's means a variable has two different types at once. That is going to cause problems for listboxes, etc.

zen is the art of being at one with the two'ness
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000