Your initial thought is fine. Nothing here involves any poi*nters to
function AFAICS
Thank you sir.
Victor, I'm batting 1/3 with you. :) I envisioned it would probably
take me two to three times to get it right since I might not have
understood something about your reponse or poor post on my part to
begin with :)
For clarification, here's the starLinkOpenStruct definition. So now.
// stalink.h
typedef unsigned int U32
// later
typedef struct _starLinkOpenStruct
{
U32 idx;
U32 starLinkId;
U32 flags;
U32 root;
void (*doorBellCallback)(struct _starLinkDevice *slDev, U32
doorBellVal);
} starLinkOpenStruct;
starLinkDevice is additonal struct which includes another struct and
that struct includes another struct, so for the purposes of discussion
and simplicity I'll modify it to look like.
// slink_mod.h
#ifndef SLINK_MOD_H
#define SLINK_MOD_H
typedef unsigned int U32;
// later
typedef struct _starLinkOpenStruct
{
U32 idx;
U32 starLinkId;
U32 flags;
U32 root;
void (*doorBellCallback)(U32 doorBellVal);
} starLinkOpenStruct;
#endif
// receiver.h
#ifndef RECV_H
#define RECV_H
# include "slink_mod.h"
static void myDoorBellISR(U32 doorBellVal)
{
doorBellVal = 5;
}
class receiver
{
public:
receiver (starLinkOpenStruct& slink_open_struct)
{
std::cout << " receiver called " << std::endl;
}
~receiver() {}
};
#endif
// test.cpp
# include <iostream>
# include "receiver.h"
# include "slink_mod.h"
int main()
{
starLinkOpenStruct myOpenStruct;
myOpenStruct.starLinkId = 100;
myOpenStruct.flags = 0;
myOpenStruct.doorBellCallback = myDoorBellISR;
myOpenStruct.root = 10;
receiver* recv = new receiver(myOpenStruct);
delete recv;
}
So I wrestled with the line.
myOpenStruct.doorBellCallback = myDoorBellISR;
For some strange reason I thought that having the user specify the
doorBellCallback member function is inane.