Python is just as good as C++ for real apps
Grant Edwards
grante at visi.com
Fri Jan 25 21:46:27 EST 2002
In article <d1645ug80n2mvcvtdkctujkruepotv5p08 at 4ax.com>, Courageous wrote:
>>IOW, *p behaves like any other int.
>
> NO. It doesn't. For one thing, adding one to it actually adds
> 4 to it.
(*p) + 1 adds one to it.
> More generally, what happens can be shown by the
> example program below. Pointers are _different_.
I know pointers are different. I never said they weren't.
I'm saying that when you declare
int *p;
*p is an int.
p is a pointer to an int.
I never propsed that you think of p as an int. I said you
should think of *p as an int.
> 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));
What I'm talking about is that *cp is a char. sizeof *cp is 1;
> 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)
>
> --------------
It appears we're talking past each other.
--
Grant Edwards grante Yow! It's OKAY --- I'm an
at INTELLECTUAL, too.
visi.com
More information about the Python-list
mailing list