关于这个,我收到了很多相互矛盾的答案。但正如我一直理解的那样。
当我们在 C 中有一个指针并在后增量语句中使用它时,后增量总是在代码行解析之后发生。
int array[6] = {0,1,2,3,4,5};
int* p = array;
printf("%d", *p++); // This will output 0 then increment pointer to 1
Run Code Online (Sandbox Code Playgroud)
输出 :
0
Run Code Online (Sandbox Code Playgroud)
很简单的东西。现在,我在人们告诉我的信息和我自己的经历中遇到了一些不协调的地方。
// Same code as Before
int array[0] = {0,1,2,3,4,5};
int* p = array;
printf("%d", *(p++)); // Issue with this line
Run Code Online (Sandbox Code Playgroud)
输出 :
0
Run Code Online (Sandbox Code Playgroud)
现在,当我运行代码的第二个版本时,结果是它将输出 0 然后增加指针。括号所暗示的操作顺序似乎被违反了。但是,该站点上的其他一些答案告诉我,应该发生的正确事情是增量应该在取消引用之前发生。所以我想我的问题是:我的理解正确吗?后增量语句总是在行尾执行吗?
附加信息:
我正在使用 gcc 版本 ubuntu 4.8.4 在 linux mint 上使用 gcc 进行编译
我还在 debian 4.7.2 版本的 debian 上的 gcc 上对此进行了测试
例如,如果我想使用常数将滤波器系数存储在n-Tap FIR滤波器中,CONSTANT声明是否会使用FPGA触发器将我的值存储在Block RAM或寄存器中?也可以SIGNAL用来存储系数而不使用RAM单元?
我正在尝试编写一些代码,这些代码只会向左或向右移动 32 位向量,其中 5 位输入将用于移位量 ( shamt)。我遇到的问题是试图将 an 转换std_logic_vector为integer. 我的代码是这样的:
library ieee;
use ieee.STD_LOGIC_1164.all;
use ieee.STD_LOGIC_ARITH.all;
entity shiftlogical is
port(x : in std_logic_vector(31 downto 0);
shamt : in std_logic_vector( 4 downto 0);
y : out std_logic_vector(31 downto 0));
end shiftlogical;
architecture beh of shiftlogical is
signal shift : integer;
signal temp : std_logic_vector(31 downto 0);
begin
shift <= conv_integer(unsigned(shamt));
temp <= x(shift downto 0);
y <= temp;
end beh;
Run Code Online (Sandbox Code Playgroud)
我知道代码不完整,但为了测试一些想法,我试图将"00010"(2)传递到 中shamt,但结果是 …
如果我有:
int a = 123;
int b = 456;
Run Code Online (Sandbox Code Playgroud)
如何得到?:
double c = 123.456;
Run Code Online (Sandbox Code Playgroud)