Re: A question of programming technique in C

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Richard Harter

    Re: A question of programming technique in C

    On Tue, 4 Nov 2008 14:26:39 -0800 (PST), s0suk3@gmail.co m wrote:
    >On Nov 4, 3:24=A0pm, cri@tiac.net (Richard Harter) wrote:
    >Suppose we are writing a program in C and that we have a
    >particular kind of object (in the sense of OO programming) that I
    [snip]
    >The problem is that C pointers are fragile, that they carry no
    >certificate of validity,
    >
    >If you're talking about memory leaks, I seriously believe that taking
    >care to avoid them is better than all the methods you've described
    >below.
    I'm not sure where you got the idea that I was talking about
    memory leaks, but I wasn't.
    >
    >and that they provide unrestricted
    >access to the struct contents.
    >
    [snip]
    >A more robust way would be to maintain an array of bobble_locator
    >>
    >structs inside the package, and store the array index inside the
    >bobble_descrip tor struct. =A0This has two benefits: (a) we can
    >check the validity of the index, and (b) the user code cannot
    >access the bobble directly.
    >
    >The user code can still modify the index :-)
    Indeed, they can, but not in a way that creates a valid
    descriptor.

    Thank you for your comments.


    Richard Harter, cri@tiac.net
    http://home.tiac.net/~cri, http://www.varinoma.com
    Save the Earth now!!
    It's the only planet with chocolate.
Working...