I know that subtracting pointers of a specific data type should return the number of items (with this specific data type), which would accommodate as whole within the memory between pointers.
I noticed that if the size of the structure is not the power of 2, the results of subtracting pointers are not what I expected. Could anyone explain to me why?
Sample code:
#include <stdio.h>
typedef struct st {
int i;
char c[7];
}v;
void main() {
v *p1 = (v*) 1000;
v *p2 = (v*) 1359;
printf("%ld\n", p2-p1);
}
Output:
6148914691236517235