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

Structure s_color4 members alignment problem #26

Open
vinz6751 opened this issue Dec 8, 2021 · 2 comments
Open

Structure s_color4 members alignment problem #26

vinz6751 opened this issue Dec 8, 2021 · 2 comments

Comments

@vinz6751
Copy link
Contributor

vinz6751 commented Dec 8, 2021

"types.h" defines the following structure to represent a 32 bit color:

typedef struct s_color4 {
    uint8_t blue;
    uint8_t green;
    uint8_t red;
    uint8_t alpha;
} t_color4;

I suspect that VBCC will align structure members on word or long word boundaries. So if you want to align the members on bytes instead (so the whole structure is 4 bytes), you should wrap the declaration with:

#pragma pack(1)
typedef struct s_color4 {
...
} t_color4;
#pragma pack()

as indicated on page 46 of the VBCC manual.
I haven't tested it though

It struck me because for the EmuTOS port I had the problem and had to use the packed attribute to indicate what I wanted to GCC.

@pweingar
Copy link
Owner

pweingar commented Dec 8, 2021

Thanks. I don't think this record ended up being used... it might be a hold over from when I started working on the code on my C256. It should probably be removed.

@vinz6751
Copy link
Contributor Author

vinz6751 commented Dec 8, 2021

I saw it was not used, but I thought it was because it was not working :D
Sometimes it's just easier to use a unsigned long.
So a colour could really be defined as a union, e.g:

union color {
  unsigned long l; // Requires the user to know the order of components but makes for easier conversion long <-> union
  t_color4 argb;
}

Anyway, as you way it can probably be deleted until we need it.

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

2 participants