【问题标题】:CPP expands macros in %-lines in rpcgen source fileCPP 在 rpcgen 源文件的 %-lines 中扩展宏
【发布时间】:2012-07-14 15:49:40
【问题描述】:

以符号 '%' 开头的行应该在输出文件中按原样传递, 但是这些行是否有一些 CPP 宏,这些宏也会被扩展:

来源(test.x):

#ifdef ONE
#warning "ONE is defined"
#else
#warning "NO ONE!!!!!1111"
#endif

%
% hello, ONE
%

运行 rpcgen:

# rpcgen test.x -DONE
test.x:2:2: warning: #warning "ONE is defined" [-Wcpp]
test.x:2:2: warning: #warning "ONE is defined" [-Wcpp]
test.x:2:2: warning: #warning "ONE is defined" [-Wcpp]
test.x:2:2: warning: #warning "ONE is defined" [-Wcpp]

结果(test.h):

/*
 * Please do not edit this file.
 * It was generated using rpcgen.
 */

#ifndef _TEST_H_RPCGEN
#define _TEST_H_RPCGEN

#include <rpc/rpc.h>


#ifdef __cplusplus
extern "C" {
#endif


 hello, 1


#ifdef __cplusplus
}
#endif

#endif /* !_TEST_H_RPCGEN */

所以“ONE”被替换为“1”,但最好保持原样 (在结果 test.h 中考虑“#ifdef ONE”)

有什么办法可以避免吗?

【问题讨论】:

    标签: rpc c-preprocessor


    【解决方案1】:

    所以,我有一个使用 CPP 包装器的解决方法:

    1. somedir/cpp

      #!/bin/sh

      执行 /usr/bin/cpp -U_LP64

    2. 以 rpcgen -Y somedir 运行 rpcgen

    【讨论】:

      猜你喜欢
      • 2016-04-14
      • 2010-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-09
      • 2023-02-10
      • 2011-03-03
      • 2013-03-02
      相关资源
      最近更新 更多