Other Parts Discussed in Thread: CONTROLSUITE
Hi folks
Looking at the opaque pointer implementation used in the C2000 drivers from the device support files there is the following pattern used in the header files:
typedef struct _FOO_Obj_ { // Example class struct
uint16_t x; // Example member
} FOO_Obj;
typedef struct FOO_Obj * FOO_Handle;
But FOO_Obj is a tag for a struct, using struct again in the pointer typedef seems incorrect... I would have thought it should be either typedef FOO_Obj * FOO_Handler; or typedef struct _FOO_Obj_ * FOO_Handler;. What is being achieved here with the current method?
Then in the driver source file there is the following pattern for use of a passed FOO_Handle:
FOO_Handle FOO_init(void *pmemory, const size_t numBytes)
{
FOO_Handle fooHandle;
fooHandle = (FOO_Handle)pMemory;
return(fooHandle);
}
What is actually in fooHandle after the assignment? E.G. If I declare something to be of type FOO_Obj and then attempt to return the address (using return(&someFOO_Obj);) of it in a similar function that is supposed to return FOO_Handle, there is an error that the types do not match... so is FOO_Handle a pointer to _FOO_Obj_ or not?
Thanks
EDIT: Also, is hiding "pointer-ness" with a typedef not code smell? especially if wanting to pass as an argument with const-ness?