Writing portable code

25 07 2008

I just wanted to share a problem that I have come across today when I was at work. This post is about writing portable code. To give you an example, here is the problem that I have faced, look at this code snippet in C.

someBuf = (SomeType *) malloc(length);

if (someBuf)
{
someBuf->someVar = x;
}

In the above statement, there is no check to know the validity of the length. It occurred to me that the value of the length was “0″. The C standard (ISO/IEC 9899) says,

If the size of the space requested is zero, the behavior is implementation-defined:

Either a null pointer is returned
Or the behavior is as if the size were some nonzero value, except that the returned pointer shall not be used to access an object.

In my case, the malloc returned an address(zero sized buffer), the validation on the allotted buffer was successful because someBuf was not NULL  and eventually the program core dumped since the code followed the above statement accessed object (object of size zero?). So the point I would like to make here is, it’s better to write our own wrapper functions that would make the behavior consistent across different implementations.





ELCOT’s student laptop scheme

22 07 2008

I don’t really know how many of you are aware of this piece of information, that is ELCOT (Electronics Corporation of Tamil Nadu Limited) is giving out laptops for students studying in Tamil Nadu. Students (of school, college or even Correspondence courses in Universities) can avail this offer. As per information from their portal, right now they offer Acer brand laptops that are preloaded with Suse Linux Enterprise Edition 10.1 (here Linux is making it’s way to student’s life), which comes in two editions, one is fully-loaded that costs 31,717.00 INR and other one costs 29,429.00 INR. I believe prices are inclusive of all other taxes. I have gone through the configurations, it is very impressive for the price tag, however I really don’t know how good is that model in performance vise. BTW, the offer ends on July 31st, and it seems they are planned to sell only 1,00,000 laptops. So if you guys are interested please make your way to get one for yourself. More details on http://www.elcot.in/StudentLaptop2008/index.php (also don’t forget to watch a crazy video posted out there). I would love to hear from you if you have any information on laptop’s performance. Please trackback.





Blogging Frequency

13 07 2008

Yeah I know this post is coming after a long time. Part of the reason for the change in blogging frequency is that hectic work, but the real reason is that I’m lazy, I did not manage my time well and I know that I could have regularly posted, now I have decided to blog regularly irrespective of my work / personal schedules. I look at the blogging habit as a good way of expressing oneself, making new friends, and expanding one’s social network. Lately I ‘ve been twittering, you could follow me on my twitter URL http://twitter.com/sivas. I would be pleased to be followed by y’all.