lundi 28 mai 2018

Object Pointer to a function

I read a piece of header code and I found below:

ObjPtr.h:

include

define OBJPTR(X) void* X##Ptr ; \

                            void* (*X##ObjPtr)() ;

void * CreateObj(void * handler, char* LibName, char* FunctionName);

Transaction.c

. . . OBJPTR(DB); . . . DBObjPtr = CreateObj(DBPtr, "DBTransaction", "Function1"); if ((unsigned long)(DBObjPtr)(csPara1, csPara2) != PD_FOUND) { . .

.

First, I don't understand what does it mean in the define line in the header file. (Why there is X## in the define line? What does it mean?)

Second, in the c file object is created instead of calling function directly. I think the purpose of such design is for isolation between objects for ease in maintenance and solution build/delivery; or code encryption from different developers, if I am correct. But what else? Or what kind of this design pattern?

Aucun commentaire:

Enregistrer un commentaire