I have the following structure
typedef struct _LSHFunctionT
{
double *a;
double b;
} LSHFunctionT, *PLSHFunctionT;
My question is; is there a difference between these two declarations
PLSHFunctionT myPointer1;
and
LSHFunctionT *myPointer2;
and if not, then why do people explicitly use two of them (LSHFunctionT and *PLSHFunctionT). Why not just use LSHFunctionT.
Does it go the same way for the following two declarations
PLSHFunctionT *myPointer3;
and
LSHFunctionT **myPointer3;
Yes,
PLSHFunctionT x;is equal toLSHFunctionT* x;And yes,
PLSHFunctionT* x;is equal toLSHFunctionT** x;The purpose of
typedefis to assign new names to existing types. You can definetypedef int lol;and declare variablelol i;, but compiler will consider itintanyway.You should also check these questions:
When should I use typedef in C++?
Why should structure names have a typedef?
Hope this helps.