A
addinall
Hi guys and gals,
Haven't been in here for a good decade or so!
I'm having a braid-dead moment that is lasting for
a couple of days. Declaring pointers to functions
witrhin structures and accessing same....
This doesnt work. I thought it should. The compiler disagrees with me!
gcc32
-- lots of stuff like this
sparqbeat.c: In function `__life':
sparqbeat.c:1188: request for member `primary' in something not a
structure or union
sparqbeat.c:1190: request for member `open_server_socket' in something
not a structure or union
sparqbeat.c:1192: request for member `bind_server_socket' in something
not a structure or union
sparqbeat.c:1194: request for member `server' in something not a
structure or union
sparqbeat.c:1198: request for member `verbose' in something not a
structure or union
sparqbeat.c:1200: request for member `display' in something not a
structure or union
sparqbeat.c:1202: request for member `log_it' in something not a
structure or union
sparqbeat.c:1204: request for member `itoa' in something not a
structure or union
sparqbeat.c:1204: request for member `identity' in something not a
structure or union
sparqbeat.c:1204: request for member `scratch' in something not a
structure or union
sparqbeat.c:1205: request for member `me' in something not a structure
or union
sparqbeat.c:1210: request for member `verbose' in something not a
structure or union
sparqbeat.c:1212: request for member `display' in something not a
structure or union
sparqbeat.c:1214: request for member `log_it' in something not a
structure or union
---------
Any hints appreciated. I read the "variable arguments" thread,
and went back a few months looking for something similar.
Google returned 15,200,000 hits for
pointers to functions within structures
typedef struct __sparqbeat
{
int identity ; // my pid i
int child_identity ; // forked child pid
int error_number ; // current error state
int normal_pulse ; // pulse at rest, operation normal
int tachycardic ; // fast pulse, trying to recover
int port ; // what port to connect?
int time_of_death ; // how long 'till pronounced dead?
int beats ; // number of heartbeats since birth
int failures ; // number of failures since birth
int socket_fd ; // socket descriptor
int child_socket_fd ; // socket descriptor after fork
struct sockaddr_ini client_socket ; // client socket
structure
struct sockaddr_in server_socket ; // server socket structure
// 'encapsulated' functions
boolean ( *logging ) ( char * log_name ) = &__logging
;
void ( *log_it ) ( const char * err1, const char * err2,
const char * err3, const char * err4 ) = &__log_it ;
boolean ( *security_check) ( void ) = &__security_check ;
boolean ( *inherit ) ( void ) = &__inherit ;
boolean ( *birth ) ( int number_arguments, char ** arguments ) =
&__birth ;
boolean ( *triage ) ( void ) = &__triage ;
boolean ( *pulse ) ( void ) = &__pulse ;
boolean ( *life ) ( void ) = &__life ;
void ( *death ) ( char * eulogy ) = &__death ;
void ( *display ) ( char * message ) = &__display ;
void ( *usage ) ( void ) = &__usage ;
boolean ( *open_server_socket) ( void ) = __open_server_socket ;
boolean ( *bind_server_socket) ( void ) = &__bind_server_socket ;
boolean ( *open_client_socket) ( void ) = &__open_client_socket ;
boolean ( *connect_server) ( void ) = &__connect_server ;
void ( *shutdown_server) ( void ) = &__shutdown_server ;
void ( *shutdown_client) ( void ) = &__shutdown_client ;
void ( *server) ( void ) = &__server ;
void ( *client) ( void ) = &__client ;
void ( *send) ( int the_socket, char * ack ) = &__send ;
int ( *receive) ( int the_socket, char * peer_message ) = &__receive ;
char * ( *itoa) ( int value, char *string, int radix ) = &__itoa ;
boolean ( *ping_network) ( void ) = &__ping_network ;
boolean ( *ping_twin) ( void ) = &__ping_twin ;
boolean ( *read_config_file) ( void ) = &__read_config_file ;
} sparqbeat ;
sparqbeat * heartbeat ;
[....]
//-----------------------------
int main(int argc, char **argv)
{
if ( i_am_god() ) // need to be root for the
{ // tricks in this bad boy...
if ( new( heartbeat ) ) // allocate a new instance of the
{ // application object. Use heap
if ( heartbeat->birth( argc, argv ) ) // can the object birth
itself?
{ // if so, a long and happy life
heartbeat->life() ; // life handles the normal (should
be)
} // non-stop pulsing
else // but then again,
{ // birth failed, probably configuration
heartbeat->death( "Failed Birth" ) ; // other routines
will have written to
} // the .log files with detailed
} // information (depending on DEBUG level)
else // -----------------------------
{ // memory allocation failed, use the
printf( "Initial malloc FAIL" ) ; // routine printf. The
object
} // (and functions) are dead.(obviously)
} // -----------------------------
else // not root
{ // tell them
printf( "You must be root to run this utility" ) ;
} // and quit
// -----------------------------
clean_up() ; // look after memory, sockets and signals
// -----------------------------
return TRUE ; // ABEND is always abnormal, seek yea
} // the log files........bye
Ta.
Mark.
Haven't been in here for a good decade or so!
I'm having a braid-dead moment that is lasting for
a couple of days. Declaring pointers to functions
witrhin structures and accessing same....
This doesnt work. I thought it should. The compiler disagrees with me!
gcc32
-- lots of stuff like this
sparqbeat.c: In function `__life':
sparqbeat.c:1188: request for member `primary' in something not a
structure or union
sparqbeat.c:1190: request for member `open_server_socket' in something
not a structure or union
sparqbeat.c:1192: request for member `bind_server_socket' in something
not a structure or union
sparqbeat.c:1194: request for member `server' in something not a
structure or union
sparqbeat.c:1198: request for member `verbose' in something not a
structure or union
sparqbeat.c:1200: request for member `display' in something not a
structure or union
sparqbeat.c:1202: request for member `log_it' in something not a
structure or union
sparqbeat.c:1204: request for member `itoa' in something not a
structure or union
sparqbeat.c:1204: request for member `identity' in something not a
structure or union
sparqbeat.c:1204: request for member `scratch' in something not a
structure or union
sparqbeat.c:1205: request for member `me' in something not a structure
or union
sparqbeat.c:1210: request for member `verbose' in something not a
structure or union
sparqbeat.c:1212: request for member `display' in something not a
structure or union
sparqbeat.c:1214: request for member `log_it' in something not a
structure or union
---------
Any hints appreciated. I read the "variable arguments" thread,
and went back a few months looking for something similar.
Google returned 15,200,000 hits for
pointers to functions within structures
typedef struct __sparqbeat
{
int identity ; // my pid i
int child_identity ; // forked child pid
int error_number ; // current error state
int normal_pulse ; // pulse at rest, operation normal
int tachycardic ; // fast pulse, trying to recover
int port ; // what port to connect?
int time_of_death ; // how long 'till pronounced dead?
int beats ; // number of heartbeats since birth
int failures ; // number of failures since birth
int socket_fd ; // socket descriptor
int child_socket_fd ; // socket descriptor after fork
struct sockaddr_ini client_socket ; // client socket
structure
struct sockaddr_in server_socket ; // server socket structure
// 'encapsulated' functions
boolean ( *logging ) ( char * log_name ) = &__logging
;
void ( *log_it ) ( const char * err1, const char * err2,
const char * err3, const char * err4 ) = &__log_it ;
boolean ( *security_check) ( void ) = &__security_check ;
boolean ( *inherit ) ( void ) = &__inherit ;
boolean ( *birth ) ( int number_arguments, char ** arguments ) =
&__birth ;
boolean ( *triage ) ( void ) = &__triage ;
boolean ( *pulse ) ( void ) = &__pulse ;
boolean ( *life ) ( void ) = &__life ;
void ( *death ) ( char * eulogy ) = &__death ;
void ( *display ) ( char * message ) = &__display ;
void ( *usage ) ( void ) = &__usage ;
boolean ( *open_server_socket) ( void ) = __open_server_socket ;
boolean ( *bind_server_socket) ( void ) = &__bind_server_socket ;
boolean ( *open_client_socket) ( void ) = &__open_client_socket ;
boolean ( *connect_server) ( void ) = &__connect_server ;
void ( *shutdown_server) ( void ) = &__shutdown_server ;
void ( *shutdown_client) ( void ) = &__shutdown_client ;
void ( *server) ( void ) = &__server ;
void ( *client) ( void ) = &__client ;
void ( *send) ( int the_socket, char * ack ) = &__send ;
int ( *receive) ( int the_socket, char * peer_message ) = &__receive ;
char * ( *itoa) ( int value, char *string, int radix ) = &__itoa ;
boolean ( *ping_network) ( void ) = &__ping_network ;
boolean ( *ping_twin) ( void ) = &__ping_twin ;
boolean ( *read_config_file) ( void ) = &__read_config_file ;
} sparqbeat ;
sparqbeat * heartbeat ;
[....]
//-----------------------------
int main(int argc, char **argv)
{
if ( i_am_god() ) // need to be root for the
{ // tricks in this bad boy...
if ( new( heartbeat ) ) // allocate a new instance of the
{ // application object. Use heap
if ( heartbeat->birth( argc, argv ) ) // can the object birth
itself?
{ // if so, a long and happy life
heartbeat->life() ; // life handles the normal (should
be)
} // non-stop pulsing
else // but then again,
{ // birth failed, probably configuration
heartbeat->death( "Failed Birth" ) ; // other routines
will have written to
} // the .log files with detailed
} // information (depending on DEBUG level)
else // -----------------------------
{ // memory allocation failed, use the
printf( "Initial malloc FAIL" ) ; // routine printf. The
object
} // (and functions) are dead.(obviously)
} // -----------------------------
else // not root
{ // tell them
printf( "You must be root to run this utility" ) ;
} // and quit
// -----------------------------
clean_up() ; // look after memory, sockets and signals
// -----------------------------
return TRUE ; // ABEND is always abnormal, seek yea
} // the log files........bye
Ta.
Mark.