General comments regarding MP1

These are some general observations that many of you might already be aware of, but few students still need to know...

1. about makefile...

# suppose your target is "command.o" and you have...

commands.o:    commands.cpp
                    g++ -c commands.cpp

# now, suppose "commands.cpp" includes and uses declarations from "commands.h" & "global.h". but according to
# the dependency list mentioned above, make utility doesn't know about this "dependence", hence any modifications
# to "command.h" or "global.h" won't result in recompilation of "command.o", something undesirable (and possible
# cause of linker/runtime errors ;o). Hence all ".h" files (that are included in ".cpp" file) should be added to the
# dependency list of that module.
 

# now, this is also important. if you are not including some files in "commands.cpp", then they should not appear in
# the dependency list of this module. otherwise it may lead to unnecessary recompilations, which at the very least
# results in waste of time !!!
 

2. about ".h" & ".cpp"

3. if (argv[i]=="-o")...

You should be aware what the above statement means !!!

well, for those who still aren't sure why this doesn't work "as expected", here is some "new" info...

C (and C++) treats all strings as constant character pointers. now, a pointer by itself means nothing but some address in the program. since "argv" (the second argument from main(...)) is a "char **" and "-o" is a string, above statement is actually comparing  memory address, where i'th command line argument is stored, to the address of memory location where "-o" string is stored. this essentially is different from comparing the two strings. hence, you should be using "strcmp(...)" or some variant here.

a note: you could be having a "String" class with overloaded "==" operator for general use. but "argv" will always have to use strcmp for historical reasons :o)
 

4. about buffer...

Since this project required (most of you) to use a buffer for reading input and scanning,  my last point is to mention an elegant technique of using a buffer which is very useful in such cases. this technique is from "Compiler Design: by Ullman, et.al.".  you can implement this as a class (or template) for general use.
 


As the course name suggests, i hope by the end of this semester everybody (including me :o) should have enhanced their programming skills !!!

-amit.