Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 24c16.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ typedef struct {
unsigned char address;
} t_24c16;

typedef struct {
typedef struct __attribute__((packed)){
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

char header[3];
char data_version;
char serial[6];
Expand Down