10

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

localPtr->wNodePtr->spin := PTW32_TRUE;

What is this line doing?

moodymudskipper
  • 46,417
  • 11
  • 121
  • 167
none7
  • 103
  • 1
  • 5
  • I did some some searching on the web, and the best i could determine is that this is just another way to perform assignment, ie (x = 5). The way of assigning things with x := 5 is used in some other languages. – AndrewGrant Jul 01 '15 at 08:05
  • You can use debugger and check behavior, it is not standard in C. – ST3 Jul 01 '15 at 08:11
  • Reference: https://github.com/BrianGladman/pthreads/blob/master/ptw32_OLL_lock.c#L578 That is extremely odd and probably a typo... Edit: Or not, seems to be used in more than 1 place. C++ operator perhaps? Is that even possible? – leppie Jul 01 '15 at 08:14
  • This stackexchange question may help you >> http://programmers.stackexchange.com/questions/101716/in-pseudo-code-what-does-mean – K.H.A.J.A.S Jul 01 '15 at 08:19
  • 2
    But does the code compile? – edmz Jul 01 '15 at 08:24
  • 2
    The file in question doesn't seem to get compiled when you build the project, there's no mention of it anywhere. So my guess is that it's work in progress, containing a typo. – molbdnilo Jul 01 '15 at 08:59

4 Answers4

5

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.

alk
  • 69,737
  • 10
  • 105
  • 255
4

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]

Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261
2

:= 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.

AndrewGrant
  • 786
  • 7
  • 17
  • Algol68 also has other similar operators such as: +:= (for adding to or appending to a string), +=: (for prefixing to a string), also -:=, *:=, /:=, %:=(int division) and %*:=(mod); Also non-operators like :=:=(juggle) and =:= (swap) and :=: (pointer comparison) ... cf. [Dyadic operators with associated priorities](https://en.wikipedia.org/wiki/ALGOL_68#Dyadic_operators_with_associated_priorities) – NevilleDNZ Jul 03 '15 at 23:38
0

":=" is assignment to variable in Pascal syntax, while equality test is "="