简体   繁体   English

C function while(*a++ = *b++) with floats

[英]C function while(*a++ = *b++) with floats

I don't learn C and I have to tell what the function below do:我不学习 C,我必须告诉下面的 function 做什么:

x(a,b){
   float *a,*b;
   while(*a++ = *b++);
}

I know how does this funcion with instead of floats chars work but I don't get what should this do.我知道这个函数是如何使用而不是浮点字符工作的,但我不知道该怎么做。 Copy the value or address.复制值或地址。 If value why is it in while loop?如果值为什么在while循环中?

This is not even "valid" code (It would be basically valid, 20 years ago, when variables without type were assumed to be ints).这甚至不是“有效”代码(它基本上是有效的,20 年前,当没有类型的变量被假定为整数时)。

/*int*/ x(/*int*/a,/*int*/ b){
   float *a,*b;
   while(*a++ = *b++);
}

In the following, I will assume, that a and b are int* (At least in the parameters)在下文中,我将假设 a 和 b 是int* (至少在参数中)

This is undefined behavior.这是未定义的行为。 float *a,*b; shadows the variables, that were given to it.隐藏给它的变量。

These both float pointers are uninitialized (=They can have every value possible, an access will crash the program) In the while loop, you are incrementing uninitialized pointers.这两个浮点指针都未初始化(=它们可以具有每个可能的值,访问将使程序崩溃)在while循环中,您正在递增未初始化的指针。 This may lead to eg crashes.这可能导致例如崩溃。

This method is copying value for value, as long as *b is non-zero.只要*b不为零,此方法就是对值进行复制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM