2009-08-23 21 views
0

我想下面的代码从MSVC转换与gcc charlower用gcc

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

这段代码是给一个编译器错误:从“字符*”到“炭”铸损失精度

我的理解是来自c的tolower(int)不会转换整个字符串。 谢谢。

回答

0

演员表演CharLower正在引发该错误。在此之前,您需要设置传递到的指针的高位字节CharLower等于零。

从功能上MSDN参考:

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.

像这样的东西可能会奏效:

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

如果您使用的是C++编译器,你可能还需要CAST操作:

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

虽然没有测试过......

+0

没有完全起作用。但谢谢你的解释。 我只是要重写代码使用tolower() – Naveen 2009-08-23 03:53:30

+0

我只能这样做:

 * aStr = (char)(int)ltolower(*aStr);
Naveen 2009-08-31 22:59:18