What is a comma separated set of assignments?

I noticed in a routine

else 
  *pbuf++ = '%', *pbuf++ = to_hex(*pstr >> 4), *pbuf++ = to_hex(*pstr & 15);

Why does it work?

What does it do?

Answers


A comma operator is a sequence point : each comma separated expression are evaluated from left to right. The result has the type and value of the right operand. Functionally, your example is equivalent to (the much more readable ?) :

else
{
    *pbuf++ = '%';
    *pbuf++ = to_hex(*pstr >> 4);
    *pbuf++ = to_hex(*pstr & 15);
}

Here is another example that the standard provides for the comma operator (6.5.17) :

In the function call

f(a, (t=3, t+2), c)

the function has three arguments, the second of which has the value 5.


Need Your Help

How do i show the last 5 users who have visited a userpage?

php web mysqli

Im very new to php so i would appricate if someone could explain it simplified :D

Open Source licensing on libraries & DLL's

dll open-source licensing

Most of you know that the main purpose of Open Source libraries' licensing is to distribute the source code along with your application.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.