Re: pointers as parameters
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Fri, 30 Nov 2007 12:56:50 -0800
CBFalconer <cbfalconer@xxxxxxxxx> writes:
Mark McIntyre wrote:
mdh wrote:
Ok...will let me then ask this. If there is no difference in the
"actual" pointers of different types that are passed to the
function,
Note that there _may_ in fact be a difference. Pointer
representations need not all be indistinguishable.
then is is correct to say that the reason one declares the
pointer's type as, a "pointer to char" or "pointer to pointer
to char" or "ptr to void" etc, is that during the compilation
of the program, the compiler is able to check the code and
prevent errors at run time?
Yes.
In addition, since the compiler knows the type, it can correctly
interpret such values as "sizeof *ptr" and also detect type
conflicts in such things as "*ptr1 = *ptr2".
And there's nothing special about pointer types in this regard; the
same thing happens with other types as well. For example, suppose int
and float are both 32 bits. There's no real distinction on the
machine level between an int object and a float object; they might
both be stored in exactly the same way. But the compiler knows the
type of each object, so that when you write "x + y" in your program,
it generates an add-integer or an add-float instruction as
appropriate. If you're writing in assembly language, you can just as
easily apply integer or floating-point operations to any chunk of
memory of the right size; in the machine code generated by a compiler,
you won't see floating-point operations on integer objects unless you
do some really ugly pointer-casting.
--
Keith Thompson (The_Other_Keith) <kst-u@xxxxxxx>
Looking for software development work in the San Diego area.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.
- References:
- pointers as parameters
- From: mdh
- Re: pointers as parameters
- From: user923005
- Re: pointers as parameters
- From: mdh
- Re: pointers as parameters
- From: Mark McIntyre
- Re: pointers as parameters
- From: CBFalconer
- pointers as parameters
- Prev by Date: printf vs scanf
- Next by Date: There is really important wrong, but I couldnt find
- Previous by thread: Re: pointers as parameters
- Next by thread: Look Is On For Pattern Designing Software
- Index(es):
Relevant Pages
|