You are using the comma operator without realizing it:
( ... "in pool not enough memory",5)
^
since the comma operator will evaluate its left operand and discard the result and then evaluate and return the right operand, you end up with:
printf( 5 ) ;
which will attempt to convert an int
to a const char *restrict
for the format string, which will almost surely not point to valid memory. Without the ()
, the ,
would have just been a separator for the function arguments.
The ()
is an expression in this context; if we look at the C99 draft standard section 6.5.1
Primary expressions, we have:
( expression )
therefore the ,
is treated as an operator while we can see from section 6.5.2
Postfix operators:
postfix-expression ( argument-expression-listopt )
argument-expression-list:
assignment-expression
argument-expression-list , assignment-expression
^
The ,
is just a separator in a function call.
Having warnings enabled should have helped here, gcc
gives me a few warnings for this program:
warning: left-hand operand of comma expression has no effect [-Wunused-value]
and
warning: passing argument 1 of 'printf' makes pointer from integer without a cast [enabled by default]
note: expected 'const char * restrict' but argument is of type 'int'