#define __T(x) L ## x , L是宽字符串的前缀

转自:http://blog.sina.com.cn/s/blog_5038ce7a0100cjb1.html

VC2005、2008编写第一个Windows程序很容易遇到的问题:不能将参数 2(等等吧) 从“const char [ ]”转换为“LPCWSTR”

这是因为VC2005、2008默认定义了#define UNICODE,这样调用的API都是宽字符版本,如同在VC6编程的开头定义了 #define UNICODE……

解决: 1.如果不准备编写使用UNICODE编码的程序,则在工程属性、常规中修改“字符集”选项,默认的“使用UNICODE字符集”导致了上述问题。

2.用VC6使用调用宽字符API的方法转换字符串为宽字符串,即控制台的常用宽字符串前缀L,如"ABC"写成标识定义成宽字符串 L"ABC"。windows编程中使用_T("ABC"),效果是一样的。这样写的程序是UNICODE程序,即使在不同语言计算机上也不会出现乱码……就是程序大小会比ANSI程序大一点点……


转自:http://bbs.csdn.net/topics/390198228


tchar文件定义
#define __T(x)      L ## x
L是宽字符串的前缀
__T("你好")展开等价于L“你好”, ##在宏里为连接符
比如说:_T("String Text")
展开后就是:L"String Text"

##在宏里面相当于连接符,把前后两个字符串连在一起作为一个字符串。


1,C/C++标准里没有任何解释
2,Rationale 里只解释了为什么用前缀而不是后缀

那么,L 难道就是 Literal 的首字母?或是 Large,或是 Long ?

何不用 Wide ?据说是重用已有的 long 字面量后缀字母?

有没有确切的说法

大家认为是什么

下面是引文

C99
$6.4.5 String literals
$6.4.5/2
A character string literal is a sequence of zero or more multibyte characters enclosed in double-quotes, as in "xyz".A wide string literal is the same, except prefixed by the letter L.

C++2003
$2.13.2 Character literals
$2.13.2/1
A character literal is one or more characters enclosed in single quotes, as in ’x’, optionally preceded by the letter L, as in L’x’.

$2.13.2/2
A character literal that begins with the letter L, such as L’x’, is a wide-character literal. A wide-character literal has type wchar_t.

Rationale for International Standard Programming Languages C
$6.4.5 String literals
An L prefix distinguishes wide string literals.  A prefix rather than a suffix notation was adopted so that a translator can know at the start of the processing of a string literal whether it is dealing with ordinary or wide characters.

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值