Is va_start (etc.) reentrant?

When editing for a class with a long history, I was driven into a dead end by the architect’s special habit of wrapping it in va_start → va_end in a mutex. The list of changes for this addition (which was made about 15 years ago and has not been revised since) noted that this was because va_start et. everything was not reentrant.

I was not aware of such problems with va_start, since I always thought it was just a macro for some math with a stack pointer. Is there something here that I don't know about? I do not want to change this code if there are side effects.

In particular, the function in question looks something like this:

void write(const char *format, ...)
{
    mutex.Lock();
    va_list args;
    va_start(args, format);
    _write(format, args);
    va_end(args);
    mutex.Unlock();
}

This is called from multiple threads.

+5
3

- (.. foo() va_start, foo() bar(), va_start), , - va_list . :

va_start, va_copy ap va_end ap.

, , va_list ( ap).

(, , , ), . C , . , "t21" , , , .

, va_list va_start, , " " va_start. va_list ( ), va_list.

, varargs. , write(), , , write() , write(), .

+5

, , C, , va_list . , va_start va_list va_start. , C va_start va_list "" va_start va_end.

A va_list "" : va_start...va_end. va_start va_list. va_start...va_end va_list .

P.S. , , , LIFO . va_start...va_end va_list ( ). C .

, C99 va_list va_copy. , va_start...va_end, , va_list.

P.P.S. , ... - ( va_list). va_list. , - . . va_... " ". va_list, , . , . , , va_list . .

+2

, va_list , all . , : _write? , , , (1) - , _write, (2) , _write, .

0

All Articles