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
 Macro evaluation with C structs
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

DerTester
New Member

3 Posts

Posted - Apr 06 2018 :  02:57:29 AM  Show Profile  Reply with Quote
Visual Assist 10.9.2258.5, built 2018.03.06
VS 2015 German

I noticed a problem regarding macro evaluation. The following example code shows a simple main.cpp of a Win32 console application:



teststruct_t is correctly color-highlighted, but nevertheless marked as "unrecognized symbol".

Another problem arises, if the macro and the structure declaration are shifted to a header file.

main.h:


main.cpp:


Now teststruct_t is neither color-highlighted in the declaration inside the header file nor in the definition of the variable inside the source file. Alt+G jump doesn't work anymore.

Even changing the PACKSTRUCT macro to
#define PACKSTRUCT( decl ) decl

doesn't change the situation.

Thanks for your help!

Edited by - DerTester on Apr 06 2018 12:54:00 PM

feline
Whole Tomato Software

United Kingdom
18983 Posts

Posted - Apr 06 2018 :  10:29:40 AM  Show Profile  Reply with Quote
Are you compiling this code as C++, C, or something else?

I have created a new, default C++ Win32 console application, typed in this code, but it does not compile for me. The first error is on the line:

PACKSTRUCT(struct teststruct_t

where I am told "this declaration has no storage class or type specifier"

I am using VS2015 and VA 2258.

I wanted to make sure this compiled, so that when testing some changes to try and get VA to understand this, I could make sure that my changes still compiled.

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

DerTester
New Member

3 Posts

Posted - Apr 06 2018 :  12:52:45 PM  Show Profile  Reply with Quote
In this small example application it is actually compiled as C++ (it's main.cpp not main.c, sorry). But it should compile also as C, because the original project, I took the code from, is an embedded C project.

In case you can't compile it, I can add the VS solution? But not before monday.

Thanks for your effort so far!
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18983 Posts

Posted - Apr 07 2018 :  06:52:25 AM  Show Profile  Reply with Quote
This compiles as pure C, so this is how I am testing and checking this.

I am not surprised that VA is a bit confused, I don't think I have ever seen this done before, I am just not used to seeing structures wrapped in macros.

It turns out that the C pre-processor works a bit differently to the C++ pre-processor in VS2015. I never knew that. My first plan was to split this into two macros, one at the start and one at the end of the structure, which I could then try to hide from VA. However macros with unmatched brackets are failing to compile in pure C, when they do work in C++.

Do you have many structures like this?

Is there another syntax that can be used to achieve the same results? I am trying to find a work around for you, since that will be faster than waiting for a change to our parser to handle this situation.

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

DerTester
New Member

3 Posts

Posted - Apr 09 2018 :  12:45:22 AM  Show Profile  Reply with Quote
Yes, two macros (at beginning and end) would be possible of course. That's how I would have done it and btw did it in other projects.

Unfortunately, the PACKSTRUCT macro is part of an external library. So, I don't want to change the syntax there. If you find a workaraound without changing the syntax, that would be great. But if not, I would really appreciate it, if your parser could handle this in a future version.

Thanks so far! VA is a fantastic tool!
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18983 Posts

Posted - Apr 09 2018 :  12:25:35 PM  Show Profile  Reply with Quote
If you want to have a go at this yourself, from this page it should be possible to get the macro call to be composed by the pre-processor, with a macro before and after the struct. Once this has been done, if it can be done, hiding these macros from VA should be fairly easy. There are some hints here:

https://stackoverflow.com/questions/34637283/using-preprocessor-macros-to-compose-another-macro-call#34637503

but its not clear how to convert them into something that works in this situation.

I have put in a bug report for this, but since this is a fairly strange edge case I am not sure how quickly we will be able to look at this for you.

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