Skip to content

Conversation

@linuxianer99
Copy link
Member

@linuxianer99 linuxianer99 commented Mar 8, 2022

  • Alignment of struct using packed attribute to fix sizeof() return value
  • Exclude checksum itself from checksum calculation

Fixes #45

@linuxianer99 linuxianer99 requested a review from kedder March 8, 2022 07:27
@linuxianer99 linuxianer99 marked this pull request as ready for review March 8, 2022 07:31
24c16.h Outdated
} t_24c16;

typedef struct {
typedef struct __attribute__((packed)){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a good idea. This moves the float field to a misaligned offset, and may crash with SIGBUS on some CPUs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you suggest as alternative ?? Add a stuff variable instead ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to define the float inside the struct as the first item? This will reduce the padding to 1 byte. Then we can add one byte to the serial number to fill that padding byte.

Add padding for struct alignment
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

Successfully merging this pull request may close these issues.

Sensorcal not working

3 participants