For the currently existing test framework I need to pass (during the first-most call) to the function a line number of a fragment inside of that function. Something like this:
#include <stdio.h>
void func(int line_num)
{
#define LINE_NUM (__LINE__ + 1)
if(line_num == __LINE__) // Check the passed arg against the current line.
printf("OK");
else
printf("FAIL");
}
int main(void)
{
func(LINE_NUM); // Pass to the func the line number inside of that func.
return 0;
}
(this is a minimalistic version of a more complex functionality).
As is the sample code prints "FAIL".
If I pass an absolute value 5, e.g. func(5) then it prints "OK". I don't like the absolute value 5 because if I add one more line in front of the func definition then the absolute value will need a correction.
Instead of #define LINE_NUM (__LINE__ + 1) I also tried the following:
1.
#define VALUE_OF(x) x
#define LINE_NUM (VALUE_OF(__LINE__) + 1)
2.
#define VAL(a,x) a##x
#define LOG_LINE() ( VAL( /*Nothing*/,__LINE__) + 1)
3.
#define VALUE_OF2(x) x
#define VALUE_OF(x) VALUE_OF2(x)
#define LINE_NUM (VALUE_OF(__LINE__) + 1)
I'm using:
gcc --version
gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
In my sample code the value that func() gets is 14 (the call site line number + 1).