Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,890 questions

51,821 answers

573 users

How to create a function call logging in C

1 Answer

0 votes
#include <stdio.h> 
 
int funcAdd(int a, int b) { 
    return a + b; 
}
 
void logging(const char* file, const char* function, const int line, const char* args) {
    printf("file:%s line: %i function: %s args: %s\n", file, line, function, args);
}
 
#define funcAdd(...) \
    (logging(__FILE__, __FUNCTION__, __LINE__, "" #__VA_ARGS__), funcAdd(__VA_ARGS__))
 
 
void funcA(void) {
    funcAdd(3, 7);
}
 
void funcB(void) {
    funcAdd(33, 876);
}
 
 
int main(void){
    funcAdd(2, 9);
 
    funcAdd(1, 88);
 
    int result = funcAdd(41, 90);
     
    printf("result = %d\n", result);
 
    funcA();
     
    funcB();
} 
 
     
     
/*
run:
     
file:main.c line: 25 function: main args: 2, 9
file:main.c line: 27 function: main args: 1, 88
file:main.c line: 29 function: main args: 41, 90
result = 131
file:main.c line: 16 function: funcA args: 3, 7
file:main.c line: 20 function: funcB args: 33, 876
    
*/

 



answered Apr 5, 2024 by avibootz
edited Apr 5, 2024 by avibootz

Related questions

1 answer 138 views
1 answer 89 views
1 answer 105 views
1 answer 108 views
1 answer 110 views
2 answers 256 views
256 views asked Aug 30, 2017 by avibootz
2 answers 233 views
...