Re: Pointer Declaration/Array definition
Jens.Toerring_at_physik.fu-berlin.de
Date: 08/22/04
- Next message: nobull_at_mail.com: "Re: [OT] Perl to C Converter?"
- Previous message: Richard Pennington: "Re: Double pointer and 2D array"
- In reply to: ur8x_at_ur8x.com: "Re: Pointer Declaration/Array definition"
- Next in thread: ur8x_at_ur8x.com: "Re: Pointer Declaration/Array definition"
- Reply: ur8x_at_ur8x.com: "Re: Pointer Declaration/Array definition"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 22 Aug 2004 16:41:34 GMT
ur8x@ur8x.com wrote:
> Jens.Toerring@physik.fu-berlin.de wrote:
Please be so kind not to top-post.
> Ok, here is what I want to know: What exactly happens when
> p[i] is called, as far accessing and dereferncing that makes
> the code wrong (yes, I know it should not work, I just want
> to know why).
In the process of compiling and linking the symbol 'p' will
get replaced by a certain memory address. The code in file2
knows that at this address there's a string, e.g. "ABCDEFG".
But the code in file1 assumes that at that address a pointer
to char is stored. Since you have "ABCDEFG" at that address
the code in file1 will interpret this value stored there as
an address like 0x61626364' (assuming you have 4 byte char
wide addresses on a big-endian machine and ASCII charset, so
0x61 == 'A' etc.). But that's of course no address but just
the bit pattern of the start of the string. If you then use
'p[i]' it tries to dereference that address (0x61626364 + i),
an address to which you proably have no access to and thus
you get a segmentation fault.
Regards, Jens
-- \ Jens Thoms Toerring ___ Jens.Toerring@physik.fu-berlin.de \__________________________ http://www.toerring.de
- Next message: nobull_at_mail.com: "Re: [OT] Perl to C Converter?"
- Previous message: Richard Pennington: "Re: Double pointer and 2D array"
- In reply to: ur8x_at_ur8x.com: "Re: Pointer Declaration/Array definition"
- Next in thread: ur8x_at_ur8x.com: "Re: Pointer Declaration/Array definition"
- Reply: ur8x_at_ur8x.com: "Re: Pointer Declaration/Array definition"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|