Skip to content

Cast integer literals to target type

Daniel Bauer requested to merge hyteg/pystencils:bauerd/long-int into backend-rework

I ran into a case where the C++ compiler wants the suffix (or a cast): std::max(0, x) does not compile if x is of 64 bit integer type. On my machine 32 bit is the correct threshold and I think this is fairly standard. However, AFAIK it is technically platform dependent, so should we emit a cast to the target type instead?

Update: According to the standard long long (ll suffix) guarantees at least 64 bit. However, we might run into similar issues with smaller types. So I updated the MR such that integer literals are always cast to the target type. Starting with C99, an integer literal is automatically assigned a 64 bit type, if the number does not fit into 32 bit. This means that we currently do not support integer literals >32 bit prior to C99. A quarter century later, I think this is OK.

Edited by Daniel Bauer

Merge request reports