Board index » cppbuilder » const LPSTR

const LPSTR


2005-07-30 04:14:17 AM
cppbuilder47
Why does the following code compiles?
strcpy((const LPSTR) hwKey, hwKey);
while
strcpy((const char *) hwKey, hwKey);
does not.
 
 

Re:const LPSTR

tinyabs wrote:
Quote
Why does the following code compiles?

strcpy((const LPSTR) hwKey, hwKey);
while
strcpy((const char *) hwKey, hwKey);
does not.


May be because LPSTR is a typedef and C++ is a strictly typed language?
LPSTR is declared this way (MSDN):
typedef CHAR *LPSTR;
 

Re:const LPSTR

Muzaffar Mahkamov < XXXX@XXXXX.COM >writes:
Quote
tinyabs wrote:
>Why does the following code compiles?
>strcpy((const LPSTR) hwKey, hwKey);
>while
>strcpy((const char *) hwKey, hwKey);
>does not.
>
May be because LPSTR is a typedef and C++ is a strictly typed language?

LPSTR is declared this way (MSDN):

typedef CHAR *LPSTR;
Which means that
const LPSTR
is a synonym to
CHAR * const LPSTR
, i.e. the pointer is const, whereas in const char *, the char objects
are const.
 

{smallsort}