3 ms·
I agree. And I find it interesting that everyone seems to think the alternative is having a handful of hard coded sizes (8, 16, 32, 64). I don't think that's th
by IAmLiterallyAB 3y ago
I agree. And I find it interesting that everyone seems to think the alternative is having a handful of hard coded sizes (8, 16, 32, 64). I don't think that's the answer either.
I imagine a language without any concrete integer type, instead you have to parameterize.
For example int<32> for a 32 bit integer. Syntax is debatable but that's the idea.
It's great cuz it can work on even weird hardware, I can make an int<13> for 13 bit machines.
And you can make typedefs for common stuff. Like a size_t mapping to int<32> or a word_t mapping to int<16>. Whatever you need.
I've been meaning to make a compiler to test the idea out. Someday maybe
- jcranmer 3y agoC23 has _BitInt(N) that works exactly like I think you'd want it to work.
- IAmLiterallyAB 3y agoYes, and I'm excited about that! Though I do wish the syntax sucked less. Also would be interesting to see it be the primary integer type of the language. I'm also interested in a more advanced version for setting arbitrary bounds. E.g. an integer that goes from 1-10. Adding two of those would be an integer from 2-20. The goal being that the compiler could help enforce that you don't pass a value that is OOB. Might make more sense for that to be a library. Perhaps some C++ template magic. But I digress