Click here to Skip to main content
15,891,633 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
#include <stdio.h>
typedef int BOOL;
#define FALSE 1
#define TRUE 1

#define CALL_FUN(_command, _expResult) CallFunction(__FILE__, __LINE__, #_command, _command, _expResult)

BOOL CallFunction(const char* pFile, int lineNr,  const char* pCommand, BOOL retVal, BOOL expResult)
{
    printf("%s[%d]:%s return %s expected %s \n",pFile, lineNr, pCommand, retVal?"TRUE":"FALSE", expResult?"TRUE":"FALSE");
    return retVal;
}


BOOL isEqual(int i, int j)
{
    return i == j;
}

int main(void)
{
    int left    = 10;
    int right   = 11;
    CALL_FUN(isEqual(left, right),TRUE);
    return 0;
}


Output : ../src/CreateFileProj.c[34]:isEqual(left, right) return FALSE expected TRUE

I want to print the above output like below. Please let me know how can I achieve that

Output : ../src/CreateFileProj.c[34]:isEqual(left=10, right=11) return FALSE expected TRUE

What I have tried:

I want to print function call along with parameter values . Please let me know how can I do it .

C#
Output : ../src/CreateFileProj.c[34]:isEqual(left, right) return FALSE expected TRUE 

I want to print the above output like below. Please let me know how can I achieve that 

Output : ../src/CreateFileProj.c[34]:isEqual(left=10, right=11) return FALSE expected TRUE 
Posted
Updated 7-Dec-16 22:51pm

1 solution

C++
#define CALL_FUN(_command, _expResult) CallFunction(__FILE__, __LINE__, #_command, _command, _expResult)

You are using the Stringizing Operator (#)[^] on _command so the macro result is:
C++
CallFunction(<filename>, <line_number>, "isEqual(left, right)", isEqual(left, right), TRUE)

So you do not get the values of left and right. I am not aware of any way for the compiler to substitute the values as you require. You would need to add them as extra parameters.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900