Wednesday, April 29, 2009

VC debugger with better data display

As a programmer, I have come across several compilers and although I am not a MS's fan but perhaps VC is the best compiler I ever used.

Now, let us customize autoexp.dat to make a better data display. The file can be found under VS's debugger, eg.:

C:\Programme\Microsoft Visual Studio 8\Common7\Packages\Debugger\autoexp.dat

The tutorials can be found here:

- Customize autoexp.dat with own types in VS2005
- Writing custom visualizers for Visual Studio 2005, the best reference about customizing autoexp.dat I found so far.
- Visual C++ 2005 IDE Enhancements Part 5: Variable Display

"premature optimization is the root of all evil." Donald Knuth

Friday, April 17, 2009

Template Specialization and GCCE compiler

An interesting point about template specialization on Symbian.
GCCE does not follow §13.5.1 rule of C++ standard, the order of specializations.

Look at the follow code:

template< class T > class MyComplex { T i, j; };

template< class T > T MySqrt( T );
template< class T > MyComplex< T > MySqrt( MyComplex< T > );
double MySqrt( double );

template< class T > void MySimpleFoo ( T& );
template< class T > void MySimpleFoo ( const T& );

template< class T1, class T > void MyFoo2 ( T1 t1, T& );
template< class T1, class T > void MyFoo2 ( T1 t1, const T& );

// The problem is lying at the following 2 templates
template< class T1, class T > T1 MyFoo ( T& );
template< class T1, class T > T1 MyFoo ( const T& );

void f ( MyComplex< double > z )

int i = 0;
const int ci = 3;

MySqrt( 2 );
MySqrt( 2.0 );
MySqrt( z );

MySimpleFoo( 2 );
MySimpleFoo( i );
MySimpleFoo( ci );

char ch;

MyFoo2( ch, 2 );
MyFoo2( ch, i );
MyFoo2( ch, ci );

MyFoo2< char >( ch, 2 );
MyFoo2< char >( ch, i );
MyFoo2< char >( ch, ci ); // MyFoo2(..) does not alert the compiler
// for ambiguious. Now look at MyFoo(..)

MyFoo< char >( 2 );
MyFoo< char >( i );
MyFoo< char,int >( ci ); // This is ok.
// But the call below will not work

// MyFoo< char >( ci ); // doesn't work with Symbian GCCE
// the compiler will complain that the functions ambiguious,
// it cannot decide whether it should take MyFoo ( T& ) or
// MyFoo ( const T& )

"Trying to outsmart a compiler defeats much of the purpose of using one." Kernighan & Plauger, The Elements of Programming Style

Thursday, April 9, 2009

"We 're linux"

Genial & informative video clips organized by The Linux Foundation, get into the world of Linux developers around the glob.

"Be Linux"

Friday, April 3, 2009

Problem in wchar.h in Open C (Symbian)

The following errors encountered in OpenC:

/EPOC32/include/stdapis/wchar.h:92: error: `__mbstate_t' does not name a type
/EPOC32/include/stdapis/wchar.h:97: error: `__size_t' does not name a type

Googled and I found similar problem posted in ( but no relevant answer how to solve the problem. How I solved it is posted in comment#6.

"Computer science education cannot make anybody an expert programmer any more than studying brushes and pigment can make somebody an expert painter" Eric Raymond

Wednesday, April 1, 2009

find & grep command to search string (Cygwin version)

There are few limitations with Windows search, e.g.
-You cannot preview the search results.
-The regular expression in Windows is not unified with other regular expression formats. The Windows search for phase or word do not recognize the syntax like


Then, let's use grep to do the work. If you do not have cygwin, install it!
Now, I want to search for the places in .h files where it contains the text "typedef" at the start of the line and may follow with some other strings but must have "_mbstate_t".

$find ../ -iname \*.h -exec grep -B 3 -i "^typedef\(.*\)_mbstate_t" '{}' \; -print

Basically, find command needs the path and the file name you need to search.
Here, I tell the find to search the one directory upward for any files which have .h" or .H at the end of files. -iname option is for case-insensitive.
Remarkably, in Cygwin, you need to have the escape for * like \*.h but you don't need to do this on native *nix. The examples shown here are only tested under Cygwin.

Next, -exec option is to follow with a command where it takes the arguments from find and execute it. We want to grep any lines starting with "typedef" (^typedef) and follow with some string (.*) and _mbstate_t in any files which passed from find command.
"^typedef\(.*\)_mbstate_t" is normal regular expression for this job.
^typedef is to have typedef at the start of the line.
\(.*\)_mbstate_t is to match _mbstate_t which contains any strings or spaces before the search string. The backslash is the escape character to group (.*)
(For more information about regular expression, google regular expression)
-i is for case-insensitive.
-B 3 is to display 3 lines before the matching line.

If we want to search for both .cpp and .h files, we can group the search within (..) as well.

$find ../ \( -iname \*.h -o -iname \*.cpp \)

However, if you often need to repeat this search, you may put it into the shell script instead.

# File: - Simplify find & grep for source & header file
if [ $# -lt 2 ]
echo ""
echo "Usage: $0 [-i] search_path search_what"
echo "-i for non case-sensitive, default is case-sensitive"
exit 0

case "$1" in
find $1 \( -name \*.cpp -o -name \*.h \) -exec grep -i $2 "{}" \; -print
find $1 \( -name \*.cpp -o -name \*.h \) -exec grep $2 "{}" \; -print

exit 0

Beyond the example here, in my opinion find command is one of the most often used commands, therefore please don't forget to have a quick look at the find man page.

See also:

"The process of preparing programs for a digital computer is especially attractive, not only because it can be economically and scientifically rewarding, but also because it can be an aesthetic experience much like composing poetry or music." Donald E. Knuth