This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
C - Pass by reference to pointers
- From: Anitha Boyapati <anithab at sankhya dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Fri, 24 Aug 2007 12:59:45 +0530 (IST)
- Subject: C - Pass by reference to pointers
Hi,
The following C code snippet uses some sort of reference type
that I am unaware of.I recently came across this during multithreaded
programming.
void f(int *t) {
printf("%u\n", t);
}
void main() {
int i=2;
printf("%u\n", &i);
f((int*)i); ---- > case 1 : gives output 2
f(&i); ---- > case 2 : normal
}
Usually, (well I thought so) the argument expected in f() is a pointer
variable. The above gives the result as 2 for the first call to f()!
Why is t giving out 2 without being dereferenced in case 1 ?
How come case 1 and case 2 are both accepted for a calling same
function ? I mean same prototype appears to have different meaning
based on the callee. Any advice ?
-----------------------------------------------------------------
gcc pointer_ref.c -o pointer_ref
./pointer_ref
3221202660
2
3221202660
As usual my gcc version is 3.2.3.
--
Regards,
Anitha B
@S A N K H Y A