S
SM Ryan
# Why does C use zero-based indexing?
#
# Many people find zero-based indexing difficult and non-intuitive. Why
# doesn't C start indices from 1 instead? This would be much easier for
# people.
#include <stdio.h>
#define array(lwb,upb,Element,name) \
Element name##_ARRAY[(upb)-(lwb)+1], \
*name = name##_ARRAY-(lwb)
int main(int N,char **P) {
array(1,5,int,twice); int i;
for (i=1; i<=5; i++) twice = 2*i;
for (i=1; i<=5; i++) printf("i=%d twice=%d\n",i,twice);
return 0;
}
#
# Many people find zero-based indexing difficult and non-intuitive. Why
# doesn't C start indices from 1 instead? This would be much easier for
# people.
#include <stdio.h>
#define array(lwb,upb,Element,name) \
Element name##_ARRAY[(upb)-(lwb)+1], \
*name = name##_ARRAY-(lwb)
int main(int N,char **P) {
array(1,5,int,twice); int i;
for (i=1; i<=5; i++) twice = 2*i;
for (i=1; i<=5; i++) printf("i=%d twice=%d\n",i,twice);
return 0;
}