Skip to content

doc contradicts itself about the result of SDL_MostSignificantBitIndex32(0) #15247

@sleeptightAnsiC

Description

@sleeptightAnsiC

The current doc page about SDL_MostSignificantBitIndex32 is like so:

/**
* Get the index of the most significant (set) bit in a 32-bit number.
*
* Result is undefined when called with 0. This operation can also be stated
* as "count leading zeroes" and "log base 2".
*
* Note that this is a forced-inline function in a header, and not a public
* API function available in the SDL library (which is to say, the code is
* embedded in the calling program and the linker and dynamic loader will not
* be able to find this function inside SDL itself).
*
* \param x the 32-bit value to examine.
* \returns the index of the most significant bit, or -1 if the value is 0.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*/
SDL_FORCE_INLINE int SDL_MostSignificantBitIndex32(Uint32 x)
{

in one place it says:

Result is undefined when called with 0

but in another:

returns [...] -1 if the value is 0.

so those notes are contradictory to one another. I quickly looked into all pp branches and each one seems to be handling this case with return -1, so the claim about it causing UB looks like some leftover (?)

Mind clarifying this one?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions