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 Error in Visual Micro, OK in Arduino IDE (Read 1292 times)
NF1Z
Junior Member
**
Offline


Posts: 49
Joined: Aug 18th, 2013
Error in Visual Micro, OK in Arduino IDE
Jan 5th, 2020 at 9:46pm
Print Post  
Sorry, Hard to come up with a short meaningful title.

I was having some odd issues with a project, and eventually tried this very simplified sketch, taken from a cppreference.com example of user-defined literals:

Code (C++)
Select All
// used with custom type
struct mytype
{
    unsigned long long m;
};
constexpr mytype operator"" _mytype ( unsigned long long n )
{
    return mytype{n};
}
void setup () {};
void loop () {};
 




It compiles fine in the Arduino IDE 1.8.5, but I get the following error from Visual Micro:

MyType.ino: 4:11: error: 'mytype' does not name a type

Clearly, this is wrong. First thing I noticed is that the error location info is completely off, which in the past has sometimes indicated a glitch in VS/VM, and has often gone away when restarting VS or rebooting the PC.  But not this time.

I will email you the output from both VM and the IDE.

Thanks, best regards,
Jed

  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Error in Visual Micro, OK in Arduino IDE
Reply #1 - Jan 5th, 2020 at 10:23pm
Print Post  
You need to put user types in a .h or add prototypes at the correct location
Code
Select All
// used with custom type
struct mytype
{
    unsigned long long m;
};

//prototypes
constexpr mytype operator"" _mytype ( unsigned long long n );

//methods that use the user type in its signature
constexpr mytype operator"" _mytype ( unsigned long long n )
{
    return mytype{n};
}

void setup () {};
void loop () {};

 




The arduino ide used to place ptototypes above the first line of code then it improved slightly but is not bullet proof yet. For now, add them to the correct location manually (which also means your code would be same as normal .cpp files)

  
Back to top
WWW  
IP Logged
 
NF1Z
Junior Member
**
Offline


Posts: 49
Joined: Aug 18th, 2013
Re: Error in Visual Micro, OK in Arduino IDE
Reply #2 - Jan 5th, 2020 at 10:35pm
Print Post  
I looked some more and there is a considerable difference between MyType.ino.cpp (generated by the IDE) and MyType.cpp (by VM), used in the command lines to compile the project/sketch.  Naturally, I don't know how different they are supposed to be, but I am assuming they should be pretty close as the object code  is usually identical.  
I notice that the VM file omits the struct definition, hence the "not a type" error, but it also omits the pair of double quotes after the operator keyword, as though they were elided.

Anyhow, that seems to indicate some kind of problem in VM, so outside my expertise.

Cheers,
Jed
  
Back to top
 
IP Logged
 
NF1Z
Junior Member
**
Offline


Posts: 49
Joined: Aug 18th, 2013
Re: Error in Visual Micro, OK in Arduino IDE
Reply #3 - Jan 5th, 2020 at 10:47pm
Print Post  
Tim,
Thanks for that, and it does work, but still confused about why the IDE does not need the prototypes.  I do have the Project property Generate Prototypes set to true.  I understood that would make VM work identically to the IDE.  Not so?

Also, I have to say, a very misleading diagnostic!   

Jed
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Error in Visual Micro, OK in Arduino IDE
Reply #4 - Jan 5th, 2020 at 10:47pm
Print Post  
If you click the project in the solution explorer so that it is selected and press F4 to show the properties you can switch off Automatic prototype generation. Then the code should be your code with your own prototypes.

Also ensure that the toolbar is set to release and not debug so that we are compating apples with apples.

Then the combined .ino code should be your code with an arduino.h added to it.

Please confirm that resolves?

update: please give valid simple ino code example that compiles in the arduino ide but not visual micro
« Last Edit: Jan 5th, 2020 at 10:50pm by Tim@Visual Micro »  
Back to top
WWW  
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Error in Visual Micro, OK in Arduino IDE
Reply #5 - Jan 5th, 2020 at 10:54pm
Print Post  
When errors are in auto generated prototypes it is difficult to get the correct source line numbers because the code does not exist in your own code.

The arduino used to work same as visual micro. they have made an improvement that we will shortly adopt but it is still not 100% so adding your own prototypes is supported by both visual micro and the arduino ide. It is about the only difference and I think arduino are working on something better so we are waiting to implement.

Leaving the auto generate prototype on is fine, visual micro will skip that step if you have added your own prototypes. Your previous but one post suggested some code difference unlreated to prototypes betwen visual micro and arduino but I suspect that might have been the debugging?
« Last Edit: Jan 5th, 2020 at 10:55pm by Tim@Visual Micro »  
Back to top
WWW  
IP Logged
 
NF1Z
Junior Member
**
Offline


Posts: 49
Joined: Aug 18th, 2013
Re: Error in Visual Micro, OK in Arduino IDE
Reply #6 - Jan 6th, 2020 at 4:10am
Print Post  
Tim,
Not sure about the F4, it doesn't seem to do anything, but if I select project properties from the toolbar,
and turn off Generate Prototypes, it works without the added prototypes, and also in IDE of course.  The lessons I am taking are (1) Generate Prototypes should be false for compatibility with the current IDE, and (2) it's always good to have the prototypes in the .ino file.

Thanks,
Jed
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Error in Visual Micro, OK in Arduino IDE
Reply #7 - Jan 6th, 2020 at 11:09am
Print Post  
Generate prototypes can be on. I think I confused things by mentioning them. However if you want to always add your own prototypes then it can be off.

Alternatively put your types in a .h so they can be shared outside of the .ino
« Last Edit: Jan 6th, 2020 at 11:09am by Tim@Visual Micro »  
Back to top
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint