Function to generate descriptive errors (line number, function name, etc).
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 void __err_print(char *file, char *function, int line, char *date, char *version, int opt, int opt_size, char *txt, ...)
21 {
22 va_list argp;
23
24 puts("** ERROR! **");
25 printf("File: \t %s\n",file);
26 printf("Function: \t %s\n",function);
27 printf("Line: \t %d\n",line);
28 printf("Compilation date: \t %s\n",date);
29 printf("Compilator version: \t %s\n",version);
30 printf("Optimization: \t %s\n",opt==1 ? "Yes" : "No");
31 printf("Size optimization: \t %s\n",opt_size==1 ? "Yes" : "No");
32
33 if (txt == NULL)
34 return;
35 puts("Description:\n>>>");
36 va_start(argp, txt);
37 vprintf(txt, argp);
38 va_end(argp);
39 puts("\n<<<");
40 }
41
42 void other_function() {
43 err_print("other %s (%d+%d=%d)", "description",2,2,5);
44 }
45
46 int main() {
47 err_print("test %d", 2);
48 puts("");
49 other_function();
50 return 0;
51 }