Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Obsolete struct initialization syntax #13

Open
kapec94 opened this issue Dec 19, 2019 · 2 comments
Open

Obsolete struct initialization syntax #13

kapec94 opened this issue Dec 19, 2019 · 2 comments

Comments

@kapec94
Copy link

kapec94 commented Dec 19, 2019

The code uses an obsolete GCC extension syntax for struct initialization.

Example:

IsoTpReceiveHandle handle = {
    success: false,
    completed: false,
    arbitration_id: arbitration_id,
    message_received_callback: callback
};

This syntax is obsolete since GCC 2.5 (released in 1993!) (source: Designated Inits, source: GCC releases)

There are a few alternatives to this. One of which is a standarized version of field initialization introduced in C99:

IsoTpReceiveHandle handle = {
    .success = false,
    .completed = false,
    .arbitration_id = arbitration_id,
    .message_received_callback = callback
};

C99 support is quite widespread (source) and even if declared "partial", designated initializers should be available on any major, modern compiler (however, this cross-compiler support doesn't matter, since the code relies on an ancient GCC extension anyway). And to ensure that on GCC it still works as before, a simple preprocessor macro might be prepared to choose between two syntaxes.

There are also other standard options of struct initialization, like using a factory function or setting fields manually. I believe that this would not introduce any performance hit (if that worried you), since there are very few places that use that syntax and in most of them we return the initialized struct immediately.

I might prepare a pull request for that change.

@wuyingsheng
Copy link

hello:I have 2 question:

  1. get_nibble 、set_nibble 、get_byte where they defined?
    2.what is bitfield.h and bitfield.c ? where they defined?

thanks!!
Error: L6218E: Undefined symbol get_byte (referred from receive.o).
Error: L6218E: Undefined symbol get_nibble (referred from receive.o).
Error: L6218E: Undefined symbol set_nibble (referred from receive.o).

@emarsman
Copy link
Member

hello:I have 2 question:

  1. get_nibble 、set_nibble 、get_byte where they defined?
    2.what is bitfield.h and bitfield.c ? where they defined?

thanks!!
Error: L6218E: Undefined symbol get_byte (referred from receive.o).
Error: L6218E: Undefined symbol get_nibble (referred from receive.o).
Error: L6218E: Undefined symbol set_nibble (referred from receive.o).

These are all defined in bitfield-c: https://github.com/openxc/bitfield-c. This is a dependency in the deps/ folder for isotp-c. Try a git submodule update --init

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants