July 9, 1999

Constraints on Pointer Arithmetic Past an Array’s End

In Standard C and C++, the address of the first element past the end of an array can be used in pointer arithmetic. Thus, you can initialize a vector with the contents of a built-in array, like this: int arr[3] = {1, 2, 3}; vector vi ( arr, //address of

What is a Side Effect?

The Standard defines a side effect as a change in the state of the execution environment. Modifying an object, accessing a volatile object, invoking a library I/O function, or calling a function that does any of these operations are all side effects.

Using “Sentry Bytes” to Detect Memory Overruns

One of the most frustrating aspects of debugging is detecting memory overruns. Some compilers (MS Visual C++ for instance) automatically add “sentry bytes” at the ends of every memory block allocated by operator new. The sentry bytes have a predefined value that the runtime system monitors. When the predefined value

Use the Conditional Operator Judiciously

The conditional operator,?, is a shorthand for a sequence of if-else statements. Although it has legitimate uses, in many cases programmers tend to misuse it, thereby producing unintelligible and buggy code. Sometimes, the use of the conditional operator yields undefined behavior. Consider this example: int n = 1; n =

Make Sure all Access QueryDef Objects are Closed

When you’re working with QueryDef (SQL instructions stored on an MDB database) and open it, DAO loads all the QueryDefs. For example, if you have an MDB with five QueryDefs named qryCustomers, qryOrders, qryContacts, qrySales, and qryPersons, and you want to use the qryCustomers, do this: Dim qdCustomer as QueryDefDim

Perform Some Common Database Chores

These several database functions work together and perform various utility functions, such as checking if fields and tables exist, creating fields and tables, and so on. The interface hides all the code and returns True or False to report the status of the functions: Function CreateDatabase(DatabasePath As String, dbLanguage _

Password Protect an Access Database

For simple Microsoft Access security, set the database password from the Security item under the Tools menu in Access, select Set Database Password, and enter a password. To use the database in VB, pass a value along with the “pwd” keyword to the SOURCE value of the OpenDatabase method: Dim

Generate Random Strings

This code helps test SQL functions or other string-manipulation routines so you can generate random strings. You can generate random-length strings with random characters and set ASCII bounds, both upper and lower: Public Function RandomString(iLowerBoundAscii As _ Integer, iUpperBoundAscii As Integer, _ lLowerBoundLength As Long, _ lUpperBoundLength As Long) As

No more posts to show