EVerest / cbexigen

cbExiGen - The V2GTP EXI codec generator for cbV2G
Apache License 2.0
32 stars 18 forks source link

Why C and not C++ ? #77

Closed andreichalapco closed 7 months ago

andreichalapco commented 7 months ago

Describe the problem

It occured to me when looking at the generated code:

void init_iso2_ServiceDetailReqType(struct iso2_ServiceDetailReqType* ServiceDetailReqType) {
    (void) ServiceDetailReqType; // this does nothing, no variable is initialized -> probably just for compiler warning
}

or

void init_iso2_MessageHeaderType(struct iso2_MessageHeaderType* MessageHeaderType) {
    MessageHeaderType->Notification_isUsed = 0u; // default initialization
    MessageHeaderType->Signature_isUsed = 0u;
}

that we basically could do this a lot better in c++ with objects ... the syntax would be also a lot cleaner. For which reason was a c implementation used? maybe I don't see the advantages

Describe your solution

No response

Additional context

No response

barsnick commented 7 months ago

For which reason was a c implementation used?

To be compatible with embedded systems which are constrained in the use of C++. C is the common denominator. (The original authors actually had the code integrated into such a product, so this is not a hypothetical scenario.)

Please feel free to modify and create a PR, best as an additional path / separate templates to be chosen by config, to optionally create proper C++ code. This would be very welcomed, especially for integration into the EVerest modules.

Unfortunately, the low- and mid-level layers of the code generator are not properly separated. Nevertheless, creating C++ code should be possible without too many modifications. (Very little stuff is C-specific.)

The same for other languages. Rust support would certainly also be welcome.

andreichalapco commented 7 months ago

Thx for the guidelines and explanation!