Sunday, November 29, 2009

++, --: yet another prove why they should be avoided

I was doing a walk through from one the old tests:

x = -2.1;

after the line...

x = -x++;

3 compilers assigned 3 different values to x:

VC++: 3.1 - incremented, negated (not necessarily in this order), assigned
linux: -1.1 - incremented, assigned (why never negated?)
borland: 2.1 - negated, assigned (never incremented)

Monday, November 23, 2009

io_checklist with comments

I added some comments to setItems() in io_checklist:

void IO_CheckList::setItems(const char *str){
int i;
unsigned int maxlen = 0;
int strLen= strlen((char*)str);
_itemstr = new char[strLen+1];
strcpy(_itemstr, (char*)str); // copy str into _itemstr
for(_len = 0,i=0;i if(_itemstr[i] == '\n'){
_len++; // number of items separated by '\n'
}
}
_items = new char*[_len+1]; //_items is pointer to an array of pointer
_status = new bool[_len+1];
for(i=0;i<_len+1;i++){
_status[i] = false;
}

/* Following lines of code:
_itemstr contains a string of items in the checklist, each one separated by '\n';
_items is made to point to the beginning of the string before the for loop;
Through the for loop, _itemstr is cycled through character by character.
Each time a '\n' is reached, _item is made to point to the character after the '\n'.
The '\n' is replaced with NULL and thus truncating the rest of the string so _item pointer in the array of pointers points to only 1 item in the checklist. */

_items[0] = _itemstr; // point to where _itemstr is pointing to
for(_len = 1,i=0;i if(_itemstr[i] == '\n'){
_items[_len]=&_itemstr[i+1]; // when '\n' is reached, _item points to first character after '\n'
_itemstr[i] = 0; // replace '\n' with NULL
if(strlen(_items[_len-1])> maxlen){
maxlen = strlen(_items[_len-1]); // keep track of the longest string copied
}
_len++; // keep track of number of items
}
}
if(strlen(_items[_len-1])> maxlen){
maxlen = strlen(_items[_len-1]);
}
IO_Frame::set(IO_Field::getRow(), IO_Field::getCol(), maxlen + 6, _len+2);
_titlelen = maxlen;
}

Tuesday, November 17, 2009

Assignment 2 progress

Just committed io_field (probably the easiest class for this assignment =P)- it's now done according to spec on wiki. The only kinks I ran into was trying to get the value of

_owner->getTop()
_owner->getLeft()

Since getTop() and getLeft() are functions of io_frame, _owner is an io_form pointer but inherits from io_frame I had to make sure that the inheritance is declared.

My next step is to look through io_checklist because Fardad said that there may be some extra functions that need to be added to io_field.

Thursday, November 5, 2009

Delayed blog - first 2 IRC meetings

This is a little delayed...not that good with words. =) Better late than never!
We had 2 irc meetings with Fardad during study break. We learnt what it means and how to update and commit on SVN.
oh and one important rule NEVER COMMIT SOMETHING THAT'S NOT BUILDABLE.
At this point we are in the process of committing our assigned classes(menubar and field for me).

My command line SVN doesn't work (not that it matters that much coz GUI works just fine). I checked PATH in my environmental variables and it's included. Anyone else having the same problem?

On a lighter note...Does anyone else find the SVN tortoise adorable?? I think I'll make a T-shirt out of it one day.