I was wondering how you could printf _ExtInts in clang without using casts. Something like this:
#include <stdio.h>
int main() {
_ExtInt(13) foo = 100;
printf("%???", foo);
}
With casts, it would look like this (this is not what I want):
#include <stdio.h>
int main() {
_ExtInt(32) foo = 100;
printf("%d", (int) foo);
}
The
_ExtInttypes are a new feature in Clang (LLVM) as described at The New Clang_ExtIntFeature Provides Exact Bitwidth Integer Types, published 2020-04-21 (3 days ago as I type).If
_ExtInt(32)is a 32-bit signed integer type andintis a 32-bit signed integer type, then you can use%dand no cast in both calls toprintf(). The arguments after the format are subject to the integer promotion rules, so I expect that both_ExtInt(13)and_ExtInt(32)would be converted tointas they are passed toprintf(), so the correct conversion specifier is%d.If you use bigger types, up to
_ExtInt(64), you can probably use%lldon any machine (or%ldon a 64-bit machine). If you go bigger than that, you are on your own; you need an implementation ofprintf()that knows how to handle_ExtInttypes, and that will probably have notations in the format that allow for the length to be specified. For example, hypothesizing wildly, it might support%<700>dfor a signed_ExtInt(700).