Re: objc_method_list structure?
Re: objc_method_list structure?
- Subject: Re: objc_method_list structure?
- From: Tim Conkling <email@hidden>
- Date: Thu, 11 Nov 2004 22:51:32 -0500
On Nov 11, 2004, at 10:23 PM, Dustin Voss wrote:
On 11 Nov, 2004, at 6:02 PM, Tim Conkling wrote:
struct objc_method_list
{
struct objc_method_list *obsolete;
int method_count;
struct objc_method method_list[1];
};
According to the documentation, the method_list field in the above
structure is supposed to be "An array of objc_method data
structures." I'm not sure what should go in the [0] index and what
should go in the [1] index in order to make this array...
This is a common C technique. How it works is, the array is not
actually 1 element long. It is however long method_count says.
method_list is actually a pointer to a block of contiguous memory that
is treated as an array. The memory block is (method_count *
sizeof(objc_method)) bytes long. You can address the elements like
method_list[0], etc., all the way up to, but not including,
method_count, just like any array.
To create this, make an appropriately-sized memory block, fill it as
if it were an array, and set method_count to the number of elements
and method_list to the address of the block.
Ok... I feel silly. I thought I knew a lot about C :)
I'm confused about why it isn't done like this, however:
struct objc_method *method_list;
Same effect, right? It's just slightly less convenient if you're
creating the objc_method_list structure yourself and you only have one
method to stick in the list.
Tim
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden