List Object's methods using class_nextMethodList Problem

  • I am having trouble using the suggested technique for accessing a
    class' method list using class_nextMethodList.

    In xCode 2.5, the following code fragment:

    //method enumeration example
    - (CC *)enumMethodList;
    {
    void *iterator = 0;
        struct objc_method_list *mList;
    Class theClass = [self class];
    int k;
    NSString *className = [theClass description];

        mList = class_nextMethodList( theClass, &iterator  );
    while( mList != NULL )
    {

      /*
      for(k=0; k < mList->method_count; k++)
      {
        NSLog(@"%@ implements %s", className, mList->method_list
    [k].method_name);
      }
      */

      mList = class_nextMethodList( theClass, &iterator  );
    }

    }

    runs and shows the method list (mList) in the debugger and its
    contents are accessible there.

    When I remove the comments around the for loop, the compiler
    generates 2 "dereferencing pointer to incomplete type" error
    messages; 1 for the method_count reference and 1 for the method_name
    reference.

    The compiler settings are default except I have "Handle Objective-C
    Exceptions" enabled.
  • On Oct 17, 2007, at 11:19 AM, colela wrote:

    > When I remove the comments around the for loop, the compiler
    > generates 2 "dereferencing pointer to incomplete type" error
    > messages; 1 for the method_count reference and 1 for the
    > method_name reference.

    There are also "assignment makes pointer from integer without a cast"
    warnings which I see when trying to compile your code. These are all
    indicative of the compiler not knowing the method prototypes.

    Adding '#import <objc/objc-runtime.h>' to your implementation file
    should fix it.

    pg
  • On Oct 17, 2007, at 1:19 PM, colela wrote:

    > I am having trouble using the suggested technique for accessing a
    > class' method list using class_nextMethodList.
    >
    > In xCode 2.5, the following code fragment:
    >
    > //method enumeration example
    > - (CC *)enumMethodList;
    > {
    > void *iterator = 0;
    > struct objc_method_list *mList;
    > Class theClass = [self class];
    > int k;
    > NSString *className = [theClass description];
    >
    > mList = class_nextMethodList( theClass, &iterator  );
    > while( mList != NULL )
    > {
    >
    > /*
    > for(k=0; k < mList->method_count; k++)
    > {
    > NSLog(@"%@ implements %s", className, mList->method_list
    > [k].method_name);
    > }
    > */
    >
    > mList = class_nextMethodList( theClass, &iterator  );
    > }
    >
    > }
    >
    >
    > runs and shows the method list (mList) in the debugger and its
    > contents are accessible there.
    >
    > When I remove the comments around the for loop, the compiler
    > generates 2 "dereferencing pointer to incomplete type" error
    > messages; 1 for the method_count reference and 1 for the
    > method_name reference.
    >
    > The compiler settings are default except I have "Handle Objective-C
    > Exceptions" enabled.

    You are, of course, including/importing the header file that defines
    objc_method_list, correct?

    #import <objc/objc-class.h>

    - Mike
previous month october 2007 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today