godotengine / godotengine/godot

Should bitfields types be unsigned integers instead of signed integers?

Open
#88,962 8 comments 0 reactions 0 assignees View on GitHub
breaks compat discussion topic:gdextension
Dominant language
C++
Stars
117k
Forks
26.8k
PR merge metrics
PR metrics pending

Description

### Tested versions

Pop OS 22.04: Godot Engine v4.3.dev.mono.custom_build.bbb3531fa
Windows 10: Godot Engine v4.3.dev.mono.custom_build.bbb3531fa

### System information

Pop OS 22.04, Windows 10

### Issue description

We found that Windows was actually treating 0xffffffff bitflags as a signed integer with a value of -1 when compared to Linux where it was treated as unsigned and assigned a value of 4294967295.

This resulted in Gdext panicing when generating Godot bindings as seen in this PR for the fix over here: https://github.com/godot-rust/gdext/pull/627

Godot currently uses signed integers when binding all of its constants including bitflags: https://github.com/godotengine/godot/blob/81f3d43cc1ba01136795fb2059bbaa55bc514a16/core/object/class_db.cpp#L949

So we are seeking further information and discussion around the data type that Godot should enforce for bitflags. Should it stay with the currently signed value? Are there instances where negative values make sense for bitflags? Is there a reason Steam's sdk evaluates to this negative value on Windows and is this expected behavior? If Godot changed to unsigned, would it still be compatible with Steam?

I don't expect all of these questions to necessarily be answered by the Godot team, but I wanted to get the discussion started while we also change the datatype on the gdext side to match Godot's datatype.

Here are the current issues / prs for reference:

godotsteam: https://github.com/CoaguCo-Industries/GodotSteam/issues/424
gdext: https://github.com/godot-rust/gdext/pull/627

### Steps to reproduce

Build godotsteam from here: https://github.com/CoaguCo-Industries/GodotSteam/tree/godot4.

Evaluate the bitflags as describe here: https://github.com/CoaguCo-Industries/GodotSteam/issues/424

See that the constant on Linux is 4294967295

![image](https://github.com/godotengine/godot/assets/24307049/969afe3a-743c-4c14-a7e7-b5c64010f074)

And the constant on Windows is -1

![image](https://github.com/godotengine/godot/assets/24307049/70f86d84-c02f-4499-8c8e-9a4182f43725)

### Minimal reproduction project (MRP)

https://github.com/CoaguCo-Industries/GodotSteam/tree/godot4

Contributor guide

Open the contributing guide

Research direction

Start with core/object/class_db.cpp around line 949, then reproduce the platform difference using the GodotSteam godot4 project and the linked reproduction steps. Review the referenced GodotSteam issue and gdext pull request; done means reaching a project decision on signed versus unsigned bitflag constants and their cross-platform compatibility.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
api, game-dev
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.