spin2cpp icon indicating copy to clipboard operation
spin2cpp copied to clipboard

C++: struct/class should be implicitly typedef'd

Open Wuerfel21 opened this issue 4 years ago • 3 comments

Should work, but doesn't:

struct SomeClass {
    int var;
};

int main() {
    SomeClass c = {123};
    _OUTA = c.var;
}

Wuerfel21 avatar Jun 20 '21 13:06 Wuerfel21

I think this should be fixed now, thanks for bringing it up.

totalspectrum avatar Jun 24 '21 20:06 totalspectrum

Aargh, it's not as simple as just typedef'ing the names, because this can lead to conflicts with other names :(. Re-opening for now, but I suspect this will become a "will not fix" (we don't claim full C++ compliance for flexcc anyway).

totalspectrum avatar Jun 28 '21 14:06 totalspectrum

It is as simple as that, FlexC just doesn't handle type names conflicting with identifiers.

typedef int mytype;

int test(mytype mytype) {
    return (int) mytype;
}

Then again, using the same name for type and identifier is like, terrible programming practice and I have no idea why C allows this.

Wuerfel21 avatar Jun 28 '21 15:06 Wuerfel21