• How to convert concatenated strings to widechar with the C preprocessor?


    If you want to convert a character string literal to a wide character string literal, you properly define a macro as _L here:
     
    #define _L(x)  __L(x)
    #define __L(x) L ## x
    #define STR "I am handsome"
     
    wchar_t str1[] = _L("I am handsome" );
    wchar_t str2[] = _L(STR);
     
    It works fine at most all compiler currently. However, when use it to convert the concatenated string like
    #define STR3 "I am handsome\n" \
                 "I love u\n"
     
    wchar_t str3[] = _L(STR3);//error C2308: concatenating mismatched strings
     
    you will get a compiler error in MSVC.
    This is because it's the new feature in C99 standards. The MSVC don't support it for a long time.
    If uses the GCC, the second code piece get compiled without error.
     
    Look how C99 standard said.
    6.4.5 String literals
    In translation phase 6, the multibyte character sequences specified by any sequence of adjacent character and wide string literal tokens are concatenated into a single multibyte character sequence. If any  f the tokens are wide string literal tokens, the resulting multibyte character sequence is treated as a wide string literal; otherwise, it is treated as a character string literal.
  • 相关阅读:
    RMI、Hessian、Burlap、Httpinvoker、WebService的比较
    分布式事务(两阶段提交)模型详解
    CAP和BASE理论
    两阶段提交协议的异常处理
    到底什么是单元测试
    Fast Paxos 和 Paxos的区别
    Servlet和JSP生命周期概述
    Zookeeper和 Google Chubby对比分析
    优秀开源项目的svn地址
    Explain语法
  • 原文地址:https://www.cnblogs.com/aoaoblogs/p/2517870.html
Copyright © 2020-2023  润新知