Python is just as good as C++ for real apps
Courageous
jkraska at san.rr.com
Fri Jan 25 21:36:29 EST 2002
>same as sizeof (int) -- which is 4 on all of my boxes.
Mea culpa. I occasionally convert ints to shorts in my head.
Don't ask me how that happens. Not sure, but I think an old
compiler of mine many moons ago defaulted all ints to 16 bits.
If I could only burn that out of my brain, I'd avoid little
mistakes like that. :)
Anyway, short and short* are different, as are many other
value/pointer types.
>IOW, *p behaves like any other int.
NO. It doesn't. For one thing, adding one to it actually adds
4 to it. More generally, what happens can be shown by the
example program below. Pointers are _different_. They should
be cognited as their own complete type. They even effectively
have operator overload. To wit:
#include <stdio.h>
void main()
{
char c=0, *cp=0;
short s=0, *sp=0;
int i=0, *ip=0;
long l=0, *lp=0;
float f=0.0, *fp=0;
fprintf(stderr, "c = %d (size %d), cp =%d (size %d)\n",
(int)c+1, sizeof(c), (int)(cp+=1), sizeof(cp));
fprintf(stderr, "s = %d (size %d), sp =%d (size %d)\n",
(int)s+1, sizeof(s), (int)(sp+=1), sizeof(sp));
fprintf(stderr, "i = %d (size %d), ip =%d (size %d)\n",
(int)i+1, sizeof(i), (int)(ip+=1), sizeof(ip));
fprintf(stderr, "l = %d (size %d), lp =%d (size %d)\n",
(int)l+1, sizeof(l), (int)(lp+=1), sizeof(lp));
fprintf(stderr, "f = %d (size %d), fp =%d (size %d)\n",
(int)f+1, sizeof(f), (int)(fp+=1), sizeof(fp));
}
% gcc test.C
% a.exe
c = 1 (size 1), cp =1 (size 4)
s = 1 (size 2), sp =2 (size 4)
i = 1 (size 4), ip =4 (size 4)
l = 1 (size 4), lp =4 (size 4)
f = 1 (size 4), fp =4 (size 4)
--------------
C//
More information about the Python-list
mailing list