Re: Any clues to this!

Thomas Pornin (bip@orion.ens.fr)
Sat, 7 Feb 1998 01:50:22 +0100


In article <Pine.HPP.3.95.980206142701.23693A-100000@payal.hss.hns.com> you write:
>[suman@linux]Fri Feb 6 14:20:47 [~]:~$cat cd.c
>main()
>{
>int *p=0x123454;
>printf("%d",*p);
>}

This cannot work. The "int *p=0x123454" stores 0x123454 not in the int
value pointed by p, but in p (the pointer) itself. So accessing *p is
reading the int stored at address 0x123454, which is unlikely to be
mapped at all; hence the seg fault.

>[suman@linux]Fri Feb 6 14:21:33 [~]:~$gcc -o cd cd.c
>[suman@linux]Fri Feb 6 14:21:39 [~]:~$cd

I guess that when you type "cd", it does not execute the program named
"cd" in your directory, but the builtin command "cd" of your shell
(also known as "change directory"). Try "./cd" to get your (deserved)
segmentation valuation.

--Thomas Pornin
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu