The Old New Thing

Using modular arithmetic to avoid timing overflow problems

In an earlier article, I presented a simple way of avoiding timing overflows which seemed to create a bit of confusion. The short version: Given a starting time start, an ending time end and an interval interval, the way to check whether the interval has elapsed is to use the expression . The naive expression suffers from integer overflow ...
Comments are closed.0 0
Code

Shocked (shocked!) that patronage exists in Chicago politics

NPR reported on a startling discovery in Chicago: That government jobs go not to those best qualified to perform them, but rather to those with the best connections. Who'd-a thunk it? Shocked by this discovery, the Daley administration vowed to end it. The City of Chicago's top lawyer Mara Georges told incredulous City Hall reporters ...

You can't simulate keyboard input with PostMessage

Some people attempt to simulate keyboard input to an application by posting keyboard input messages, but this is not reliable for many reasons. First of all, keyboard input is a more complicated matter than those who imprinted on the English keyboard realize. Languages with accent marks have dead keys, Far East languages have a variety of ...
Comments are closed.0 0
Code

When is x/2 different from x>>1?

Everyone "knows" that the following pairs of expressions are equivalent: Too bad they aren't. In the C language standard, there is no requirement that the internal representation of signed integers be two's complement. All the permissible representations agree for positive numbers, but negative numbers can have different representations. If...
Comments are closed.0 1
Code

Why does Add or Remove Programs show a large blank space?

Some people have noticed that certain programs cause the Add or Remove Programs control panel to create an enormous amount of blank space. What's going on? These are programs that have bad custom uninstall icon registrations. If you go to the registry key , you'll find a list of programs that have registered for appearing in the Add or ...

The effect of SetCursor lasts only until the next SetCursor

Of course the effect of the function for a thread lasts only until that thread changes the cursor to something else. Any moron knows that, right? The tricky part is that the may come from an unexpected place. THe most common place people run into this is when they do something like this: This puts up the hourglass during the ...
Comments are closed.0 0
Code

Understanding ternary raster operations

It's perfectly logical, which doesn't mean that it's easy to understand. A ternary raster operation describes how three boolean values should combine to form an output boolean. I was going to write up a description but found that the existing documentation pretty much covers it, so I refer you to that. In particular, look at the table that ...
Comments are closed.0 0
Code

Boil first, then mash

Last year, British schoolchildren (ages six and seven) went to a farm and were baffled by the long, pointy, orange things. (Those who specialize in plant biology have a special term for these strange objects: carrots.) Their older siblings don't seem to be faring much better. A three-year study revealed that modern Scottish schoolchildren ...

Why are DLLs unloaded in the "wrong" order?

When a program starts or when a DLL is loaded, the loader builds a dependency tree of all the DLLs referenced by that program/DLL, that DLL's dependents, and so on. It then determines the correct order in which to initialize those DLLs so that no DLL is initialized until after all the DLLs upon which it is dependent have been initialized. (Of...

I'd like to register my stolen car, please

On NPR's All Things Considered Robert Siegel reported on the curious status of legally stolen cars in Gaza. Gaza license plates can be red for official, green for taxis, and white for private vehicles. The lower the number on the red plates, the higher the position of the official. The number 30 designates a truck. All this is pretty ...