The preprocessor in Microsoft VisualStudio 2003 (VC++ 7.1) does not support variable argument lists in macros; instead it spews syntax errors when compiling. However, there is a way to get around this limitation and indeed gain this ability.
In a project I'm working on, we use macros to construct portions of our logging system. A typical declaration looks as such:#define LOG_TRACE(...) log_routine(__FILE__, __LINE__, __VA_ARGS__)
However this fails to compile on VisualStudio.Net 2003, because as stated before, its preprocessor does not support variable argument lists.
A workaround is to instead use a class to handle the semantics of the variable argument list; observe:class tracing_output_va
{
private:
const char* m_file;
int m_line;
public:
tracing_output_va(
const char* p_File,
const int p_Line) :
m_file( p_File ),
m_line( p_Line )
{
}
void operator()( const char* p_Format, ... )
{
va_list marker ;
va_start( marker, p_Format ) ;
LoggingOutVa(
m_file,
m_line,
p_Format,
marker ) ;
va_end( marker );
}
};
And then redefine the macro as such:#define LOG_TRACE_APPLIB (tracing_output_va(__FILE__, __LINE__) )
This will indeed compile and perform as expected in VC++ 7.1
The elegance to this solution is that one need only modify the declaration of this macro, and that existing calls to this macro need not change.
For what it's worth the routine LoggingOutVa( ) wraps the actual magic of formatting and file output.
Cite: http://www.codeproject.com/KB/debug/location_trace.aspx
Tuesday, May 20, 2008
Macros and Variable Arguments in VisualStudio 2003
Thursday, May 15, 2008
VMWare Fusion -- No Hard Links in Shared Folders
VMWare Fusion allows one to use folders on the OSX filesystem from within the guest OS via Shared Folders.
This is useful if you need to access files from both the host OS (OSX) or the guest OS running in VMWare Fusion.
However I have found limitations with this arrangement when the guest OS is a Linux-based system -- it seems that VMWare's driver for Shared Folders does not support all of the linux filesystem operations (most specifically hard links).
Observe (/mnt/hgfs/wa points to a shared folder residing on the OSX filesystem) :
clermontr@synergy:/mnt/hgfs/wa/test$ touch tree
clermontr@synergy:/mnt/hgfs/wa/test$ ln tree shrub
ln: creating hard link `shrub' to `tree': Operation not permitted
Operation not permitted?! How about symbolic links:
clermontr@synergy:/mnt/hgfs/wa/test$ ln -s tree shrub
clermontr@synergy:/mnt/hgfs/wa/test$ ll
total 1
lrwxr-xr-x 1 clermontr ccm_root 4 2008-05-15 14:17 shrub -> tree
-rw-r--r-- 1 clermontr ccm_root 0 2008-05-15 14:16 tree
clermontr@synergy:/mnt/hgfs/wa/test$
Well it looks like symbolic links are permitted, but no chance for hard links. For what it's worth I also attempted to hard-link as sudo but to no avail.
Switching to the OSX filesystem I was able to create hard-links without issue. So then it would appear that this is indeed a limitation of the VMWare Fusion Shared Folders driver (vmhgfs).
I am interested in hearing if others have experienced this issue, and also if anyone has found a workaround.
Friday, March 14, 2008
Compiling MySQL 5 in Ubuntu
If when compiling MySQL5 you get an error similar to the following:
sed: can't read y.tab.c: No such file or directory
make[2]: *** [sql_yacc.cc] Error 2Then you're probably missing the bison package.
To remedy, first install bison:
sudo apt-get install bisonThen start the mysql build again with a fresh start:
make distclean; ./configure; make
Your troubles should be over.
Subscribe to:
Posts (Atom)