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

Make enumeration counts constant expressions #366

Merged
merged 1 commit into from
Oct 4, 2024

Conversation

ZXShady
Copy link
Contributor

@ZXShady ZXShady commented Oct 2, 2024

This change allows now having these variables as array sizes that are not Variable Length Arrays like in structs for example.

struct {
   sfKeycode keys[sfKeyCount]; // didn't compile since it was not constant expression
} global_table;

int main(void) {
   return 0;
}

To note however that this changes the type from unsigned int to an implementation defined type which usually int which is signed and not unsigned. and also disallows taking the address of the constant since it is mo longer a variable.

the other is using a macro which I don't like, but it can allow us to change the type to an unsigned type if we really wanted

#define sfKeyCount ((unsigned int)sfKeyPause + 1)

but I prefer CSFML to be macro free if possible so I choose the enum approach.

@eXpl0it3r
Copy link
Member

Doesn't that still need to be exported?

@ZXShady
Copy link
Contributor Author

ZXShady commented Oct 2, 2024

enums do not provide functionality I don't think they need to be exported and as I see no enums in CSFML are exported

@eXpl0it3r eXpl0it3r added this to the 3.0 milestone Oct 3, 2024
@ChrisThrasher
Copy link
Member

For the sake of consistency could you make this change to all similar constants? I think it's just sfMouseButtonCount and sfSensorCount that need this treatment.

This change allows now having these variables as array sizes that
are not Variable Length Arrays like in structs for example.

To note however that this changes the type from unsigned int to an
implementation defined type which usually `int` which is signed and
not unsigned.
@ChrisThrasher ChrisThrasher changed the title Make sfKeyCount and sfScancodeCount constant expressions Make enumeration counts constant expressions Oct 3, 2024
@ChrisThrasher ChrisThrasher merged commit 884dcde into SFML:master Oct 4, 2024
39 checks passed
@ZXShady ZXShady deleted the real_constants branch October 4, 2024 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants