Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Visual Assist
 Technical Support
 Parsing problem: Defining symbol using macro

You must be registered to post a reply.
Click here to register.

Screensize:
UserName:
Password:
Format: BoldItalicizeUnderlineStrikethrough Align leftCenterAlign right Insert horizontal ruleUpload and insert imageInsert hyperlinkInsert email addressInsert codeInsert quoted textInsert listInsert Emoji
   
Message:

Forum code is on.
Html is off.

 
Check to subscribe to this topic.
   

T O P I C    R E V I E W
KirillMueller Posted - Jul 10 2009 : 04:32:54 AM
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?
5   L A T E S T    R E P L I E S    (Newest First)
feline Posted - Jul 13 2009 : 09:50:54 AM
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.
KirillMueller Posted - Jul 10 2009 : 4:19:42 PM
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...
feline Posted - Jul 10 2009 : 4:02:03 PM
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.
KirillMueller Posted - Jul 10 2009 : 3:56:35 PM
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.
feline Posted - Jul 10 2009 : 3:44:25 PM
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.

© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000