A
akarui.tomodachi
I have about twenty functions written in C.
Each time I call a function, it logs the status of the function
operation to a file. I use a central logging function which is called
from each function to report status into a log file. However, I am
using "sprintf" and formatting the log info into a string and sending
to my central logging routine myLogFunc().
Here is the skeleton code:
/*******************
void myFunc1()
{
char logString[100];
/* do some thing here.. */
....
....
sprintf(logString,"%s", "Hello World, everything is OK");
myLogFunc(logString);
....
}
********************/
Now question is that:
1) Should I declare the char array logString[] in every function as a
local variable ? or should I declare as a static global. I know that,
this array is local to each function and it would be disappear once the
function returns.
2) Could you please advice which one is better, local or global ?
Each time I call a function, it logs the status of the function
operation to a file. I use a central logging function which is called
from each function to report status into a log file. However, I am
using "sprintf" and formatting the log info into a string and sending
to my central logging routine myLogFunc().
Here is the skeleton code:
/*******************
void myFunc1()
{
char logString[100];
/* do some thing here.. */
....
....
sprintf(logString,"%s", "Hello World, everything is OK");
myLogFunc(logString);
....
}
********************/
Now question is that:
1) Should I declare the char array logString[] in every function as a
local variable ? or should I declare as a static global. I know that,
this array is local to each function and it would be disappear once the
function returns.
2) Could you please advice which one is better, local or global ?