Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic "'myStruct' does not name a type" error only appearing with VisualMicro (Read 3212 times)
WielandB
Newbies
*
Offline


Posts: 4
Joined: Apr 28th, 2018
"'myStruct' does not name a type" error only appearing with VisualMicro
Apr 9th, 2019 at 8:35pm
Print Post  
I am currently developing a rather simple program, which is supposed to run on a ESP8266. It is not finished yet but I encountered a strange error.
I defined a struct for RGB colors and this did not cause any problems for a little while. But eventually, it produced a compiler error. Unluckily, I do not remember anymore what I did/changed when the error started to occur.
The really strange aspect of this is that this error only occurs in Visual Studio with the Visual Micro AddOn. When I open the .ino file with the Arduino IDE, it compiles just fine.

I completly reinstalled the Arduino IDE (all libraries and boards) and the VisualMicro AddOn.

The error is in the .zip file with the whole code due to the character limitation.

  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: "'myStruct' does not name a type" error only appearing with VisualMicro
Reply #1 - Apr 10th, 2019 at 4:59pm
Print Post  
Hi, 

Thanks for the example. 

Arduino and visual micro have to auto generate prototypes for functions if they do not exist. In the not too distant past arduino has changed to make a better job at automatic prototype insertion, although still not perfect. 

This is one of a couple of areas that visual micro differs from Arduino, but will shortly change/improve.  With visual micro (and c++) if you have your own types mixed in with your code you should insert prototypes at the location of that you choose.

A prototype is simply the exact same signature as the function in your code followed by a semi-colon ;

Code (C++)
Select All
typedef struct RGB
{
	union
	{
		byte r, g, b;
		byte arr[3];
	};
} RGB;


/ * insert c++ prototypes before they are used */

RGB rgb(byte r, byte g, byte b);


/* main program code below this line  */

RGB rgb(byte r, byte g, byte b)
{
	RGB color;
	color.r = r;
	color.g = g;
	color.b = b;
	return color;
}
 



For complex prototypes it is better to switch off "auto prototype generation" which can be done in the F4 project properties tool window.

tip: If you declare user defined types in #include files or add your ow prototypes then your .ino code will move more easily to .cpp files as the project grows
« Last Edit: Apr 10th, 2019 at 5:00pm by Tim@Visual Micro »  
Back to top
WWW  
IP Logged
 
WielandB
Newbies
*
Offline


Posts: 4
Joined: Apr 28th, 2018
Re: "'myStruct' does not name a type" error only appearing with VisualMicro
Reply #2 - Apr 11th, 2019 at 6:11pm
Print Post  
Thank you very much!
Now it compiles without any errors.
Am I correct that I am basically supposed to forward declare a function or similar before defining it, if I face similar errors in the future?
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: "'myStruct' does not name a type" error only appearing with VisualMicro
Reply #3 - Apr 11th, 2019 at 6:26pm
Print Post  
If you have functions in .ino that include user defined types in their signature then you should put the forward declarations where they make sense. The arduino ide will see you have done that and not attempt to duplicate the declarations.

It's an anomaly of c++ in arduino .ino. Alternatively declare your types in header files so they can more easily be re-used.

I expect the future will be more forgiving so not to worry if it works now it's fine.
  
Back to top
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint