I apologise if it is a basic or silly question. What is the difference between char* and LPSTR. where the sizeof both gives 4 bytes in my compiler. Can someone explain me in detail. thanks..
I apologise if it is a basic or silly question. What is the difference
Share
LPSTRis a Windows type, meant to be be the same regardless of what platform you were compiling on. It’s a long pointer to a string.Back in the days of segmented architecture (the old 64K segments, not the newer selector-based segmented memory), where you had tiny, small, medium, large and huge memory models, it was important that the Windows type was always the same, regardless of what type of pointer
char *was.So, if you complied with different compilers where the underlying types were different, the
windows.hheader file would defineLPSTRto compensate for that.For example, Borland C may have had a sixteen-bit
char *andLPSTRmay have had to be defined asfar char *for it. In a compiler wherechar *was already a long/far pointer,LPSTRwould have just used that instead.Nowadays, with 32+ bit flat models, there is probably no real need for such shenanigans, though it may still happen with things like thunking between 64-bit and 32-bit code. Still, the types defined back then are still with us and still very much in use.