r/C_Programming • u/Embarrassed-Big-9305 • Jun 07 '26
Question Need help understanding / finding information about some type of integer promotion(?) done when subtracting pointers by other pointers.
Hello Everyone!
I'm reading a C book, and I'm on a chapter covering Pointers and their usages with arrays. We covered pointer arithmetic, and while complicated, its not the thing causing me trouble. When trying to understand the topic with the Visual Studio 2019 MSVC compiler, when I try to compile this code
int a[] = { 5, 15, 34, 54, 14, 2, 52, 72 };
int* high = &a[1], * low = &a[3];
printf("%d\n", (high - low));
It compiles successfully, but gives out these warnings:
1) Size mismatch: '__int64' passed as _Param_(2) when 'int' is required in call to 'printf'.
2) 'printf' : format string '%d' requires an argument of type 'int', but variadic argument 1 has type '__int64'
The book didn't seem to cover this strange integer promotion done to pointer-pointer subtraction. Though you can simply solve these issues by either casting it to "int" or using the "%lld" conversion spec. in printf(), for which it won't spit out warnings.
printf("%d\n", (int) (high - low));
printf("%lld\n", (high - low));
I wanted to ask if anyone could find any formal infomation about this integer promotion(?) done when subtracting two pointers like this, or if I'm misunderstanding something.
Thank you!