网页资讯视频图片知道文库贴吧地图采购
进入贴吧全吧搜索

 
 
 
日一二三四五六
       
       
       
       
       
       

签到排名:今日本吧第个签到,

本吧因你更精彩,明天继续来努力!

本吧签到人数:0

一键签到
成为超级会员,使用一键签到
一键签到
本月漏签0次!
0
成为超级会员,赠送8张补签卡
如何使用?
点击日历上漏签日期,即可进行补签。
连续签到:天  累计签到:天
0
超级会员单次开通12个月以上,赠送连续签到卡3张
使用连续签到卡
06月06日漏签0天
c++吧 关注:618,026贴子:2,111,185
  • 看贴

  • 图片

  • 吧主推荐

  • 游戏

  • 1 2 下一页 尾页
  • 42回复贴,共2页
  • ,跳到 页  
<<返回c++吧
>0< 加载中...

关于 要不要有VLA

  • 只看楼主
  • 收藏

  • 回复
  • Con
  • <
    11
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
Stack Overflow上问过这个问题了,但是被认为是opinion-based problem,然后 put on hold 也是十分心酸,所以特此求助吧友,希望大家给予帮助,就不翻译了,markdown也不去掉了,大家知道意思就好


  • Con
  • <
    11
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
It's well-known that VLA is a kind of array implemented besed on WM, which can determine size at runtime. But that's what I all know about it. Now I want to know whether I should use it.
C99 firstly made VLA becomes a part of standard, but then in C11, standard permitted that complier can choose not to support VLA or VM if `#define __STDC_NO_VLA__ 1`, and C++ never bring VLAs into standard, even it hasn't come into TS. I want to find out why the situation is like that.
And here are some opinions(some are mine, some are others), if they are wrong, please point out for me, thank you.
1. It is redundant to use VLA.
> Each time the flow of control passes over the declaration, expression is evaluated (and it must always evaluate to a value greater than zero), and the array is allocated (correspondingly, lifetime of a VLA ends when the declaration goes out of scope). The size of each VLA instance does not change during its lifetime, but on another pass over the same code, it may be allocated with a different size.
If so, then if I use code like this, what is the difference except the *type*?:
Allocate some dynamic memory, and let pointer pt points to the first "element"
dosomething
free the memory allocated
By this way, I can subscript pt and easily modify the value. Except I cannot pass it to an array reference, it seems no differences at all.
2. VLA's performance is too bad.
This isn't my opinion but many people says that. But in fact I don't agree. I don't think it will takes more time than use "dynamic array".
3. VM is just too hard or too haze to implement.
Many semantics( or I'd say feature) should require complie-time evaluated expression, but VM can't implement that, so I think it could be too hard to define the behaviors.
4. C++ has `std::vector`, I think it will be more comfortable to use `vector` than use VLA.
In consequence, many people don't like VLA, but I did have seen someone likes it, so I the answer I want is your attitude t


2025-06-06 10:19:04
广告
  • Con
  • <
    11
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
最大两千字,不过我这贴了也差不多了,后面都是废话。


  • Con
  • <
    11
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
度娘又吞了这个世界对我不公


  • 南风吹北巷
  • +
    13
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
从C11学起的萌新表示从来不用VLA。
考试中会算错的。


  • Con
  • <
    11
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
事实证明没有邀答等于没发
@jxhzq1996 祭萌幻


  • Con
  • <
    11
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
@幻の上帝 @M_P_C_King @lh_mouse_ex
以及ID巨难打的各位。。


  • 桜内-千音
  • +
    13
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
萌新不懂


2025-06-06 10:13:04
广告
  • 神座流出
  • *
    14
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
运行时定界数组进过 TS 和 C++1y 草案,后来被踢出去了。


  • 萧の十三郎
  • *
    14
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
大佬竟然被SO被鄙视?
VLA会很慢吗?
如果特别大的话可能会吧。。 一般的小内存的话,应该很快,和alloca差不多吧


  • noelemahcz
  • <
    11
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
VLA是刚需么,C++现在动态内存也还挺好用的,不要再加些***的feature了


  • AWE
  • &
    9
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
运行时界定大小的数组自己实现一个又不是什么难事


  • 流光逝者如斯乎
  • +
    13
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
c++已经有了vector这种运行期长度的类了,而且还能动态扩展,支持泛型。难道真的为了迎合c语言,无脑增加一个语言特性么?所以c++采取不积极不主动不负责任的态度也是合适的。


  • 抬头望那苍穹
  • ==
    10
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
感觉没有必要弄个变长数组。vector感觉就比那玩意好使。


2025-06-06 10:07:04
广告
  • 幻の上帝
  • ->*
    15
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
没链接不评论。


登录百度账号

扫二维码下载贴吧客户端

下载贴吧APP
看高清直播、视频!
  • 贴吧页面意见反馈
  • 违规贴吧举报反馈通道
  • 贴吧违规信息处理公示
  • 1 2 下一页 尾页
  • 42回复贴,共2页
  • ,跳到 页  
<<返回c++吧
分享到:
©2025 Baidu贴吧协议|隐私政策|吧主制度|意见反馈|网络谣言警示