Python is just as good as C++ for real apps
Grant Edwards
grante at visi.com
Sat Jan 26 10:32:12 EST 2002
In article <a2tugq$a2a$0 at 216.39.172.122>, Bengt Richter wrote:
>>int *p,i; // both i and *p are ints
>>
>>i = 7; // i has the value 7;
>>*p = 7; // *p has the value 7;
> Oops, you're thinking Pythonic binding? You are actually using
> an uninitialized pointer and storing an int value of 7 wherever it points.
> You might get a GPF and not get to the rest ;-)
I know -- I left out a few details. :) I should have added a [...]
>>(*p) + 1; // expression with value 8;
>
>>i + 1; // expression with value 8;
>>
>>// You have to add parens, but (*p) seems to act like an int in that
>>// expression also.
> You don't have to add parens unless you are using ++ or -- and want the
> latter to apply to the pointer's target rather than the pointer itself,
You're right. I was thinking of ++.
>>That both i and (*p) are ints.
>
> And so is *p without parens.
I added the parens so it would be true in all syntactic
contexts (e.g. ++ and --).
> But: "int *p;" declares a pointer to an int value, and
> reserves space for a pointer. It doesn't declare an integer
> slot to point at. You have to make sure to initialize the
> pointer so it points to a valid integer value (which needs its
> own declaration)
Or you can allocate memory using malloc, calloc, etc. I was
skipping over that part since it had nothing to do with my
point.
> I'll spare you C++ references in the above examples ;-)
Thamks!
--
Grant Edwards grante Yow! Yow! STYROFOAM...
at
visi.com
More information about the Python-list
mailing list