• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: objc_method_list structure?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >objc_method_list structure? (From: Tim Conkling <email@hidden>)
 >Re: objc_method_list structure? (From: Dustin Voss <email@hidden>)

  • Prev by Date: Re: objc_method_list structure?
  • Next by Date: Re: My bug or Apple's?
  • Previous by thread: Re: objc_method_list structure?
  • Next by thread: My bug or Apple's?
  • Index(es):
    • Date
    • Thread