Next: Method Type Descriptor, Previous: Class Instance, Up: Cplusplus [Contents][Index]

### 8.6 Method Definition

The class definition shown above declares Ameth. The C`++` source below defines Ameth:

    int
    baseA::Ameth(int in, char other)
    {
            return in;
    };

This method definition yields three stabs following the code of the method. One stab describes the method itself and following two describe its parameters. Although there is only one formal argument all methods have an implicit argument which is the `this` pointer. The `this` pointer is a pointer to the object on which the method was called. Note that the method name is mangled to encode the class name and argument types. Name mangling is described in the ARM (The Annotated C++ Reference Manual, by Ellis and Stroustrup, ISBN 0-201-51459-1); `gpcompare.texi` in Cygnus GCC distributions describes the differences between GNU mangling and ARM mangling.

    .stabs "name:symbol_descriptor(global function)return_type(int)",
            N_FUN, NIL, NIL, code_addr_of_method_start

    .stabs "Ameth__5baseAic:F1",36,0,0,_Ameth__5baseAic

Here is the stab for the `this` pointer implicit argument. The name of the `this` pointer is always `this`. Type 19, the `this` pointer is defined as a pointer to type 20, `baseA`, but a stab defining `baseA` has not yet been emitted. Since the compiler knows it will be emitted shortly, here it just outputs a cross reference to the undefined symbol, by prefixing the symbol name with ‘`xs`’.

    .stabs "name:sym_desc(register param)type_def(19)=
            type_desc(ptr to)type_ref(baseA)=
            type_desc(cross-reference to)baseA:",N_RSYM,NIL,NIL,register_number

    .stabs "this:P19=*20=xsbaseA:",64,0,0,8

The stab for the explicit integer argument looks just like a parameter to a C function. The last field of the stab is the offset from the argument pointer, which in most systems is the same as the frame pointer.

    .stabs "name:sym_desc(value parameter)type_ref(int)",
            N_PSYM,NIL,NIL,offset_from_arg_ptr

    .stabs "in:p1",160,0,0,72

<< The examples that follow are based on A1.C >>

Next: Method Type Descriptor, Previous: Class Instance, Up: Cplusplus [Contents][Index]