Float Point Number Rounding Error
Fool me twice, shame on me! But what if when one was fooled by different people, and occurred many years apart!
One of the algorithm library was found to be responsible for the some data inconsistency in a mission critical application I was responsible of. Although fixing the problem does not take anything more than converting the variables from "float" to "double", it cost me over a day to validate the new release and document the changes.
Last time when I was bitten by rounding error of float point number arithematic opetions, it was over four years ago. At the time, I was newly employed in Company V which is a very young company itself. I was asked to incorporate a newly developed algorithm library into an application. I worked dilligently for a day or two and handed in the product but quickly I was asked to look into the application to find out why the result seem to be incorrect. My suggestion that the error was very likely come from rounding error of the float point number arithematics encountered with skeptism but eventually proved to be right.
One of the algorithm library was found to be responsible for the some data inconsistency in a mission critical application I was responsible of. Although fixing the problem does not take anything more than converting the variables from "float" to "double", it cost me over a day to validate the new release and document the changes.
Last time when I was bitten by rounding error of float point number arithematic opetions, it was over four years ago. At the time, I was newly employed in Company V which is a very young company itself. I was asked to incorporate a newly developed algorithm library into an application. I worked dilligently for a day or two and handed in the product but quickly I was asked to look into the application to find out why the result seem to be incorrect. My suggestion that the error was very likely come from rounding error of the float point number arithematics encountered with skeptism but eventually proved to be right.
VTK Example - Sphere
In this article, the procedures to take to build and run a vtk example is shown in two development environments. The first is with an IDE and the second is with the use of source editor and command line tools.
Why Doesn't C# Have "const"?
So far, the most convincing reason I can find is that since CLI is designed as mixed language, compile time support of constness in C# will give programmer's a false sense of security whilst enforcing support of run time constness will break the existing VB code, or worse, will force many Mort programmers out of business.
The following is an inception (punctuations modified to better confirm to proper style) from Stan Lippman's writing about this issue:
The following is an inception (punctuations modified to better confirm to proper style) from Stan Lippman's writing about this issue:
[const] Casts are morally indefensible to many coding standards and project norms. They are often characterized as second-class citizens resorted to by programmers of dubious character, and can easily result in the greatest of managed sins: unverifiable code. And yet in order to make use of the Base Class Library, all const parameters must (the programmer has no choice) be cast away.A typical example of the need of gyrating towards the lowest common denomination.
Solutions to Common Build Errors in Visual Studio 8
The following link error may occur when a mix mode dll library was migrate from VC++7 to VC++8:
Solution: In "Release" build configuration, add "msvcmrt.lib" (or "msvcurt.lib" in the case of "/clr:pure") and "msvcrt.lib" (if not already added) to "Additional Dependecies" property under "Linker->Input" for the project. Also make sure "mscoree.lib" is also included. In "Debug" build configuration, add corresponding debug version libraries.
Stdafx.obj : error LNK2001: unresolved external symbol "?.cctor@@$$FYMXXZ" (?.cctor@@$$FYMXXZ)
AssemblyInfo.obj : error LNK2001: unresolved external symbol "?.cctor@@$$FYMXXZ" (?.cctor@@$$FYMXXZ)
AssemblyInfo.obj : error LNK2001: unresolved external symbol "?.cctor@@$$FYMXXZ" (?.cctor@@$$FYMXXZ)
[name].obj : error LNK2001: unresolved external symbol "?.cctor@@$$FYMXXZ" (?.cctor@@$$FYMXXZ)
[name].obj : error LNK2001: unresolved external symbol "?.cctor@@$$FYMXXZ" (?.cctor@@$$FYMXXZ)
AssemblyInfo.obj : error LNK2001: unresolved external symbol "?.cctor@@$$FYMXXZ" (?.cctor@@$$FYMXXZ)
AssemblyInfo.obj : error LNK2001: unresolved external symbol "?.cctor@@$$FYMXXZ" (?.cctor@@$$FYMXXZ)
[name].obj : error LNK2001: unresolved external symbol "?.cctor@@$$FYMXXZ" (?.cctor@@$$FYMXXZ)
[name].obj : error LNK2001: unresolved external symbol "?.cctor@@$$FYMXXZ" (?.cctor@@$$FYMXXZ)
Solution: In "Release" build configuration, add "msvcmrt.lib" (or "msvcurt.lib" in the case of "/clr:pure") and "msvcrt.lib" (if not already added) to "Additional Dependecies" property under "Linker->Input" for the project. Also make sure "mscoree.lib" is also included. In "Debug" build configuration, add corresponding debug version libraries.
Solutions to Common Build Errors in Visual Studio 7
Problem: A pair of the following errors in building a .NET library:
Solution: add msvcrt.lib (or msvcrtd.lib) to "Additional Dependecies" property under "Input" in "Linker".
[filename] error LNK2001: unresolved external symbol "void * __cdecl operator new(unsigned int)" (??2@$$FYAPAXI@Z)
[filename] error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" (??3@$$FYAXPAX@Z)
[filename] error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" (??3@$$FYAXPAX@Z)
Solution: add msvcrt.lib (or msvcrtd.lib) to "Additional Dependecies" property under "Input" in "Linker".
"spawn" and Command Line Argument
Suppose your task is to write an program that will act as a proxy to call another program and pass all command line argument to the target program. The following is an implementation of such a program.
crt_spawn.cpp:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <process.h>
int main(int argc, char* argv[])
{
if (argc < 2) {
fprintf(stderr, "Usage: crt_spawn ...");
return 0;
}
// split the name
char drive[_MAX_DRIVE];
char dir [_MAX_DIR ];
char fname[_MAX_FNAME];
char ext [_MAX_EXT ];
_splitpath(argv[0], drive, dir, fname, ext);
if ( strlen(argv[1])>strlen(fname) ) {
fprintf(stderr, "Please enter a file name "
"shorter than the name of this file.\n");
return 0;
}
char target[_MAX_PATH];
_makepath(target, drive, dir, argv[1], ext);
const char* args[1024];
if (argc > 1023)
argc = 1023;
args[argc] = 0; // terminate the array
while (--argc) {
args[argc] = argv[argc];
}
args[0] = target;
return _spawnv(_P_WAIT, target, args);
}
A target program for testing crt_spawn is implemented as:
#include <stdio.h>
int main(int argc, char* argv[])
{
for (int i=0; i<argc; ++i) {
printf("%02i %s\n", i+1, argv[i]);
}
return 0;
}
Question: If both programs are placed in a directory "C:\West Point", and invoke crt_spawn.exe with the following command:C:\>"C:\West Point\crt_spawn.exe" target /opt="C:\West Point";What will be the output?
Mystery Program
TAOCP Section 1.3.2 Excercise 8
01 * MYSTERY PROGRAM 02 BUF ORIG *+3000 03 1H ENT1 1 04 ENT2 0 05 LDX 4F 06 2H ENT3 0,1 07 3H STZ BUF,2 08 INC2 1 09 DEC3 1 10 J3P 3B 11 STX BUF,2 12 INC2 1 13 INC1 1 14 CMP1 =75= 15 JL 2B 16 ENN2 2400 17 OUT BUF+2400,2(18) 18 INC2 24 19 J2N *-2 20 HLT 21 4H ALF AAAAA 22 END 1B
Diagnosing the Mental State of a Software Enginner's Child
Probe:
It's bright outside!Child:
It's bright inside too. No need to use light. There's a switch. (pause) There's a switch. There's a switch... (endless loop)Probe:
Are you in an endless loop?Child:
Anp-loo-ploose has a switch. (memory corruption from buffer overflow) Anp-loos-loop has a switch. ... Andrewf-loop has switch. Not an end-lessloop, there's a switch. (self-healing)
Why Isn't std::auto_ptr as Widely Used as It Deserves?
The motivation of the creation of std::auto_ptr class template is to make memory management easier. It allows the an object created in heap memory to have a single ownership and the auto_ptr object that owns the heap object is responsible for deleting it. So instead of having to write:
class T;
void foo(void) {
T* p = new T;
// do something
delete p;
}
One can write:
void foo(void) {
std::auto_ptr<T> p = new T;
// do something
}
The concept sounds neat and at the first look does not seem to be hard to implement. In reality, it took the standard committee to make three revisions to make it almost safe to use. Still, tossing a piece of code to any junior programmer and it will likely turn a solution to a problem into a problem to a solution.Date Created, Date Modified, Date Accessed of Windows XP
For files, date modified is the last time the file is modified, pretty straight forward!
For folders, date modified is last time a file or a folder is created or removed just insider the folder. The modification date does not propegate to the parent folder. Evidently, this behaviour is consistent with the UNIX file system concept. In Unix, everything in the file system is file. A UNIX directory is a special kind of file that contains a list of entries that point to the files belongs to it. Thus when any entry is added or removed insider the folder, the folder is modified, but any modification of "files" pointed to by the entries in the folder does not modify the folder itself.
It seems that for a folder, the "Date Accessed" is always the "Date Modified".
For folders, date modified is last time a file or a folder is created or removed just insider the folder. The modification date does not propegate to the parent folder. Evidently, this behaviour is consistent with the UNIX file system concept. In Unix, everything in the file system is file. A UNIX directory is a special kind of file that contains a list of entries that point to the files belongs to it. Thus when any entry is added or removed insider the folder, the folder is modified, but any modification of "files" pointed to by the entries in the folder does not modify the folder itself.
It seems that for a folder, the "Date Accessed" is always the "Date Modified".
Virtual Labs - New Visual C++ .NET Tips and Tricks
The MSDN virtual labs is a series of guided, hands on practices for users to evaluate or to learn application development for Windows and the Web.
The stated objectives of the virtual lab, New Visual C++ .NET Tips and Tricks, is for the user to learn how to use the following new optimization and compiler feature of Visual C++:
Track down bugs using run-time error checking (/RTC1 option).
Enable whole-program optimizations (/GL option) for release builds and change the Inline Function Expansion setting to Any Suitable (/Ob2 option) for improved performance.
Detect buffer overruns using buffer security checks (/GS option).
While the first and the third objectives are readily demonstrated. The sample program does not seemed to demonstrate the second objective well.
The sample program used in this virtual lab displays a mandelbrot graph in a frame window as shown below:
Figure 1. The a screen shot of the sample application used in this virtual lab.

The stated objectives of the virtual lab, New Visual C++ .NET Tips and Tricks, is for the user to learn how to use the following new optimization and compiler feature of Visual C++:
Track down bugs using run-time error checking (/RTC1 option).
Enable whole-program optimizations (/GL option) for release builds and change the Inline Function Expansion setting to Any Suitable (/Ob2 option) for improved performance.
Detect buffer overruns using buffer security checks (/GS option).
While the first and the third objectives are readily demonstrated. The sample program does not seemed to demonstrate the second objective well.
The sample program used in this virtual lab displays a mandelbrot graph in a frame window as shown below:
Figure 1. The a screen shot of the sample application used in this virtual lab.



