• The Old New Thing

    Why does my hard drive light flash every few second?

    • 22 Comments

    Back in Windows 95, people would notice that their hard drive light would blink every few seconds. What's that all about?

    Actually, it wasn't the hard drive light after all.

    Windows 95 was polling your CD-ROM drive to see whether you had inserted a new CD. Some computers wired up the "hard drive light" not to the hard drive but rather to the SCSI and/or IDE bus. So the light didn't indicate hard drive activity necessarily. It turned on for any bus activity.

    Fortunately, motherboard manufacturers discovered their mistake and nowadays you don't find any of them that miswire the hard drive access light.

    Or do you? I keep my computer under my desk so I never see the hard drive light anyway. I'm just surmising that in the past seven years, motherboard manufacturers have gotten their act together.

  • The Old New Thing

    Today is Swedish tax day

    • 16 Comments

    Of course, in Sweden, every day is tax day.

    By now, it's too late to fill out your tax form, which the Swedish tax agency permits you to file on paper, via Internet, over the phone, or even via SMS.

    They even have what I wish the US tax agency had: An online tax form calculator.

  • The Old New Thing

    You wanted Extreme Crochet?

    • 3 Comments

    Keith Moore thought I was writing about Extreme Crochet in my previous post about Extreme Croquet.

    No, Keith, if I had wanted to write about Extreme Crochet, I would have used this link.

  • The Old New Thing

    Extreme croquet

    • 7 Comments

    This week, Only a Game covered the sport of Extreme Croquet.

    Still doesn't hold a candle to Extreme Ironing, though.

  • The Old New Thing

    Using the echo command to remember what you were doing.

    • 43 Comments

    Sometimes you'll start typing a complex command line and then realize that you can't execute it now. Perhaps you're in the wrong directory or you forgot to map the drive. It would be a shame to hit ESC and lose that command line.

    What I do is edit the line to insert the word "echo" in front, then hit Enter. (Note: This doesn't work if you have command line redirection.)

    This prints the command to the screen, where it can be cut/pasted later. Even more, it enters the line into the command history, so a few uparrows will bring it back.

  • The Old New Thing

    $501 for 510g of peanut butter

    • 8 Comments

    You can buy 510 grams of peanut butter for only $501.

    Of course, this is special peanut butter. It must be kept at -20°C. And it is not intended for human consumption.

    This is peanut butter from the National Institute of Standards and Technology intended for use by food analysis laboratories to calibrate their equipment. For example, standard peanut butter consists of 10.4% ± 0.2% saturated fat.

    (Link courtesy of Slate.)

  • The Old New Thing

    What is __purecall?

    • 39 Comments

    Both C++ and C# have the concept of virtual functions. These are functions which always invoke the most heavily derived implementation, even if called from a pointer to the base class. However, the two languages differ on the semantics of virtual functions during object construction and destruction.

    C# objects exist as their final type before construction begins, whereas C++ objects change type during the construction process.

    Here's an example:

    class Base {
    public:
      Base() { f(); }
      virtual void f() { cout << 1; }
      void g() { f(); }
    };
    
    class Derived : public Base {
    public:
      Derived() { f(); }
      virtual void f() { cout << 2; }
    };
    

    When a Derived object is constructed, the object starts as a Base, then the Base::Base constructor is executed. Since the object is still a Base, the call to f() invokes Base::f and not Derived::f. After the Base::Base constructor completes, the object then becomes a Derived and the Derived::Derived constructor is run. This time, the call to f() invokes Derived::f.

    In other words, constructing a Derived object prints "12".

    Similar remarks apply to the destructor. The object is destructed in pieces, and a call to a virtual function invokes the function corresponding to the stage of destruction currently in progress.

    This is why some coding guidelines recommend against calling virtual functions from a constructor or destructor. Depending on what stage of construction/destruction is taking place, the same call to f() can have different effects. For example, the function Base::g() above will call Base::f if called from the Base::Base constructor or destructor, but will call Derived::f if called after the object has been constructed and before it is destructed.

    On the other hand, if this sample were written (with suitable syntactic changes) in C#, the output would be "22" because a C# object is created as its final type. Both calls to f() invoke Derived::f, since the object is always a Derived. Notice that means a method can be invoked on an object before its constructor has run. Something to bear in mind.

    Sometimes your C++ program may crash with the error "R6025 - pure virtual function call". This message comes from a function called __purecall. What does it mean?

    C++ and C# both have the concept of a "pure virtual function" (which C# calls "abstract"). This is a method which is declared by the base class, but for which no implementation is provided. In C++ the syntax for this is "=0":

    class Base {
    public:
      Base() { f(); }
      virtual void f() = 0;
    };
    

    If you attempt to create a Derived object, the base class will attempt to call Base::f, which does not exist since it is a pure virtual function. When this happens, the "pure virtual function call" error is raised and the program is terminated.

    Of course, the mistake is rarely as obvious as this. Typically, the call to the pure virtual function occurs deep inside the call stack of the constructor.

    This raises the side issue of the "novtable" optimization. As we noted above, the identity of the object changes during construction. This change of identity is performed by swapping the vtables around during construction. If you have a base class that is never instantiated directly but always via a derived class, and if you have followed the rules against calling virtual methods during construction, then you can use the novtable optimization to get rid of the vtable swapping during construction of the base class.

    If you use this optimization, then calling virtual methods during the base class's constructor or destructor will result in undefined behavior. It's a nice optimization, but it's your own responsibility to make sure you conform to its requirements.

    Sidebar: Why does C# not do type morphing during construction? One reason is that it would result in the possibility, given two objects A and B, that typeof(A) == typeof(B) yet sizeof(A) != sizeof(B). This would happen if A were a fully constructed object and B were a partially-constructed object on its way to becoming a derived object.

    Why is this so bad? Because the garbage collector is really keen on knowing the size of each object so it can know how much memory to free. It does this by checking the object's type. If an object's type did not completely determine its size, this would result in the garbage collector having to do extra work to figure out exactly how big the object is, which means extra code in the constructor and destructor, as well as space in the object, to keep track of which stage of construction/destruction is currently in progress. And all this for something most coding guidelines recommend against anyway.

  • The Old New Thing

    What, going to Sweden *again*?

    • 10 Comments

    It appears that I will have an opportunity to visit Sweden during the first week of June. I'll have three days in Uppsala and three days in Lund, with a travel day in between. Now, I've already spent a week and a half in Uppsala, so perhaps I could spend the Uppsala days taking a ferry to Helsinki and back. (And I could visit Denmark from Lund...)

    My Swedish won't be any better (well, okay, I learned a little more about formation of past participles, not like that counts for much), but I still enjoy trying. The hard part is finding someone patient enough to put up with all my fumbling and not switch to English out of frustration.

    (In Finland and Denmark, I'm just going to start in English with German as a fallback. Sorry, guys.)

    The question facing me now is whether I should go. It hasn't even been a month since my previous trip, and if the Finland thing doesn't come together, I'll be spending half my time in a city I've already visited. Hm...

  • The Old New Thing

    Why doesn't C# have "const"?

    • 45 Comments

    I was going to write about why C# doesn't have "const", but Stan Lippman already discussed this in A Question of Const, so now I don't have to.

    (And another example of synchronicity: After I wrote up this item and tossed it into the queue, Eric Gunnerson took up the topic as well.

  • The Old New Thing

    Nobody said it was a democracy

    • 10 Comments

    It's proxy season, which means I've been reading through proxy statement after proxy statement.

    The proxy voting rules for Allstate aren't very democratic. Scroll down to "How votes are counted and discretionary voting authority":

    The thirteen nominees who receive the most votes will be elected to the open directorships even if they get less than a majority of the votes.

    Okay, let's see, how many nominees are there? Oh, exactly thirteen.

    How convenient.

    In other words: These thirteen people will be elected to directorships regardless of what you do.

    So of course I voted against all of them.

    Later, I realized that I had fallen into their trap.

    You see, the only way I could stop these people from becoming directors was to withhold my vote and attempt to hinder a quorum. Under these rules, a "no" vote is as good as a "yes" vote!

    Allstate isn't the only company to rig their elections. Baxter and Wyeth (can't find proxy online) have similarly sham elections.

Page 404 of 439 (4,383 items) «402403404405406»