3

I was looking llvm clang's implementation of the C++ standard library...
In file mutex.cpp I found the following code:

void
mutex::unlock() _NOEXCEPT
{
    int ec = pthread_mutex_unlock(&__m_);
    (void)ec;                              // What??, Why??? O.o
    assert(ec == 0);
}

I don't understand what that expression is doing and why...
I need some explanation.

Sam
  • 1,722
  • 3
  • 18
  • 32

1 Answers1

4

I think that this expression is used that to avoid a compiler warning that the variable was declared but was not used.

As user2864740 pointed out the assert statement in this code can be a mcaro that in some conditions does not use the variable. That is it can be expanded to an empty statement.

Vlad from Moscow
  • 224,104
  • 15
  • 141
  • 268