为什么叫sizeof操作符有两个参数? [英] Why call sizeof operator with two arguments?

查看:364
本文介绍了为什么叫sizeof操作符有两个参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近碰到一些code,看上去像来了

I recently came across some code that looked like:

if(sizeof(var,2) == 4) { ... }

(其中 VAR 是一种类型)

我很惊讶地看到似乎是两个参数的sizeof 运营商。在ISO / ANSI C99标准的快速扫描没有取得任何秘密。我无法想出,允许一个逗号有语法的任何阅读。

I was quite surprised to see what appeared to be two arguments to the sizeof operator. A quick scan of the ISO/ANSI C99 standard did not yield any secrets. I couldn't come up with any reading of the grammar that allowed a comma there.

搜索谷歌code,我能够找到<一个href=\"http://www.google.com/$c$csearch/p?hl=en#YaNWgKqS-Ho/p-vxworks/i386-wrs-vxworks/sys-include/arch/ppc/toolPpc.h&q=%22sizeof(mode,2)%22&l=519\">an这个语法在一些PPC code的例子。

Searching Google Code, I was able to find an example of this syntax in some PPC code.

这是一些具体的PPC-语法?这是什么意思?

Is this some PPC-specific syntax? What does it mean?

编辑:事实证明,无论什么,我一直在寻找 - 以及链接code - 语法是特定于<一个href=\"http://74.125.95.132/search?q=cache:zuQVRjmLT6sJ:https://support.windriver.com/olsPortal/download%3Bjsessionid%3D5b6397d842c51ec425e8532f3591ed7788e78b4ec5b65f0df3314c020d895127.e3yQb3uNa3aRe34MbxuMc3iNbNz0%3FdocId%3D2755%2Bsizeof%2Boperator%2Bdiab%2Bppc&cd=2&hl=en&ct=clnk&gl=us\">WindRiver迪亚卜编译:

It turns out that both what I was looking at--as well as the linked code--is syntax specific to the WindRiver Diab compiler:

的sizeof (类型,INT-常量):

sizeof(type, int-const):

如果INT-const为0 的sizeof 返回的大小,类型的字节数。

If int-const is 0 sizeof returns the size in bytes of type.

如果INT-const为1 的sizeof 返回类型的对齐。

If int-const is 1 sizeof returns the alignment of type.

如果INT-const为2 的sizeof 返回一个整型常量指定
  类型类型。查一查sizeof操作符中的
  的迪亚布C / C ++用户指南的对数值。

If int-const is 2 sizeof returns an integer constant designating the type of type. Look up "sizeof operator" in the Diab C/C++ User's Guide for values.

哇,他们真的已经超载了的sizeof 运营商的意义。

Wow, they've really overloaded the meaning of the sizeof operator.

EDIT2:的完整文档是在这里:<一href=\"http://www.vxdev.com/docs/vx55man/diab5.0ppc/c-additi.htm#3001432\">http://www.vxdev.com/docs/vx55man/diab5.0ppc/c-additi.htm#3001432

Full documentation is here: http://www.vxdev.com/docs/vx55man/diab5.0ppc/c-additi.htm#3001432

推荐答案

在进一步的研究,我发现这是特定于<行为href=\"https://support.windriver.com/olsPortal/faces/manuals%5Fpublic%5Fsearch%5Fresults.jspx;jsessionid=3c3b3b290f1a62d77628bfccde40eb6e31acfc6eabaa43de12efba42de5ad361.e3yQb3uMbNuLe34SahaOa3mKa3b0?action=search&prodId=382\">WindRiver迪亚布编译。请参阅修改在细节问题。

On further research, I discovered that this is behavior specific to the WindRiver Diab compiler. Please see the EDIT in the question for details.

这篇关于为什么叫sizeof操作符有两个参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆