小编Fin*_*Man的帖子

处理HDL中的数组

如何在HDL中使用数组(表示总线)?

例如,我有以下代码:

/**
 * 16-bit bitwise And:
 * for i = 0..15: out[i] = (a[i] and b[i])
 */

CHIP And16 {
    IN a[16], b[16];
    OUT out[16];

    PARTS:
    // Put your code here:
}
Run Code Online (Sandbox Code Playgroud)

假设我And已经实现了,我该如何实现呢?

我宁愿没有以下内容:

And(a=a[0],b=b[0],out=out[0]);
And(a=a[1],b=b[1],out=out[1]);
...
And(a=a[14],b=b[14],out=out[14]);
And(a=a[15],b=b[15],out=out[15]);
Run Code Online (Sandbox Code Playgroud)

arrays syntax hdl bus nand2tetris

7
推荐指数
1
解决办法
1319
查看次数

如何为 C++ 中采用“char*”的函数提供“const char*”参数?

我有以下代码。

const char* my_input = "my string";

void my_function(char* my_argument);

int main()
{
  my_function(my_input);
}

void my_function(char* my_argument)
{
  /* Do something */
}
Run Code Online (Sandbox Code Playgroud)

请注意,my_function 的参数需要“char*”,但我为其提供了“const char*”。

我的 IDE 给出错误:没有调用“my_function”的匹配函数。

我认为这是因为函数调用被解释为“my_function(const char* my_argument)”,我显然没有定义(并且不想)。

我怎样才能使我的常量输入对于预期的非常量参数有效?

在我的真实程序中,我有一个接受“char*”的函数,但它不会修改它。参数本身可能不是一个常量(通常也不是),但有时我期望一个常量。

c++ arguments constants function

4
推荐指数
1
解决办法
5256
查看次数

标签 统计

arguments ×1

arrays ×1

bus ×1

c++ ×1

constants ×1

function ×1

hdl ×1

nand2tetris ×1

syntax ×1