|
Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com |
From: Jedi/Sector One (j
pureftpd.org)Date: Wed Feb 06 2002 - 01:10:03 CST
On Wed, Feb 06, 2002 at 12:48:06AM +0000, Marc Xander Makkes wrote:
> struct point *p;
> p->y = 13;
p->y = 13 is a synonym for (*p).y = 13 and means "take the value of p.
It's an address. Look at what's stored in that address. You get a 'struct
point' object. Modify the 'y' field of that structure".
The problem is that you didn't assign any address to 'p'. 'p' can have any
value according to the junk on the stack and in registers when the function
is called. So your program takes a random address and uses it to modify
another random address. It explains the segmentation fault (and
*fortunately* is segfaults, or your system would get really instable if it
hadn't any sort of memory page protection) .
Don't use pointers when you don't need to :
struct point p;
p.y = 13;
That one works. Because the first line says "allocate a new 'struct point'
object on the stack called 'p'" .
Best regards,
-Frank.
-- __ /*- Frank DENIS (Jedi/Sector One) <j42-Networks.Com> -*\ __ \ '/ <a href="http://www.PureFTPd.Org/"> Secure FTP Server </a> \' / \/ <a href="http://www.Jedi.Claranet.Fr/"> Misc. free software </a> \/
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]