October 10, 2000

Rethrowing a Throwable Exception in Your Code

Use the fillInStackTrace() method to rethrow a Throwable type of exceptional condition in your code. This is useful if you want to rethrow a exception that occurred while using a method or creating a Object but want to avoid the stack trace from these calls. The intention is to show

Using dynamic_cast Properly

Programmers who use dynamic_cast sometime discover that their applications suffer from mysterious crashes although seemingly, they are bug free. In most cases, the reason is that they forgot to turn on RTTI support when building the application. For RTTI to operate, the compiler must generate additional code and data in

Taking an Address of a Pointer

The sequence && is parsed as the logical AND operator. According to the Maximal Munch parsing principle, it’s never construed as two & (address of) operators: void func (char ** pp);char c;func (&&c); // parse error, && treated as logical AND If you want to pass the address of c’s

Escape Sequences

Certain special characters are represented as escape sequences. An escape sequence begins with a (backslash) followed by an alphanumeric character. For example, the escape sequence represents the newline character. Note that the two characters of an escape sequence are construed as a single character. Here’s a complete list of the

Invoking a Function Through a Pointer

When you call a function through a pointer to function, use that pointer as if it were the function itself, not a pointer. For example: #include char buff[10];void (*pf) (char *, const char *);pf = strcpy; // take address of strcpypf(buff, “hi”); // use pf as if it were the

Assigning an Integer Value to an Enumeration

C++ doesn’t allow you to assign integer value to an enumeration directly: enum Direction (Up, Down};Direction dir;Dir=0; // error, can’t assign int to enum type However, you can use static_cast to explicitly cast an int value to an enumeration. dir=static_cast < Direction > (0); // OK< dir equals 'Up' If

Servlet Variables

Question: If I declare one variable in a servlet class, and if I create many instances of that servlet, what will be the status of that variable? Answer: If the variable is not static, there will be separate instances of that variable in each servlet and the value of the

Free Store and Heap

Question: Is there any difference between heap and free store in C++? Answer: The free store is a region of memory from which a program allocates dynamic memory using new. In most cases, the free store is implemented as a heap. Therefore, each allocation request returns a memory address that

Random Number Generator

Question: Is there a way to capture the last value (digit) of the system clock number and use that to generate a random number? Or look at system clock–find last digit (in seconds)–make my variable equal to that digit? Answer: Use the time() function to get the system time. This

No more posts to show