<< prev | home | next >>

WCRT is a small C runtime library for Visual C++, which implements parts of its functionality through calls to the Win32API. It is meant as a replacement for the Visual C runtime library (libc.lib).

The main purpose of this library is to allow the creation of small statically linked executables from regular C source files.

As an example, consider the following simple program:

   #include <stdio.h>

   int main()
       printf("Hello World!");
       return 0;

Compiling with Visual C++ 7.1 using cl /O1 hello.c (optimize for size) results in an executable of 36.864 bytes.

The same source file, compiled using WCRT, is only 3.072 bytes. If we apply a little further magic, and merge the data and code sections, it ends up at 2.048 bytes.

Of course this reduction in size comes at a price:

  • some standard C functions are missing
  • functions are optimised for size, not for speed
  • no buffering of I/O
  • limitations on some functions (e.g. *printf and atexit)
  • limited unicode and wide character support
  • no floating point emulation library
  • some functions are not thread-safe
  • the math functions are basic implementations

It is possible to get even smaller executables by using the Win32API directly without any C runtime (by supplying your own entry function), or writing in assembler. But I think WCRT offers a nice way to retain a lot of the power of the C runtime library without bloating small programs unnecessarily.

Using msvcrt.dll will also give you a small file because it shifts the code from your executable to a dynamic link library. However the startup code with the extra memory it uses still has to be executed when the dll is mapped into memory.

Yes .. I admit .. it's a geek toy ;-)

Valid XHTML 1.0!  Made with Cascading Style Sheets!  Valid CSS!
Copyright © 2004 by Jørgen Ibsen. All Rights Reserved. Products and company names mentioned may be the trademarks of their respective owners.