P
Paul Shipley
Hi,
Does anyone know a way of converting the __LINE__ macro to a string at
compile time? The reason I ask it because I want to put some debug
information in to tell me if memory is not being allocated. For
example, this function will return the status of my system:
static char* get_status (void)
{
char* str_ptr;
str_ptr = mem_alloc( SIZE_OF_TEXT );
if( NULL == str_ptr )
{
str_ptr = "Out of memory in " __FILE__ " at " __LINE__ "\n";
}
else
{
str_ptr = /* blah blah blah... */
}
return( str_ptr);
}
Of course this code won't work, because __LINE__ is an integer, not a
string. Also, I can't resort to something like printf( "%u \n",
__LINE__ ) because in this case the output might not (and probably
won't) be going to stdout. Also, sprintf can't be used because there
is no memory available to sprintf to.
Any suggestions on how to convert __LINE__ to a string at compile time
will be most appreciated.
Thanks,
Paul.
Does anyone know a way of converting the __LINE__ macro to a string at
compile time? The reason I ask it because I want to put some debug
information in to tell me if memory is not being allocated. For
example, this function will return the status of my system:
static char* get_status (void)
{
char* str_ptr;
str_ptr = mem_alloc( SIZE_OF_TEXT );
if( NULL == str_ptr )
{
str_ptr = "Out of memory in " __FILE__ " at " __LINE__ "\n";
}
else
{
str_ptr = /* blah blah blah... */
}
return( str_ptr);
}
Of course this code won't work, because __LINE__ is an integer, not a
string. Also, I can't resort to something like printf( "%u \n",
__LINE__ ) because in this case the output might not (and probably
won't) be going to stdout. Also, sprintf can't be used because there
is no memory available to sprintf to.
Any suggestions on how to convert __LINE__ to a string at compile time
will be most appreciated.
Thanks,
Paul.