标签: operands

C操作数评估顺序的意外行为

所以只是为了好玩,我有这个代码片段:

#include <stdio.h>
main()
{
 int i;
 int a;
 i = 17;
 //scanf("%d", &i);
 a = (i+=5) * (i-=3);
 printf("a is %d, i is %d\n", a, i);
}
Run Code Online (Sandbox Code Playgroud)

在C规范中,它表示操作数评估的顺序是未定义的,所以我期望看到22*19或19*14.但是,结果是19*19:

~ $ gcc a.c
~ $ ./a.out
a is 361, i is 19
Run Code Online (Sandbox Code Playgroud)

我想到了,我能想出的唯一解释是编译器对值进行了"延迟"评估(i+=5),它认为(i+=5)价值只是i的值.同样的(i-=3).

但是,如果我取消注释scanf():

#include <stdio.h>
main()
{
 int i;
 int a;
 i = 17;
 scanf("%d", &i);
 a = (i+=5) * (i-=3);
 printf("a is %d, i is %d\n", a, i); …
Run Code Online (Sandbox Code Playgroud)

c evaluation operands

0
推荐指数
1
解决办法
197
查看次数

C#中所有操作数的列表

很简单的问题:如何获取C#中所有操作数的列表?例:

{ "return", "break", "if", "case", "switch", ... };
Run Code Online (Sandbox Code Playgroud)

更难的问题:如何获取所有函数(类型,方法)的列表?

{ "string", "Math.Abs", "double.IsNaN", "int.ToString", ... };
Run Code Online (Sandbox Code Playgroud)

我想为CodeDom制作类似IntelliSense(非常糟糕和肮脏的东西)的东西.因此,用户可以通过将其代码添加到我的文本中来扩展软件的功能.我向他提供了一个函数体,其中包含一些他可以使用的参数,但是他也应该能够使用任何标准函数,例如,或者.他将代码输入RichTextEditor.我想让他更容易看到语法(突出显示已知的操作数,打开/关闭括号,函数参数).double.ToString()Math.PI

我已经可以突出显示单词(参数)并且它看起来不错,但突出一切都很酷.而且我认为这是得到的操作数/ functins /类型/方法,我也不懂怎么办(我都可以操作数输入到阵列中自己OFC)的想法名单.

这个问题应该改写一下:如何制作我自己的IntelliSense?:-)

PS:快速潜伏甚至没有提供我一个单一的结果,我实际上有问题来制定我正在寻找的东西.

c# intellisense rich-text-editor operands

0
推荐指数
1
解决办法
406
查看次数

比较通用方法中的两个值c#

我认为我的代码可以自我解释我想要实现的目标:

private bool Comparison<T>(T operatorOne, T operatorTwo, string operand)
    {
        switch (operand.ToLower())
        {
            case "=":
                return operatorOne.Equals(operatorTwo);
            case "<":
                return operatorOne < operatorTwo;
            case ">":
                return operatorOne > operatorTwo;
            case "contains":
                return operatorOne.ToString().Contains(operatorTwo.ToString());
            default:
                return false;
        }
    }
Run Code Online (Sandbox Code Playgroud)

它给了我错误:

Error   16  Operator '>','<' cannot be applied to operands of type 'T' and 'T'
Run Code Online (Sandbox Code Playgroud)

我需要一个可以比较字符串,Int,Double,chars的方法.注意:排除将为>或<check>传递字符串的条件或将为"包含"检查发送Int

c# generics comparison operators operands

0
推荐指数
1
解决办法
884
查看次数

类型为'int'和'double(double*,double*,int)'的二元运算符的操作数无效

我们正在为课堂上的项目进行线性回归.我必须写一个函数.我已经尝试过静态转换和其他将"int n"更改为double的方法,因此它不会抛出错误?还是我完全错误的思路?

功能

void linear_regression(double x[], double y[], int n,
                   double *slope, double *y_int)
{    
    double sum_x, sum_y, sum_x_Squared, sum_Squared_x, product_x_y;
    double m = *slope, b = *y_int;

    sum_x = sum_array(x, n);
    sum_y = sum_array(y, n);

    sum_Squared_x = sum_square_array(x, n);
    sum_x_Squared = sum_array(x, n) * sum_array(x, n);

    product_x_y = sum_product_of_arrays(x, y, n);

    //I'm getting an error on the next statement, about the n
    m = ((sum_x * sum_y) - (n * sum_product_of_arrays)) /
            ((sum_x_Squared) - (n * sum_Squared_x));
    b = …
Run Code Online (Sandbox Code Playgroud)

c++ binary types operands operator-keyword

0
推荐指数
1
解决办法
1348
查看次数

NASM称"操作码和操作数的无效组合"

我刚开始学习汇编编程.我在linux上使用NASM.我写了这段代码,基本上是为了计算某事物的某些功能而且我知道它可能不是很好,但我真的不在乎这一点,我想要的只是一些想法为什么我一直得到那个错误,因为我我试图修改和切换操作数和操作以及问题部分中的所有内容,但是如果有的话只给了我更多的错误消息.就像我说的那样,我真的,对这整个事情都很陌生,我可能只是愚蠢.问题必须在其中一行中.如果你需要它,我当然会发布更多的代码,我只是不希望你不得不去70-80行奇怪的,不必要的复杂代码.我只是想知道这可能是什么原因导致这种情况发生,因为我现在非常,非常绝望,而且我已经达到了考虑它并且没有任何新想法只会让一切变得更糟的程度.我将把这部分留在这里.但我会给你任何你需要知道的帮助.

    mov dword [power], 2
    mov ecx, 0

while:
    mov eax, [neededforloop]
    cmp eax, ecx
    je endwhile

    mov eax, [power]
    mul eax, 2
    mov [power], eax

    mov eax, ecx
    add eax, 1
    mov ecx, eax

    jmp while
Run Code Online (Sandbox Code Playgroud)

assembly nasm opcode operands

0
推荐指数
1
解决办法
3016
查看次数

"在这种背景下,+不能拥有这样的操作数." 错误(VHDL代码)

  • 在这种情况下不能有这样的操作数

有人能告诉我出了什么问题以及如何解决它吗?

我试图在互联网上搜索问题,为什么我不能添加到STD_LOGIC_VECTOR,我没有找到任何解释我的问题的东西.所以我在这里问你们这是什么问题?

entity Modes is
    Port ( RST : in  STD_LOGIC;
           CLK_33MHZ : in  STD_LOGIC;
           BTN : in  STD_LOGIC;
           LED : out  STD_LOGIC);
end Modes;

architecture Behavioral of Modes is

 signal ledstatus : STD_LOGIC;
 signal mode : STD_LOGIC_VECTOR(1 downto 0);
 signal modestatus : STD_LOGIC_VECTOR (1 downto 0);

begin 

 process(CLK_33MHZ,RST)

 variable cnt : integer range 0 to 33000000;

begin

 if(RST = '1') then
    cnt := 0;
    mode <= "00";
    LED <= '0';
    ledstatus <= '0';
     elsif(rising_edge(CLK_33MHZ)) then
        if(BTN …
Run Code Online (Sandbox Code Playgroud)

add vhdl operands

0
推荐指数
1
解决办法
7524
查看次数

在C++中重载+ =运算符 - 如何传递左操作数?

我需要创建一个接受双'参数'的运算符.

myClass myobject();

double mydouble = 10000;

mydouble += myobject;
Run Code Online (Sandbox Code Playgroud)

我的运营商:

double operator+=(double value, const myclass& object)
{
    value += object.value;           
    return  value;
}
Run Code Online (Sandbox Code Playgroud)

即使mydouble初始化为10000,参数值也会传递给operator + = 0.

如何创建一个可以接受左操作数作为参数的运算符?

c++ parameters operator-overloading operands

0
推荐指数
1
解决办法
120
查看次数

Obj-c表达式错误 - 二进制表达式的操作数无效('CGFloat'(又名'double'))

我已经回顾了相同类型的问题而不是堆栈溢出,但这是不同的.这里我想用整数模数加倍值.编译器给出了以下错误.

我需要获得scrollview内容偏移的模数值.为此,我写了下面的代码,但它给了我错误'二进制表达式的无效操作数('CGFloat'(又名'双'))'.任何人请帮忙.

scrollView.contentOffset.x % 1024.00;
Run Code Online (Sandbox Code Playgroud)

提前致谢.

expression objective-c operands ios

0
推荐指数
1
解决办法
1697
查看次数

二元运算符 + 的错误操作数类型

我需要一个最多 20 位的数字,并且我正在使用 bigint。它在下面的行给了我这个错误(二元运算符 + 的操作数类型错误)。

BigInteger t = new BigInteger(my_number.getText().toString());
                my_number.setText(String.valueOf(t+1));
Run Code Online (Sandbox Code Playgroud)

java operands

0
推荐指数
1
解决办法
3779
查看次数

"int i = 0"中的操作数

我想问一下这个简短的代码:

int i = 0;
Run Code Online (Sandbox Code Playgroud)

有1个操作数还是2个?这i是一个操作数,但0也是?根据维基百科,0不应该(或者我可能误解).如果0不是操作数,它是常量还是什么?如果重要,则代码在C99中.

c operands

0
推荐指数
1
解决办法
110
查看次数