免费注册 查看新帖 |

Chinaunix

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

[C++] 这个也不是c++语法吧?? [复制链接]

论坛徽章:
84
每日论坛发贴之星
日期:2015-12-29 06:20:00每日论坛发贴之星
日期:2016-01-16 06:20:00每周论坛发贴之星
日期:2016-01-17 22:22:00程序设计版块每日发帖之星
日期:2016-01-20 06:20:00每日论坛发贴之星
日期:2016-01-20 06:20:00程序设计版块每日发帖之星
日期:2016-01-21 06:20:00每日论坛发贴之星
日期:2016-01-21 06:20:00程序设计版块每日发帖之星
日期:2016-01-23 06:20:00程序设计版块每日发帖之星
日期:2016-01-31 06:20:00数据库技术版块每日发帖之星
日期:2016-01-16 06:20:00程序设计版块每日发帖之星
日期:2016-01-16 06:20:00程序设计版块每日发帖之星
日期:2016-01-14 06:20:00
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2016-04-15 16:22 |只看该作者 |倒序浏览
本帖最后由 yjh777 于 2016-04-15 16:23 编辑

Internet-Draft
    https://tools.ietf.org/wg/nfsv4/ ... -from-06.wdiff.html

里面有这样的代码,上次来问了一遍,有人说是c++语法;可是最近翻 c++ primer 也没看到过这样的用法:

   <CODE BEGINS>

   /// struct ff_device_versions4 {
   ///         uint32_t        ffdv_version;
   ///         uint32_t        ffdv_minorversion;
   ///         uint32_t        ffdv_rsize;
   ///         uint32_t        ffdv_wsize;
   ///         bool            ffdv_tightly_coupled;
   /// };
   ///

   /// struct ff_device_addr4 {
   ///         multipath_list4     ffda_netaddrs;
   ///         ff_device_versions4 ffda_versions<>;      //<<<------------------- 这里
   /// };
   ///

   <CODE ENDS>

尝试编译报错:      ff_device_versions4 ffda_versions<>;   这个写法真的是 C++ 语法吗?还是伪代码?
  1. $ cat kkk.cpp
  2. #include <vector>
  3. #include <cstdint>

  4. using std::vector;

  5. struct ff_device_versions4 {
  6.         uint32_t        ffdv_version;
  7.         uint32_t        ffdv_minorversion;
  8.         uint32_t        ffdv_rsize;
  9.         uint32_t        ffdv_wsize;
  10.         bool            ffdv_tightly_coupled;
  11. };

  12. struct ff_device_addr4 {
  13.         int ffda_netaddrs;
  14.         ff_device_versions4 ffda_versions<>;
  15. };
  16. $ g++ -std=c++11 kkk.cpp
  17. kkk.cpp:16:22: 错误:expected ‘;’ at end of member declaration
  18.   ff_device_versions4 ffda_versions<>;
  19.                       ^
  20. kkk.cpp:16:35: 错误:expected unqualified-id before ‘<’ token
  21.   ff_device_versions4 ffda_versions<>;
  22.                                    ^

复制代码

论坛徽章:
84
每日论坛发贴之星
日期:2015-12-29 06:20:00每日论坛发贴之星
日期:2016-01-16 06:20:00每周论坛发贴之星
日期:2016-01-17 22:22:00程序设计版块每日发帖之星
日期:2016-01-20 06:20:00每日论坛发贴之星
日期:2016-01-20 06:20:00程序设计版块每日发帖之星
日期:2016-01-21 06:20:00每日论坛发贴之星
日期:2016-01-21 06:20:00程序设计版块每日发帖之星
日期:2016-01-23 06:20:00程序设计版块每日发帖之星
日期:2016-01-31 06:20:00数据库技术版块每日发帖之星
日期:2016-01-16 06:20:00程序设计版块每日发帖之星
日期:2016-01-16 06:20:00程序设计版块每日发帖之星
日期:2016-01-14 06:20:00
2 [报告]
发表于 2016-04-15 17:18 |只看该作者
知道了,不是什么 C++ 语法; 是 rpc .x 的特有语法,定义变长数组的:

The  rpcgen  compiler transfers this declaration into
the header file without modification.

You can also specify variable length arrays.

The maximum size of the array is enclosed in angle braces.  You can
omit the size to indicate that there is no maximum value.
For example, consider the following declaration:

        long x_coords<50>;

This declares  x_coords  to be an array of
0 to 50 long integers.  Similarly, the following declaration:

        long z_coords<>;


https://cs.nyu.edu/courses/spring00/V22.0480-002/class07.html

评分

参与人数 1可用积分 +6 收起 理由
MMMIX + 6 赞一个!

查看全部评分

论坛徽章:
84
每日论坛发贴之星
日期:2015-12-29 06:20:00每日论坛发贴之星
日期:2016-01-16 06:20:00每周论坛发贴之星
日期:2016-01-17 22:22:00程序设计版块每日发帖之星
日期:2016-01-20 06:20:00每日论坛发贴之星
日期:2016-01-20 06:20:00程序设计版块每日发帖之星
日期:2016-01-21 06:20:00每日论坛发贴之星
日期:2016-01-21 06:20:00程序设计版块每日发帖之星
日期:2016-01-23 06:20:00程序设计版块每日发帖之星
日期:2016-01-31 06:20:00数据库技术版块每日发帖之星
日期:2016-01-16 06:20:00程序设计版块每日发帖之星
日期:2016-01-16 06:20:00程序设计版块每日发帖之星
日期:2016-01-14 06:20:00
3 [报告]
发表于 2016-04-15 17:21 |只看该作者
更详细的介绍:  http://neo.dmcs.pl/rso/du/onc-rpc3.html

The syntax for each, followed by examples, is listed here:

    Simple declarations

            simple-declaration:
                    type-ident variable-ident

    For example, colortype color in XDR, is the same in C: colortype color. [Return to example]

    Fixed-length array declarations

            fixed-array-declaration:
                    type-ident variable-ident "[" value "]"

    For example, colortype palette[8] in XDR, is the same in C: colortype palette[8]. [Return to example]

    Variable-length array declarations

    These have no explicit syntax in C, so XDR creates its own by using angle brackets, as in the following syntax:

    variable-array-declaration:
            type-ident variable-ident "<" value ">"
            type-ident variable-ident "<" ">"

    The maximum size is specified between the angle brackets; it may be omitted, indicating that the array can be of any size, as shown in the following example:

            int heights<12>;        /* at most 12 items */
            int widths<>;           /* any number of items */

    Variable-length arrays have no explicit syntax in C, so each of their declarations is compiled into a struct. For example, the heights declaration is compiled into the following struct:

        struct {
            u_int heights_len; /* number of items in array */
            int *heights_val;  /* pointer to array */
        } heights;

    Here, the _len component stores the number of items in the array and the _val component stores the pointer to the array. The first part of each of these component names is the same as the name of the declared XDR variable. [Return to example]

    Pointer declarations

    These are the same in XDR as in C. You cannot send pointers over the network, but you can use XDR pointers to send recursive data types, such as lists and trees. In XDR language, this type is called optional-data, not pointer, as in the following syntax:

    optional-data:
            type-ident "*"variable-ident

    An example of this (the same in both XDR and C) follows:

            listitem *next;

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP