The following is a very interesting e-mail forward recently and sharing the same with you all.

A group of alumni, highly established in their careers got together to visit old university professor. Conversation soon turned into complaints about stress in work and life.

Offering his guest coffee, professor went to the kitchen and brought a large pot of coffee and assortment of cups- porcelain, plastic, glass, crystal. Some plain looking, some expensive and some exquisite, telling them to help themselves to hot coffee.

When all the student had a cup of coffee in hand professor said-
If you noticed, all the nice looking expensive cups were taken up leaving behind the plain and cheap ones.  It is normal for you to want only the best for yourself But that is the source of your problem and stress.

What all of you wanted was coffee, not the cup, but you consciously want for the best cup and were eyeing each other’s cup.

Now if life is coffee, than jobs, money and position in society are the cups. They are just tools to hold Life, but the quality of Life doesn’t change. Sometimes by concentrating only on the cup we fail to enjoy the coffee in it.

So don’t let the cups drive you….

Enjoy the coffee instead.

The zune bug mentioned in the previous post was caused by a missing break statement. There was an interesting incident which had happened on January 15th, 1990, caused by the insertion of a break statement at the wrong place in the, C code. I have read about this bug in the book “Expert C Programming – Deep C secrets – Peter Vander Linden“. The following is the excerpt from the book which explains it.

 This is a replica of the code that caused a major disruption of AT&T phone service throughout the U.S. AT&T’s network was in large part unusable for about nine hours starting on the afternoon of January 15, 1990. Telephone exchanges (or “switching systems” in phone jargon) are all computer systems these days, and this code was running on a model 4ESS Central Office Switching System. It demonstrates that it is too easy in C to overlook exactly which control constructs are affected by a “break” statement.

network code()
{
switch (line) {
    case THING1:
        doit1();
        break;
 case THING2:
         if (x == STUFF) {
            do_first_stuff();
            if (y == OTHER_STUFF)
                 break;
            do_later_stuff();
          } /* coder meant to break to here... */
          initialize_modes_pointer();
          break;
    default:
         processing();
    } /* ...but actually broke to here! */
   use_modes_pointer();/* leaving the modes_pointer
    uninitialized */
}

 This is a simplified version of the code, but the bug was real enough. The programmer wanted to break out of the “if” statement, forgetting that break” actually gets you out of the nearest enclosing iteration or switch statement. Here, it broke out of the switch, and executed the call to use_modes_pointer() —but the necessary initialization had not been done, causing a failure further on. This code eventually caused the first major network problem in AT&T’s 114-year history. The saga is described in greater detail on page 11 of the January 22, 1990 issue of Telephony magazine. The supposedly fail-safe design of the network signaling system actually spread the fault in a chain reaction, bringing down the entire long distance network.

And it all rested on a C switch statement!!!!.

The book “The Practice of Programming – Brian .W.Kernighan and Robert Pike“  is one the books, which has a profound influence on the way I  program/debug. One of the advice it provides is :

Know yourself, and the kind of errors you make.Once you have found and fixed a bug, make sure that you eliminate other bugs that might be similar. Think about what happened so you can avoid making that kind of mistake again.

The book provides the above advice in the context of an implementation of a very useful UNIX utility, strings. One of the  functions in that implementation had 3 erroneous calls to printf . Later, it was fixed in one place, but the other two calls were not fixed.

Now you might be wondering how is this related to the Zune bug. The original file containing the bug is available for public viewing.  The root cause for the bug is also explained in detail in  zuneboards.com forum. Upon a close observation of the file containing the bug, we can  notice that  there is a function MX31GetRealTime, which contains the similar code as in the buggy function, ConvertDays. But MX31GetRealTime has the correct version  with an extra break statement. 


year = ORIGINYEAR;
while (day > 365)
{
if (IsLeapYear(year))
{
numOfLeap++;
if (day > 366)
{
OALMSG(OAL_RTC&&OAL_INFO, (TEXT("Leap Year: %u"),year));
day -= 366;
year += 1;
OALMSG(OAL_RTC&&OAL_INFO, (TEXT(", Days left: %u\r\n"),day));
}
else
{
OALMSG(OAL_ERROR, (TEXT("ERROR calculate day\r\n")));
break;
}
}
else
{
OALMSG(OAL_RTC&&OAL_INFO, (TEXT("Not Leap Year: %u"),year));
day -= 365;
year += 1;
OALMSG(OAL_RTC&&OAL_INFO, (TEXT(", Days left: %u\r\n"),day));
}
}

Probably this bug wouldn’t have been there, if the above advice from the book had been followed!!!

In the next post, I will discuss about an (in)famous AT&T bug, which was caused by the inclusion of break statement (quite the opposite of this case :-) .

Testing how to use the syntax highlighter works.


#include <stdio.h>

int main()

{

printf(”Hello World!\n”);

return 0;

}

And finally I have started blogging on my website www.gowrikumar.com. For a long time, I was pondering whether I should blog or not. If so, how should I do it? I have made a few attempts earlier to blog, but those were mostly on blogspot or wordpress domains. Though I have been thinking about setting up a blog in my website, a few things hold me back. The questions I have had in my mind were:

  • What would I blog on?
  • How do I change the look and feel for the blog?
  • Is it possible to depict the C code in a beautiful manner with all syntax highlighting?
  • How to add adsense to the wordpress blog?
  • ….
  • ….

And a lot more questions like these. Thanks to Internet and the great user community for wordpress, I have been able to find the answers for most of them.

What to expect in this blog? Well, the least you can expect are answers to the C puzzles and the programming interview questions which are posted on my website :-)   And then nostalgic stuff of how I started my programming, how I learnt it, what am I doing currently etc…

Happy new year 2009 to all of you.

Have a terrific day!!!

Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!