Re: gcc oriented questions



In message <997278074 14844 10 camel master>you write:
>Am 08 Aug 2001 15:03:15 +0200 schrieb David Robin:
>> hi,
>> 
>> here are two different questions:
>> - why are callback functions defined as 'static'? Is there an obligation to 
>do so? Does it makes my app faster?
>
>Er, I guess you talking about static class members in C++ ?
>A static class member function behaves like an ordinary C function,
>e.g. it has no implicit "this"-pointer. Since the GTK+ C-API knows
>nothing about C++, you have to declare the callback functions static.

to clarify a little (since when i first started with C++, i found this
very hard to understand): a pointer-to-a-member-function is a
*totally* different kind of entity in a C++ program than a
pointer-to-a-function. you really need to get this firmly established
in your mind and never confuse the two. the things you can do with one
of them cannot be done with the other, and vice versa.

there is a small hint of this in C++'s syntax:

      void (SomeClass::*ptr_to_member)(void) func;
      SomeClass *some_object;

      (some_object->*)(func);

the "->*" operator is unique to C++ and there is no corresponding
equivalent operator in C. 

so, by declaring functions as "static", you convert pointers to them
from ptr-to-member into ptr-to-function. this makes it possible for C
code to call them correctly.

--p




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]