免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2693 | 回复: 7
打印 上一主题 下一主题

问一个费解的问题#define SF_INT64(x) int filler_##x; int x; [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-02-28 10:29 |只看该作者 |倒序浏览
以前从来没见过,是什么意思呢?请教高手!

论坛徽章:
1
射手座
日期:2013-08-21 13:11:46
2 [报告]
发表于 2011-02-28 10:44 |只看该作者
将##的左边和右边在编译期间连接成一个token.

PS:
几乎任何一本语法书都会讲这个东西.

论坛徽章:
0
3 [报告]
发表于 2011-02-28 10:47 |只看该作者
将##的左边和右边在编译期间连接成一个token.

PS:
几乎任何一本语法书都会讲这个东西.
egmkang 发表于 2011-02-28 10:44

能讲的详细一点吗?因为用这个关键字去google搜索很难搜索到想要的信息。能讲讲这个定义的语义,与它等效的定义,和用法吗?

论坛徽章:
1
射手座
日期:2013-08-21 13:11:46
4 [报告]
发表于 2011-02-28 11:08 |只看该作者
能讲的详细一点吗?因为用这个关键字去google搜索很难搜索到想要的信息。能讲讲这个定义的语义,与它等效 ...
torthtyo 发表于 2011-02-28 10:47


强烈推荐你去买一本TCPL看看.

#define SF_INT64(x) int filler_##x; int x;

SF_INT64(x1)  就等价于:

int filler_##x1; int x1;

等价于:

int filler_x1; int x1;

论坛徽章:
0
5 [报告]
发表于 2011-02-28 11:09 |只看该作者
你调用这个宏函数 SF_INT64(Test)
编译后的代码就相当于: int filler_Test; int x;
## 只是起到连接作用...

论坛徽章:
0
6 [报告]
发表于 2011-02-28 12:53 |只看该作者
本帖最后由 torthtyo 于 2011-02-28 12:59 编辑
你调用这个宏函数 SF_INT64(Test)
编译后的代码就相当于: int filler_Test; int x;
## 只是起到连接作用 ...
wb112200 发表于 2011-02-28 11:09

呵呵,谢谢了,我是用java的 因为要用到jni的native代码,所以遇到了这个问题。 我当时猜是这个意思,让我迷惑的是,如果这样定义,我的代码就变得不通用了:

sf_iobuf        Points to a sf_parms structure defined as follows:
/*
* Structure for the send_file system call
*/
#ifdef __64BIT__
#define SF_INT64(x)     int64_t x;
#define SF_UINT64(x)    uint64_t x;
#else
#ifdef _LONG_LONG
#define SF_INT64(x)     int64_t x;
#define SF_UINT64(x)    uint64_t x;
#else
#define SF_INT64(x)     int filler_##x; int x;
#define SF_UINT64(x)    int filler_##x; uint_t x;

#endif
#endif

struct sf_parms {
    /* --------- header parms ---------- */
    void      *header_data;         /* Input/Output. Points to header buf */
    uint_t      header_length;      /* Input/Output. Length of the header */
    /* --------- file parms ------------ */
    int       file_descriptor;      /* Input. File descriptor of the file */
    SF_UINT64(file_size)            /* Output. Size of the file */
    SF_UINT64(file_offset)          /* Input/Output. Starting offset */
    SF_INT64(file_bytes)            /* Input/Output. number of bytes to send */
    /* --------- trailer parms --------- */
   void      *trailer_data;         /* Input/Output. Points to trailer buf */
   uint_t    trailer_length;        /* Input/Output. Length of the trailer */
    /* --------- return info ----------- */
    SF_UINT64(bytes_sent)           /* Output. number of bytes sent */
};

我需要这样一行代码, file_bytes = count; //count 是 64bit的jlong
如果是按照红色的行定义,上面的赋值就得单独处理,我觉得这样的做法是不值得提倡的

论坛徽章:
0
7 [报告]
发表于 2011-02-28 13:51 |只看该作者
呵呵 这些设计我们现在用到了就用 如果新设计什么东西 能不用就不用了

论坛徽章:
0
8 [报告]
发表于 2011-02-28 14:40 |只看该作者
这个是预处理的事情,JNI一样可以连进去.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP