Skip to content

Can size_t be 64 bits? #34

Closed
Closed
@dimitri-xyz

Description

@dimitri-xyz

I believe this will fail if size_t is 64 bits or more and the value is requested is also more than 2^32.

size_t get_power_of_two(size_t n)
{
n--;
n |= n >> 1;
n |= n >> 2;
n |= n >> 4;
n |= n >> 8;
n |= n >> 16;
n++;
return n;
}

Adding a similar right shift of 32 bits would solve the problem for situations when size_t has 64 bits.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions