问题标签 [indirection]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
8 回答
17963 浏览

computer-science - Level of Indirection solves every Problem

What does the quote "Level of Indirection solves every Problem" mean in Computer Science?

0 投票
4 回答
555 浏览

language-agnostic - 你有没有遇到过三级间接的任何原因?

只需浏览我最喜欢的一本书(Ellen Ullman 的 The Bug),就会发现一个程序员在三个间接级别上遇到另一个程序员:

我得到了双重间接的想法——一种将指针传递给函数的方法,并允许它指向在函数中创建的对象。

但是你有没有遇到过使用三个(或更多)间接级别的理由?

0 投票
2 回答
233 浏览

c++ - Include indirection on Visual C++

Let's say we have an application that will need Boost to compile. Boost being an external library, updated regularly, and our application having multiple binaries and multiple versions ("multiple" as in "Let them grow and multiply"... don't ask...), we need an easy to update/maintain indirection to have for each app's version link with the right Boost version.

For example:

  • MyApp 8.0 => Boost 1.34
  • MyApp 8.1 => Boost 1.35
  • MyApp 9.0 => Boost 1.35
  • MyApp 10.0 => Boost 1.37

On a Linux filesystem, we would create a symbolic link redirecting to the right boost directory:

  • MyApp 8.0 => MyAppBoostLink_8.0 => Boost 1.34
  • MyApp 8.1 => MyAppBoostLink_8.1 => Boost 1.35
  • MyApp 9.0 => MyAppBoostLink_9.0 => Boost 1.35
  • MyApp 10.0 => MyAppBoostLink_10.0 => Boost 1.37

This would enable us to easily update MyApp 10.0 to link with Boost 1.38 when it will be available, just by replacing the symbolic link.

But on Windows, this does not work (or I missed something).

Boost itself seems to give up on the idea: With BJam, I recall seeing warnings saying BJam was copying the lib files because symbolic links did not work on WinNT. I tried an alternative, as we use Visual C++, but no pragma resolves this problem (I searched for a pragma adding default search directories for header includes and library links, but found none).

I can't believe I'll need to launch a script to check-out the VCPROJs files (Visual C++ XML makefiles), to update the Boost includes, and then check-in the modifications, but I see no other solution until Windows have working symbolic links (or either I discover how to create them).

Is there a better idea?

Edit

The problem disappeared when we updated our compiler, from Visual C++ 2003 to Visual C++ 2008. Apparently, Visual C++ 2008 sees symbolic links across networks.

0 投票
2 回答
9484 浏览

c++ - 如何重载间接运算符?(C++)

我正在尝试创建一个迭代器类作为列表类的成员类,并尝试重载间接运算符 (*) 以访问它指向的列表:

其中lstptr是指向列表current的指针, 是指向节点类的指针,并且节点类包含datatype的数据成员T

迭代器声明如下:

我能够很好地编译重载 operator* 的函数定义,但是当我尝试执行以下操作时:

我得到的错误说 <1> 我使用了非法间接,而 <2> 它不能从 list::iterator 转换为 int。两个错误都发生在第十四行。

有谁知道我做错了什么以及如何正确重载间接运算符?

注意:如果您需要查看更多代码,请告诉我哪一部分,因为我不想将整个代码放在这里,因为它大约有 205 行,其中 204 行(我认为)没有任何错误。

0 投票
1 回答
1132 浏览

c# - C# P/Invoke:如何为结构化参数的字段实现双重间接

我正在从 C# 调用本机 dll。对于有问题的特定函数,我需要的参数之一是一个包含双重间接字段(指向指针的指针)的结构。

例如,采用以下 C 原型和结构:

以下 C# 代码只为字段 AnotherStruct 提供了一个间接级别,这是不正确的:

如何实现此处所需的双重间接?我知道在函数的双重间接参数的情况下如何做到这一点,但我对它嵌入在结构中的事实感到困惑。

也许我应该将 AnotherClass 字段声明为 IntPtr,然后使用不安全代码为其分配适当的值。这是一种有效的方法,还有其他/更好的选择吗?

0 投票
6 回答
8900 浏览

c++ - 从结构访问变量

我们如何访问结构的变量?我有一个结构:

在我的另一堂课中,我有一个方法:

**显示是什么意思?要访问我使用过的 struct 变量->,还有其他方法吗?

0 投票
3 回答
235 浏览

c - 在 C 中取消引用指针作为参数的目的

我最近遇到了这行代码:

我想,不是:

只是语法糖:

考虑到这一点,这一行可以重写为:

如果是这样的话,传入有什么意义

&(*a),作为参数,而不仅仅是 a? 似乎 -(-a) 的指针等效项正在传入,这有什么逻辑吗?

谢谢你。

0 投票
3 回答
3317 浏览

c - C中的直接调用与间接调用

我是 C 的新手,我正在阅读指针如何“指向”另一个变量的地址。所以我尝试了间接调用和直接调用,并收到了相同的结果(正如任何 C/C++ 开发人员所预测的那样)。这就是我所做的:

所以我想知道使用指针的间接调用是否比直接调用有任何优势,反之亦然?一些优点/缺点可能包括速度、执行操作所消耗的内存量(很可能相同,但我只是想把它放在那里)、安全性(如悬空指针)、良好的编程习惯等。
1有趣的是,我是使用 GNU C 编译器 (gcc),它仍然可以在没有 return 语句的情况下进行编译,并且一切都符合预期。可能是因为如果你忘记了 C++ 编译器会自动插入 return 语句。

0 投票
4 回答
1187 浏览

c++ - TOUGH:在 C++ 中处理深度嵌套的指针

我定义了这个结构:

和这些结构:

然后在我的代码中,我返回一个指向 s_molecule 的指针(类型定义为 t_molecule,但仍然如此)。

使用这个指针我可以让这个代码工作:

如果我将其替换为:

我现在遇到讨厌的段错误...

不要在这里放太多,但是当我尝试这样做时,我也会遇到段错误:

同样, current_molecule 是指向 s_molecule 结构的指针,该结构包含结构数组,而这些结构又或者直接具有变量或者是指针。我无法让这些多层间接工作。有关修复这些段错误的建议。

仅供参考,我正在使用 g++ 并使用自定义 makefile 系统在 Linux Centos 5.4 上进行编译。

0 投票
4 回答
388 浏览

c++ - C ++中的奇怪指针问题

我遇到了一个非常令人沮丧的指针问题。我之前在这里发布过: TOUGH:在 C++ 中处理深度嵌套的指针

但是那个帖子太长了而且过时了,所以我选择重新发布更多细节。

这是定义我的类型的头文件:

这是我为将 t_molecule 类型的 var 添加到分子数组的调用(请参阅上面的标题以了解 t_molecule 的定义)。

这完美地工作...... resname 字符串打印,并且债券向量中最后一个债券的信息打印。然后,一旦我添加了所有分子。我称之为:

这在债券线上出现了段错误。

我可以从我在添加步骤中打印的索引中看出我没有覆盖我推到向量上的分子(大小正在增长)..

换句话说,似乎正在发生的是:读取子向量(工作)->在父向量中添加更多项目->重新读取子向量(seg-faults)

这些函数是将分子变量添加到向量中的唯一方法,并且分子变量仅添加一次,并且在我当前的测试中不会在死后修改。

有任何想法吗????先感谢您!!