Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does operator ':=' mean?

I am trying to compile pthreads for MSVC2015 and found some strange code.

localPtr->wNodePtr->spin := PTW32_TRUE;

What is this line doing?

like image 533
none7 Avatar asked Jul 01 '15 07:07

none7


3 Answers

As others pointed out := is not a valid C-operator.

However, this "operator" := is found twice in the current "PThread for Windows" source release which seems to be as of 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.

Interesting enough the source file in question contains an int main() and is not in the testsub-directory.

All in all this seems to be alpha, beta or it's simply noise, so just delete it.

like image 192
alk Avatar answered Nov 20 '22 15:11

alk


IIRC, C standard does not specify anything about := operator. So, most likely, it's not standard C.

However, AFAIK, some languages, which use the = as comparison operator, to separate the assignment from comparison, use := as assignment operator. [Example: 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]

like image 27
Sourav Ghosh Avatar answered Nov 20 '22 15:11

Sourav Ghosh


:= is not a valid operator in 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

This is done mostly to remove any ambiguity in code, as to avoid using '=' for assignment.

like image 38
AndrewGrant Avatar answered Nov 20 '22 14:11

AndrewGrant