zoukankan      html  css  js  c++  java
  • linux C++中宏定义的问题:error: unable to find string literal operator ‘operator""fmt’ with ‘const char [4]’, ‘long unsigned int’ arguments

    测试项目的代码里有这样的宏定义

    #define SCRPRINT(fmt,...)     fprintf(stderr, "[%s]-> "fmt"
    ", __FUNCTION__, ##__VA_ARGS__)

    在linux的c或者windows下的c/c++都没问题,在linux的cpp中编译无法通过,报了下面的错误

    error: unable to find string literal operator ‘operator""fmt’ with ‘const char [4]’, ‘long unsigned int’ arguments

    查了很久,才发现需要在fmt前面增加一个空格,这是C++11才新增的语法要求,而我们的操作系统和编译器刚好也升级了,导致以前的代码不兼容新的编译器了

    修改之后的代码如下:

    #define SCRPRINT(fmt,...)     fprintf(stderr, "[%s]-> " fmt"
    ", __FUNCTION__, ##__VA_ARGS__)

    增加空格之后,无论你的程序保存成.c或者.cpp文件,编译都是成功的,而且用旧版本的gcc/g++也没问题。

    有的文章里说fmt后面也要增加空格,实际测试下来似乎可有可无。

  • 相关阅读:
    滑动窗口法学习
    209. Minimum Size Subarray Sum
    485. Max Consecutive Ones
    27. Remove Element
    167. Two Sum II
    561. Array Partition I
    344. Reverse String
    14. 最长公共前缀
    layui上传文件时出现 请求上传接口出错
    Linux-5.13将初步支持苹果M1 Soc
  • 原文地址:https://www.cnblogs.com/cner/p/14084644.html
Copyright © 2011-2022 走看看