Re: a simple question.



On Thu, Oct 26, 2000 at 12:52:50AM -0700, learfox furry ao net wrote:
Hi,all:
  I have a simple question.I would like to know why all callback
function are static? Are there anybody know answer?

I don't think functions for GTK+ signal callbacks need to be
declared static.

I think in the tutorial or whereever you saw them given per
example is that they have ambiguous names such as
static void handle_key()

Which may conflict with other function names, from what I recall, C
declares a local function static to indicate it is to be used in this .c
file only and not allow external calls to link to it (corrections?).

yes -- declaring a function (or global variable) as static means that it
does not get an entry in the symbol table for the corresponding .o
file, so other files linking to it (eg. other files in the application)
cannot see that symbol, so cannot access that function or variable
by name.

It is good programming style to declare all functions and global variables
that do not need to be accessed by other files as 'static', in order
to avoid polluting the symbol table of the final objects with lots
of names. Having many symbol names increases the chance of conflicts
(ie. when you attempt to link against another object which has its own
similar symbol, the linker fails) so it is good to avoid this.

Further, it is usually a good idea to prefix the remaining symbols
(non-static functions and non-static globals) with a unique
identifier, such as the application or widget name, to get rid of any
chance of conflicts.

(think of non-static functions and globals as 'public' and static
functions and globals as 'private').

Conrad.




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