Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Strange C++ syntax error(CDT syntax parser is choking on valid C++ code when class method is declared const)
Strange C++ syntax error [message #1797199] Sat, 27 October 2018 17:09 Go to next message
Martin Green is currently offline Martin GreenFriend
Messages: 1
Registered: October 2018
Junior Member
I'm a long-time C++ CDT user targeting several platforms, including Windows, BlackBerry 10, etc, but lately I've been using it with the Arduino plugin. I rely on CDT syntax checking to catch "dumb-programmer" errors, but I'm encountering an error report under a specific condition that doesn't make sense.

I have this class method definition...

uint16_t GFXmaster::height()  {

    uint16_t retVal;

    // ---Select slave
    digitalWrite( SS, LOW );

    // ---Send command type
    this->send( GfxCommand::GetHeight );

    retVal = this->get16();

    // ---Deselect slave
    digitalWrite( SS, HIGH );

    return retVal;
}

...which compiles normally and satisfies the CDT syntax parser. I realized, however, that I needed to change the method prototype to const, so the new definition is like this...

uint16_t GFXmaster::height() const  {

    uint16_t retVal;

    // ---Select slave
    digitalWrite( SS, LOW );

    // ---Send command type
    this->send( GfxCommand::GetHeight );

    retVal = this->get16();

    // ---Deselect slave
    digitalWrite( SS, HIGH );

    return retVal;
}

Like the original version, this compiles fine, but the CDT syntax parser now chokes on two lines...

this->send( GfxCommand::GetHeight );

and

retVal = this->get16();

These methods are at the ancestor level, and are prototyped thus...

protected:
    void send( byte value );
    uint16_t get16();


Although they compile fine, the CDT syntax parser reports the following errors...

Invalid arguments ' Candidates are: void  send(unsigned char) '
Invalid arguments ' Candidates are: unsigned  short int get16() '

Neither message makes any sense. Firstly, GfxCommand::GetHeight is declared as...

class GfxCommand {

public:
    enum Type : byte {

        GetHeight 
    };
};

...so the argument to send() is byte, which is the same as unsigned char, so CDT shouldn't complain.

Secondly, the get16() method returns uint16_t, which is the same as unsigned int, NOT unsigned short int as the syntax parser claims.

The ONLY change between the two scenarios is that the GFXmaster::height() method is declared const in the second case, and not in the first. Is this a CDT syntax parser bug?
Re: Strange C++ syntax error [message #1797330 is a reply to message #1797199] Tue, 30 October 2018 03:45 Go to previous message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
You should post the minimum code which has the problem.
The problem is unduplicable as given even if we try.
As it is, we don't know what you've included or how byte or uint16_t have been defined.
If the Indexer is saying they are defined as "unsigned char" and "unsigned short int" then they probably are.

Suggest posting something like
#include "whatever.h"  // show necessary includes
typedef something byte; // or whatever if not included
typedef yadayada uint16_t;

void send( byte value );
uint16_t get16();
enum Type : byte {
        GetHeight 
};

void func () {
   send(GetHeight);
   get16();
}


If the Indexer is happy with that then try adding more until you get the problem.

[Updated on: Tue, 30 October 2018 03:57]

Report message to a moderator

Previous Topic:how to write data into a Excel file in C++
Next Topic:Executable dll dependancy on other PC
Goto Forum:
  


Current Time: Thu Apr 25 11:23:39 GMT 2024

Powered by FUDForum. Page generated in 0.03239 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top