文章收藏-FAQ 位置:电脑学习网

C 语言中长度为 0 的数组妙用

    长度为0的数组在GNU C是可以使用的,在定义一个变长对象的结构体是非常有用的。
    
    请看下例:
    
    struct line {
    int length;
    char contents[0];
    };
    struct line *thisline = (struct line *)
    malloc (sizeof (struct line) + this_length);
    thisline-〉length = this_length;
    显然这样的代码要比下面的定义节省空间
    struct line {
    int length;
    char *contents;
    };
    struct line {
    int length;
    char contents[1];
    };

     [文章来源:“十万个为什么”电脑学习网]
     [网络地址:http://why100000.com]
     [版权声明:除本站部分特别声明禁止转载的专稿外,其他的文章可以自由转载,但请务必注明出处和原始作者。本站文章版权归文章原作者所有。如果本站转载的文章有版权问题请联系本站,我们会尽快予以更正。]
 

【字体:[大] [中] [小] 【加入收藏】 【发表评论】 【关闭本窗口】

Copyright © “十万个为什么”电脑学习网 2000-2007 陕ICP备06007929号
站务联系:MSN & Email:zhangking2008@gmail.com  QQ:9365822