Originally Posted by
manav
i am hearing such comments from someone who uses cryptic (to me, at least
) #defines to make it even more difficult to understand template ridden code
Not really. You need some more practice, that's all. It removes long, template-ish lines which has to be duplicated all the time.
but anyways such typedefs have advantages:
like:
Code:
char* p, q r; // not all are pointers :(
LPSTR p, q, r; // all are pointers :)
Code:
typedef LPVOID void*;
typedef LPPVOID void**;
typedef LPINT int*;
void myfunc(LPVOID p);
int main()
{
LPVOID myvar;
LPPVOID myvarr;
myvarr = &myvar; /* Wtf? How can you assign the address of one variable to another which is not a pointer? */
int myint = 0;
LPINT myint2;
myint2 = &myint; /* Wtf? How can you assign the address of one variable to another which is not a pointer? */
*myint2 = 5; /* Wtf? Myint2 is a variable, not a pointer */
LPVOID myvar2 = 100; /* Valid in C! */
myfunc(myvar2, 4);
}
void myfunc(LPVOID p)
{
int val = 4;
memcpy(p, &val, sizeof(val));
}
It could go on. This will make your head hurt in complex code whereas, if you simply typed int, int*, void* or void**, it would be so much simpler.
Worse is if someone renames them such as:
Code:
typedef struct
{
/* ... */
} *mystruct;
/* Wtf? mystruct is a pointer, not a variable! */
Originally Posted by
robwhit
For type-matching with an API that specifies the use of such type.
Use documentation instead. It's much less error prone than using stupid typedefs for taking arguments.
Say: this function expects the address of a variable of type X instead of typing LPVOID.