This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: gcc - static pointer initialization problem


This is pretty OT for this list. It's a plain "C" language issue.

You are creating two instances of type <funcPtrStructDef>, all named <funcPtrStruct>.
One is instanciated and initialized as you expect in static_function_ptr_def.c. But this instance is <static>, so it cannot be used from another module (i.e. from static_function_ptr.c)
Another instance is created and initialized to NULL in static_function_ptr.c, instance created in static_function_ptr_def.h line 11. This is the one that you are using at runtime. It is NULL and it has to be.


Statics are initialized to all zero's, unless explicitly initialized otherwise. That is correct, and that is what is happening here.
Instantiating a variable in a header file is hardly ever a good idea .. it will usually be instantiated more than once in the runtime.
Static members are not accessible by other modules, so your example can't work the way you expect it.


HTH
;Henning



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]