- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
考虑以下函数:
int bar(const int* __restrict x, void g())
{
int result = *x;
g();
result += *x;
return result;
}
我们是否需要从 x
中读取两次,因为调用了 g()
?或者 __restrict
ion 是否足以保证 g()
的调用不会访问/不会更改地址 x
处的值?
在 this link我们看到最流行的编译器对此有看法(GodBolt;语言标准 C99,平台 AMD64):
clang 是否正确地优化了第二次读取,或者不是吗?我在这里要求同时使用 C 和 C++,因为行为是相同的(感谢@PSkocik)。
相关信息和一些注意事项:
__restrict
(或 __restrict__
)的读者可能想看看:What does the restrict keyword mean in C++? x
被标记为 const
的事实在这里并不重要 - 如果我们删除 const
并且问题成立,我们会得到相同的行为原样。最佳答案
我认为这实际上是一个 C 问题,因为 C 实际上是具有 restrict
并附有正式规范的语言。
控制 restrict
使用的 C 标准部分是 6.7.3.1 :
1 Let D be a declaration of an ordinary identifier that provides a means of designating an object P as a restrict-qualified pointer to type T.
2 If D appears inside a block and does not have storage class extern, let B denote the block. If D appears in the list of parameter declarations of a function definition, let B denote the associated block. Otherwise, let B denote the block of main (or the block of whatever function is called at program startup in a freestanding environment).
3 In what follows, a pointer expression E is said to be based on object P if (at some sequence point in the execution of B prior to the evaluation of E) modifying P to point to a copy of the array object into which it formerly pointed would change the value of E.137) Note that ''based'' is defined only for expressions with pointer types.
4 During each execution of B, let L be any lvalue that has &L based on P. If L is used to access the value of the object X that it designates, and X is also modified (by any means), then the following requirements apply: T shall not be const-qualified. Every other lvalue used to access the value of X shall also have its address based on P. Every access that modifies X shall be considered also to modify P, for the purposes of this subclause. If P is assigned the value of a pointer expression E that is based on another restricted pointer object P2, associated with block B2, then either the execution of B2 shall begin before the execution of B, or the execution of B2 shall end prior to the assignment. If these requirements are not met, then the behavior is undefined.
5 Here an execution of B means that portion of the execution of the program that would correspond to the lifetime of an object with scalar type and automatic storage duration associated with B.
按照我的理解,g()
的执行属于 bar
block 的执行,所以 g()
不允许修改 *x
并且 clang
是 优化第二个负载的权利(IOW,如果 *x
指的是一个非常量全局变量,g()
不能修改那个全局变量。
关于c - __restrict vis-a-vis 流行编译器的函数优化行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54847052/
我有一个 vis.js 网络图,其中包含节点之间的多条边,我也尝试使用分层布局对其进行设置。如果我做一个没有分层布局选项的普通图形,那么节点之间会显示多条线,但是,一旦我打开/放置分层布局选项,只绘制
是否可以在组中设置与节点中相同的颜色选项?只有在 icon.color 中将颜色作为字符串传递才有效。但我还想设置悬停 和突出显示 颜色。 我试过以下方法: var options={ group
考虑以下函数: int bar(const int* __restrict x, void g()) { int result = *x; g(); result += *x;
我正在尝试将 vis.js 功能集成到 Oracle Application Express 中,但似乎根本无法使其工作。 如果我单独运行脚本,它会正常工作,但是当我尝试在 APEX 中加载脚本 (v
我是一名 C# 开发人员,受托为我们的一个项目开发 Android native 应用程序,该项目的 C# 逻辑引擎作为 REST 服务公开。当前项目有一个使用 Html5 和 JS 的 Web 版本
我添加了 xType="time"到图表以在 x 轴上显示时间刻度。我只显示 25 秒范围内的数据。目前,x 轴显示的时间格式为 :SS . 所以 x 轴以下列格式显示时间(数据显示每秒): :23,
当 vis.js 在网络节点上时,有没有办法改变鼠标光标?我希望将它们视为节点所代表对象的链接,并被要求将光标更改为“手指”图标以指示可以单击它。 最佳答案 对我来说,它的工作有 3 个步骤 1.如果
我正在使用 vis.js 的二维折线图 ( http://visjs.org/graph2d_examples.html )。有没有办法向数据点添加工具提示,以便当您将鼠标悬停或单击时,您可以在弹出窗
我正在按照 vis 的动态数据集示例进行操作,但在尝试设置边时遇到 typescript 错误。 我只有一个边缘数组,看起来像: edgesArray = [ { from: 1, to: 3 },
我试图在同一页面上使用网络和时间线包(就像我在使用旧的 4.21 版本时所做的那样,它在那里工作),但我无法让它工作。当我向网络提供可见数据集时,它会抛出错误(需要数据集或数组)。如果我删除标题中时间
js 和 angular 在我的网页上显示一些图表。我安装了 npm install vis npm install @type/vis 但我发现两者都有一个名为 DataView 的函数。 我想使用
我使用 vis.js 创建了一个时间线图表。我有很多 vis-box 项目。因为我可以在时间轴上显示非常有限的信息。因此,当用户移动到项目上时,我想显示该项目的详细信息。 我在这个 url http:
如何使用特定日期数组和每个日期的特定标签制作我自己的 x 轴? 像这样的…… 这些是每三周一次,但我的需要是标记每个蓝色组(彩色是事件),每个组都有开始和结束日期 最佳答案 您可以使用格式函数自定义
我有一个由 vis.js 创建的大型网络图,它在浏览器中的宽度为 100% 并且非常高,因此需要向下滚动页面才能看到所有内容 - 我希望我的页面能够像世界上大多数其他网页一样运行 - 但是vis.js
我正在使用 vis.js 来显示节点,并非所有节点都相互连接,但它们如图所示重叠,有没有办法避免这种情况,我浏览了配置选项,但无法寻找。 最佳答案 我建议对物理和布局使用手动配置: configure
是否可以使用visjs在时间轴上绘制折线图? 我想在这里得到类似的东西 http://almende.github.io/chap-links-library/js/timeline/examples
我正在使用 Visjs 并用文本显示矩形节点。有些节点可以有几行文本,因此我添加了一种启发式算法来大致计算出换行符应该在哪里,以避免在非常宽但非常短的节点中出现非常宽的单行文本 block 。 问题是
vis.js 库是 1.6mb,缩小后的文件是 610k,这仍然太大了。将库文件下载到用户机器上需要相当长的时间,尤其是在网络连接速度较慢的情况下。 目前我只使用这个库来构建时间线图,我想知道是否有办
我使用 vis.js 在层次网络图中发现了这种奇怪的布局。如您所见,边缘被弄乱了。任何建议都会很好。谢谢。还是可以通过父节点位置改变排序函数? 图1:当前网络 图2:预期网络 最佳答案 根据 this
我对这个库有问题 vis.js 数据是正确的(图表内部也是正确的),但在视觉上它们没有被正确表示。 例子: 红色节点与蓝色节点有连接。绿色节点与黑色节点有连接 问题:红色节点在绿色节点内部传递到蓝色节
我是一名优秀的程序员,十分优秀!