[英]What does operator ':=' mean?
I am trying to compile pthreads for MSVC2015 and found some strange code. 我正在尝试为MSVC2015编译pthreads并发现一些奇怪的代码。
localPtr->wNodePtr->spin := PTW32_TRUE;
What is this line doing? 这条线在做什么?
As others pointed out :=
is not a valid C-operator. 正如其他人所指出的:=
不是有效的C运算符。
However, this "operator" :=
is found twice in the current " PThread for Windows " source release which seems to be as of v2.9.1 . 但是,这个“operator” :=
在当前的“ PThread for Windows ”源代码版本中被发现两次, 这似乎是v2.9.1的版本 。
Both occurencies appear in ptw32_OLL_lock.c
, which proclaims to " implements extended reader/writer queue-based locks ", but does not seem to be part of the pthread*.dll
build, so the file ptw32_OLL_lock.c
is not passed to the compiler. 两个出现的ptw32_OLL_lock.c
都出现在ptw32_OLL_lock.c
,它宣称“ 实现扩展的 ptw32_OLL_lock.c
/写器队列锁定 ”,但似乎不是pthread*.dll
构建的一部分,因此文件ptw32_OLL_lock.c
不会传递给编译器。
Interesting enough the source file in question contains an int main()
and is not in the test
sub-directory. 有趣的是,有问题的源文件包含一个int main()
,并且不在test
子目录中。
All in all this seems to be alpha, beta or it's simply noise, so just delete it. 总而言之,这似乎是alpha,beta或它只是噪音,所以只需删除它。
IIRC, C
standard does not specify anything about :=
operator. IIRC, C
标准没有具体说明:=
运算符。 So, most likely, it's not standard C
. 所以,很可能,它不是标准的C
However, AFAIK, some languages, which use the =
as comparison operator, to separate the assignment from comparison , use :=
as assignment operator. 但是,AFAIK,一些语言,使用=
作为比较运算符,将赋值与比较分开,使用:=
作为赋值运算符。 [Example: Pascal, postgresql] [示例:Pascal,postgresql]
In some other cases, it carries a meaning that the variable is getting defined and assigned in the same step, to differentiate with normal assignment elsewhere. 在某些其他情况下,它具有在同一步骤中定义和分配变量的含义,以区别于其他地方的正常分配。 [Example: GO] [例子:GO]
:= is not a valid operator in C. :=不是C中的有效运算符。
It does however have use in other languages, for example ALGOL 68. Basically, for what you want to know, the := in this example is used to assign the variable PTW32_TRUE to localPty->wNodeptr->spin 但它确实可以用于其他语言,例如ALGOL 68.基本上,对于你想知道的,在这个例子中使用:=用于将变量PTW32_TRUE赋值给localPty-> wNodeptr-> spin
This is done mostly to remove any ambiguity in code, as to avoid using '=' for assignment. 这主要是为了消除代码中的任何歧义,以避免使用'='进行赋值。
“:=”是在Pascal语法中赋值给变量,而等式测试是“=”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.