views:

56

answers:

1

I am trying to convert the following code from msvc to gcc

    #define ltolower(ch) CharLower((LPSTR)(UCHAR)(ch))
    char * aStr;
    * aStr = (char)ltolower(*aStr); 

This code is giving a compiler error: cast from ‘CHAR*’ to ‘char’ loses precision

My understanding is that tolower(int) from c wouldn't convert the whole string. Thanks.

A: 

Your cast in CharLower is raising that error. Before doing that, you need to set the high order byte of the pointer passed to CharLower equals to ZERO.

From MSDN reference on the function:

If the operand is a character string, the function returns a pointer to the converted string. Because the string is converted in place, the return value is equal to lpsz.

If the operand is a single character, the return value is a 32-bit value whose high-order word is zero, and low-order word contains the converted character.

Something like this might work:

#define ltolower(ch) CharLower(0x00ff & ch)

If you are using a C++ compiler, you might also need a CAST operator:

#define ltolower(ch) CharLower((LPTSTR)(0x00ff & ch))

Haven't tested it though...

Pablo Santa Cruz
that didn't work exactly. But thanks for the explanation.I am just going to rewrite the code using tolower()
Naveen
I was able to just do: <pre> * aStr = (char)(int)ltolower(*aStr); </pre>
Naveen