> Ok, I was trying to show the point not sintaxis.
If you're trying to make a point about a programming language issue in which syntax is the central issue, I don't see the sense in a statement like that.
>int my_fync(int *piA)
>{
>printf("Arg: %u\n",piA);
%u? don't you mean:
printf("Arg: %d\n",*piA);
Above you were trying to print the pointer, not what it points to.
If you /were/ printing the pointer:
printf("Arg: %p\n",piA);
>return 0;
>}
>main ()
>{
>int a[10];
>
>my_func((int*)c);
>my_func((int*)&c);
What are these casts for?
>
>return 0;
>}
Yes, despite the warning about incompatible types they do seem to produce the same values in the function argument. Not being an expert on the C standard, I'd be interested to know if this is really legal or if it just /happens/ to work. In other words, just because it compiles and produces the expected result on a compiler doesn't mean it's correct. When you get warnings such as you get when you try to do my_func(&a) (passing arg 1 of 'myfunc' from incompatible pointer type), it's nearly always best to listen and get rid of that warning (and /not/ with a cast). At any rate, you can have that one
On, the function/pointer/address issue:
>int my_fync(int **piA)
>{
>printf("Arg: %u\n",*piA); /* print "Arg: 1" */
No, you print the pointer (if you pass it the correct type)
>printf("Arg: %u\n",(*piA)[0]); /* crush */
Yes, of course, /if/ you pass it an incorrect type. No problem though if you pass it the type it's asking for.
>return 0;
>}
>main ()
>{
>int a[2] = {1,2};
>
>my_func((int**)&c);
>
>return 0;
>}
This causes all kinds of problems because you're passing an incompatible pointer type to my_func(). That cast just silences the compiler as you are in effect telling it, "Yes, I know that I'm not passing a pointer to a pointer to int to my_func(), but I know what I'm doing." Very rarely are casts justified and usually result in a covered up bug.
At any rate, how does this address the question I asked you in regard to the function knowing or caring about how the caller passes it arguments? As far as the function is concerned, it has a pointer to a pointer to int, it's implementation isn't affected whatsoever by how a caller passes arguments to it.
Below is an example using myfunc() with a pointer to pointer int and using the & operator in the caller. Note that you need to use the & operator to pass the function the correct type as it needs a deep copy of the pointer to affect the caller's copy:
#include <stdio.h>
#include <stdlib.h>
int my_func(int **piA,int count)
{
int i;
*piA=malloc(count);
if (NULL!=piA) {
for (i=0;i<count;++i) {
/* No crush here!

*/
(*piA)
=i+1;
}
return 0;
} else {
return 1;
}
}
int main (void)
{
int *a;
int i;
int count=10;
if (0==my_func(&a,count)) {
for (i=0;i<count;++i) {
printf("%d\n",a);
}
free(a);
}
return 0;
}
The whole point of your post was to discourage people from using the address operator in situations where using the variable by itself and the variable prefixed with the address operator are equivalent -- you still haven't (IMO) made a convincing argument for this whatsoever.
Russ
bobbitts@hotmail.com