J
jeff_j_dunlap
Dear C++ Users:
I alwasy use std::string and avoid char buffers but last night I
wanted to see if I could make a C style function that would be thread
safe.
For me, it was a good learning experience since my C/C++ knowledge is
limited but I do understand threading issues due to prior Delphi
experience.
In the following function, pleas assume that the Date object is well
written. What I really want to know is if my char buff is being
handled safely.
void fbDateToStr( const IBPP:ate &d, char *buff )
{
if ( d < IBPP::MinDate || d > IBPP::MaxDate )
{
strcpy(buff, "");
}
else
{
int iMonth=0, iDay=0, iYear=0;
d.GetDate(iYear, iMonth, iDay);
sprintf(buff, "%d/%d/%d", iMonth, iDay, iYear);
}
}
USAGE:
char buffer[15];
fbDateToStr(dtInitialContactDt, buffer);
RETURNS:
MM/DD/YYYY or if date is invalid, a blank string
NOTES:
Initially, I thought of creating a static buffer within the function
instead of passing a buffer as this function currently is doing, but
doing so would have been thread-unsafe since the buffer would now be
visible/editable by all threads.
I alwasy use std::string and avoid char buffers but last night I
wanted to see if I could make a C style function that would be thread
safe.
For me, it was a good learning experience since my C/C++ knowledge is
limited but I do understand threading issues due to prior Delphi
experience.
In the following function, pleas assume that the Date object is well
written. What I really want to know is if my char buff is being
handled safely.
void fbDateToStr( const IBPP:ate &d, char *buff )
{
if ( d < IBPP::MinDate || d > IBPP::MaxDate )
{
strcpy(buff, "");
}
else
{
int iMonth=0, iDay=0, iYear=0;
d.GetDate(iYear, iMonth, iDay);
sprintf(buff, "%d/%d/%d", iMonth, iDay, iYear);
}
}
USAGE:
char buffer[15];
fbDateToStr(dtInitialContactDt, buffer);
RETURNS:
MM/DD/YYYY or if date is invalid, a blank string
NOTES:
Initially, I thought of creating a static buffer within the function
instead of passing a buffer as this function currently is doing, but
doing so would have been thread-unsafe since the buffer would now be
visible/editable by all threads.