<?xml version="1.0" encoding="ISO-8859-1"?><html xmlns="http://www.w3.org/1999/xhtml" xmlns:xh="http://www.w3.org/1999/xhtml" xmlns:axle="http://www.cs.odu.edu/~zeil/axle" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ns0="http://www.cs.odu.edu/~zeil/axle" mode="ignore" ns0:xlinkuri="open/unix.dbk" ns0:xpath="/html" ns0:page="unix" foo="0 " ns0:last="/cocoon/~cs252/open/unix/section-8.2.html"><head><title>An Introduction to Unix</title><link type="text/css" href="_axle/docbookstyle.css" rel="stylesheet"/><link type="text/css" href="_axle/cppformat.css" rel="stylesheet"/><link type="text/css" href="_axle/overrides.css" rel="stylesheet"/><script src="_axle/docbook.js"/><link href="http://cocoon.cs.odu.edu:80/cocoon/~cs252/open/unix/section-7.2.html" title="Next" rel="next"/><link href="http://cocoon.cs.odu.edu:80/cocoon/~cs252/open/unix/xferproblems.html" title="Prev" rel="prev"/><link href="http://cocoon.cs.odu.edu:80/cocoon/~cs252/open/unix/unix.html" title="Up" rel="up"/><link href="http://cocoon.cs.odu.edu:80/cocoon/~cs252/open/unix/unix.html" title="First" rel="first"/><link href="http://cocoon.cs.odu.edu:80/cocoon/~cs252/open/unix/section-8.2.html" title="Last" rel="last"/><script>function gotoNext() {top.location.href="/cocoon/~cs252/open/unix/section-7.2.html";}
function gotoPrev() {top.location.href="/cocoon/~cs252/open/unix/xferproblems.html";}
function gotoUp() {top.location.href="/cocoon/~cs252/open/unix/unix.html";}
</script><xhtml:link xmlns:xhtml="http://www.w3.org/1999/xhtml" rel="stylesheet" href="_axle/navigation.css" type="text/css"/><xhtml:script xmlns:xhtml="http://www.w3.org/1999/xhtml" src="_axle/navigation.js"/></head><body><table width="100%" class="navigationBar"><tr class="navigationBar"><td width="5%" class="navigationBar"><a class="navigationBarArrow" title="First" href="http://cocoon.cs.odu.edu:80/cocoon/~cs252/open/unix/unix.html"><img class="navigationBar" src="_axle/first.gif" alt="First"/></a></td><td width="5%" class="navigationBar"><a class="navigationBarArrow" title="Prev" href="http://cocoon.cs.odu.edu:80/cocoon/~cs252/open/unix/xferproblems.html"><img class="navigationBar" src="_axle/prev.gif" alt="Prev"/></a></td><td width="5%" class="navigationBar"><a class="navigationBarArrow" title="Up" href="http://cocoon.cs.odu.edu:80/cocoon/~cs252/open/unix/unix.html"><img class="navigationBar" src="_axle/up.gif" alt="Up"/></a></td><td width="5%" class="navigationBar"><a class="navigationBarArrow" title="Next" href="http://cocoon.cs.odu.edu:80/cocoon/~cs252/open/unix/section-7.2.html"><img class="navigationBar" src="_axle/next.gif" alt="Next"/></a></td><td width="5%" class="navigationBar"><a class="navigationBarArrow" title="Last" href="http://cocoon.cs.odu.edu:80/cocoon/~cs252/open/unix/section-8.2.html"><img class="navigationBar" src="_axle/last.gif" alt="Last"/></a></td><td class="navigationBar"/><td width="5%" class="navigationBar"><a class="navigationBar" title="CS252 Home" href="http://cocoon.cs.odu.edu:80/cocoon/~cs252/directory/announcements.html"><img class="navigationBar" src="_axle/home.gif" alt="CS252 Home"/></a></td><td width="5%" class="navigationBar"><a class="navigationBar" title="discuss this page" href="http://cocoon.cs.odu.edu:80/cocoon/~cs252/forum/getXPath/open/unix/section-7.html"><img class="navigationBar" src="_axle/forum.gif" alt="discuss this page"/></a></td></tr></table><br/><script type="text/javascript">
checkForAnchorOnOtherPage('section-1','unix');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('mainmini','mainmini');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('section-1.1.1','mainmini');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('displays','mainmini');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('networks','mainmini');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('taleof2','taleof2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('section-1.2.1','taleof2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('pcrev','taleof2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref1','taleof2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref1_live','taleof2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref2','taleof2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref2_live','taleof2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fnote1','taleof2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fnote2','taleof2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('mswin','taleof2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('reflections','reflections');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref3','reflections');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref3_live','reflections');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fnote3','reflections');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('ssh','ssh');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref4','ssh');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref4_live','ssh');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('puttyConnect','ssh');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('sshConnect','ssh');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fnote4','ssh');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('login','login');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('termtypes','termtypes');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref5','termtypes');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref5_live','termtypes');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fnote5','termtypes');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('section-1.7','section-1.7');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('section-1.8','section-1.8');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('section-2','section-2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('section-2.1','section-2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref6','section-2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref6_live','section-2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref7','section-2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref7_live','section-2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('basicFileCmds','section-2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref8','section-2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref8_live','section-2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fnote8','section-2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('cmdlist','section-2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('session','section-2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('rlogin','section-2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('filemanip','section-2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('cdcmd','section-2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('findcmd','section-2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('lsa','section-2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('lsF','section-2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('pwdcmd','section-2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('textmanip','section-2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('catcmd','section-2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('morecmd','section-2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('printing','section-2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fnote6','section-2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fnote7','section-2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('section-2.2','section-2.2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref9','section-2.2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref9_live','section-2.2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('paths','section-2.2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref10','section-2.2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref10_live','section-2.2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fnote10','section-2.2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('specialChar','section-2.2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('cmdpatterns','section-2.2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref11','section-2.2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref11_live','section-2.2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('wildcards','section-2.2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref12','section-2.2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref12_live','section-2.2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fnote12','section-2.2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('regexp','section-2.2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('grepregexps','section-2.2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref13','section-2.2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref13_live','section-2.2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref14','section-2.2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref14_live','section-2.2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fnote13','section-2.2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fnote14','section-2.2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('sedregexps','section-2.2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref15','section-2.2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref15_live','section-2.2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref16','section-2.2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref16_live','section-2.2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fnote15','section-2.2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fnote16','section-2.2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fnote11','section-2.2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('quoting','section-2.2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref17','section-2.2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref17_live','section-2.2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fnote17','section-2.2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fnote9','section-2.2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('section-2.3','section-2.3');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref18','section-2.3');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref18_live','section-2.3');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('redirect','section-2.3');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('piping','section-2.3');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('xargs','section-2.3');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('find','section-2.3');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fnote18','section-2.3');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('section-2.4','section-2.4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('section-2.4.1','section-2.4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref19','section-2.4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref19_live','section-2.4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fnote19','section-2.4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('section-2.4.2','section-2.4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref20','section-2.4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref20_live','section-2.4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fnote20','section-2.4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('umask','section-2.4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('section-2.4.4','section-2.4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('section-3','section-3');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('vim','section-3');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref21','section-3');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref21_live','section-3');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('section-3.1','section-3.1');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('section-3.2','section-3.2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('section-3.3','section-3.3');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('markregion','markregion');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref22','markregion');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref22_live','markregion');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fnote22','markregion');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('section-3.5','section-3.5');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('section-3.6','section-3.6');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fnote21','section-3.6');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('section-4','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('section-4.1','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('section-4.1.1','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('twin','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('icewin','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('starwin','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('connections','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('runningx','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref23','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref23_live','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('launchTheServer','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('creatingsession','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('section-4.1.2.1.2','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('section-4.1.2.1.3','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref24','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref24_live','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fnote24','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('section-4.1.2.1.4','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref25','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref25_live','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fnote25','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('launchClient','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref26','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref26_live','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('launchViaSsh','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref27','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref27_live','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fnote27','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('launchViaPutty','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref28','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref28_live','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fnote28','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('xlaunch-sessions','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('xwin32-sessions','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref29','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref29_live','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fnote29','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fnote26','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fnote23','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('section-4.1.3','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('xappl','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('xtrouble','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('cannotOpen','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('firewall','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref30','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref30_live','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref31','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref31_live','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref32','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref32_live','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fnote30','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fnote31','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fnote32','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('xforwarding','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('xfast','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('section-4.1.5.4.1','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('section-4.1.5.4.2','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('xtermFont','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('connect-localhost','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('refusedByServer','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('alternatives','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('RDP','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('vnc','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('vncx','section-4');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('section-4.2','section-4.2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('emacsinx','section-4.2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('emacsintelnet','section-4.2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('section-5','section-5');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('section-5.1','section-5');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('section-5.1.1','section-5');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('section-5.1.2','section-5');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('mailcommand','section-5');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('mailsend','section-5');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('section-5.1.3.2','section-5');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref33','section-5');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref33_live','section-5');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fnote33','section-5');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('popmail','section-5');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('section-5.2','section-5.2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('pinemain','section-5.2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('pinecompose','section-5.2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('pineindex','section-5.2');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('section-6','section-6');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('xfermode','xfermode');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('xfersamba','xfersamba');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref34','xfersamba');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref34_live','xfersamba');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fnote34','xfersamba');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('internetftp','internetftp');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('anonprivateftp','internetftp');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref35','internetftp');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref35_live','internetftp');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fnote35','internetftp');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('ftpclient','internetftp');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref36','internetftp');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref36_live','internetftp');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref37','internetftp');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fref37_live','internetftp');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fnote36','internetftp');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('fn_fnote37','internetftp');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('xferproblems','xferproblems');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('dostounix','xferproblems');
</script><script type="text/javascript">
checkForAnchorOnOtherPage('unixtodos','xferproblems');
</script><div class="sect1" id="section-7" ns0:xpath="//*[@id='section-7']" ns0:page="section-7" ns0:next="/cocoon/~cs252/open/unix/section-7.2.html" ns0:prev="/cocoon/~cs252/open/unix/xferproblems.html" ns0:up="/cocoon/~cs252/open/unix/unix.html" foo="0 " ns0:last="/cocoon/~cs252/open/unix/section-8.2.html" ns0:first="/cocoon/~cs252/open/unix/unix.html"><div class="info_sect1"><div class="title_sect2">7. Program Development</div></div><div class="TOC">Contents:<div class="TOC-section1"><a href="#section-7.1">7.1 Program Development via telnet</a></div><div class="TOC-section2"><a href="#section-7.1.1">7.1.1 Compiling</a></div><div class="TOC-section2"><a href="#section-7.1.2">7.1.2 Project Management (make)</a></div><div class="TOC-section2"><a href="#section-7.1.3">7.1.3 Debugging</a></div><div class="TOC-section1"><a href="section-7.2.html#section-7.2">7.2 Program Development via X</a></div><div class="TOC-section2"><a href="section-7.2.html#section-7.2.1">7.2.1 Compiling</a></div><div class="TOC-section2"><a href="section-7.2.html#section-7.2.2">7.2.2 Debugging</a></div></div><div class="sect2" axle:nopage="1" id="section-7.1"><div class="info_sect2"><div class="title_sect3">7.1. Program Development via telnet</div></div><div class="TOC">Contents:<div class="TOC-section2"><a href="#section-7.1.1">7.1.1 Compiling</a></div><div class="TOC-section3"><a href="#compshell">7.1.1.1 Compiling C and C++</a></div><div class="TOC-section3"><a href="#errmsgs">7.1.1.2 Error Messages</a></div><div class="TOC-section3"><a href="#javacomp">7.1.1.3 Compiling Java in the Shell (Optional)</a></div><div class="TOC-section3"><a href="#section-7.1.1.4">7.1.1.4 Compiling with emacs</a></div><div class="TOC-section3"><a href="#vimcompile">7.1.1.5 Compiling with vim</a></div><div class="TOC-section2"><a href="#section-7.1.2">7.1.2 Project Management (make)</a></div><div class="TOC-section3"><a href="#section-7.1.2.1">7.1.2.1 Symbols</a></div><div class="TOC-section3"><a href="#section-7.1.2.2">7.1.2.2 Default Rules</a></div><div class="TOC-section3"><a href="#artificial-targets">7.1.2.3 Common Conventions</a></div><div class="TOC-section3"><a href="#writingMakefiles">7.1.2.4 Creating a Makefile</a></div><div class="TOC-section3"><a href="#section-7.1.2.5">7.1.2.5 Is It Worth It?</a></div><div class="TOC-section2"><a href="#section-7.1.3">7.1.3 Debugging</a></div><div class="TOC-section3"><a href="#section-7.1.3.1">7.1.3.1 Debugging Output</a></div><div class="TOC-section3"><a href="#section-7.1.3.2">7.1.3.2 assertions</a></div><div class="TOC-section3"><a href="#section-7.1.3.3">7.1.3.3 Automated Debuggers</a></div><div class="TOC-section3"><a href="#gdbmode">7.1.3.4 emacs debugging mode</a></div></div><div class="sect3" axle:nopage="1" id="section-7.1.1"><div class="info_sect3"><div class="title_sect4">7.1.1. Compiling</div></div><div class="TOC">Contents:<div class="TOC-section3"><a href="#compshell">7.1.1.1 Compiling C and C++</a></div><div class="TOC-section4"><a href="#cStructure">7.1.1.1.1 The Structure of C++ and C Programs</a></div><div class="TOC-section4"><a href="#compilingSingle">7.1.1.1.2 Compiling a Program With Only One Non-Header File</a></div><div class="TOC-section4"><a href="#compilingMultiple">7.1.1.1.3 Compiling With Multiple Non-Header Files</a></div><div class="TOC-section4"><a href="#compilerOptions">7.1.1.1.4 Some Useful Compiler Options</a></div><div class="TOC-section3"><a href="#errmsgs">7.1.1.2 Error Messages</a></div><div class="TOC-section4"><a href="#capturing">7.1.1.2.1 Capturing the Error Messages</a></div><div class="TOC-section4"><a href="#understanding">7.1.1.2.2 Understanding the Error Messages</a></div><div class="TOC-section3"><a href="#javacomp">7.1.1.3 Compiling Java in the Shell (Optional)</a></div><div class="TOC-section3"><a href="#section-7.1.1.4">7.1.1.4 Compiling with emacs</a></div><div class="TOC-section3"><a href="#vimcompile">7.1.1.5 Compiling with vim</a></div></div><div class="sect4" axle:nopage="1" id="compshell"><div class="info_sect4"><div class="title_sect5">7.1.1.1. Compiling C and C++</div></div><div class="TOC">Contents:<div class="TOC-section4"><a href="#cStructure">7.1.1.1.1 The Structure of C++ and C Programs</a></div><div class="TOC-section5"><a href="#section-7.1.1.1.1.1">7.1.1.1.1.1 What Goes Into a Header File? What Goes Into a Non-Header File?</a></div><div class="TOC-section5"><a href="#section-7.1.1.1.1.2">7.1.1.1.1.2 What is the difference between a declaration and a definition?</a></div><div class="TOC-section4"><a href="#compilingSingle">7.1.1.1.2 Compiling a Program With Only One Non-Header File</a></div><div class="TOC-section4"><a href="#compilingMultiple">7.1.1.1.3 Compiling With Multiple Non-Header Files</a></div><div class="TOC-section4"><a href="#compilerOptions">7.1.1.1.4 Some Useful Compiler Options</a></div></div>
    
    <p class="para">Now that you know how to create and edit files, you can generate new
programs. The most commonly used languages in the CS Department at the
moment are C<span class="inlineequation"><span class="mathphrase">++</span></span>, C, and Java.</p>
    <p class="para">The most popular C<span class="inlineequation"><span class="mathphrase">++</span></span> and C compilers are <span class="code">g++</span>
and <span class="code">gcc</span>.<a onmouseover="DBshowBriefly('fn_fref38_live')" name="fn_fref38" id="fn_fref38" class="footnotemark" href="#fn_fnote38">38</a><div class="footnote_live" id="fn_fref38_live">Actually, <span class="code">gcc</span> and <span class="code">g++</span> are the 
same compiler being invoked with slightly different options.</div></p>


    <div class="sect5" id="cStructure"><div class="info_sect5"><div class="title_sect6">The Structure of C++ and C Programs</div></div><div class="TOC">Contents:<div class="TOC-section5"><a href="#section-7.1.1.1.1.1">7.1.1.1.1.1 What Goes Into a Header File? What Goes Into a Non-Header File?</a></div><div class="TOC-section5"><a href="#section-7.1.1.1.1.2">7.1.1.1.1.2 What is the difference between a declaration and a definition?</a></div></div>
      

<p class="para">Although not really a Unix-specific topic, it's hard to discuss how to compile code under any operating system without a basic understanding how programs are put together.</p>


      <p class="para">The source code for a C++ (or C) program is contained in a number of text files called <span class="firstterm">source files</span>. Very simple programs might be contained within a single source file, but as our programs grow larger and more complicated, programmers try to keep things manageable by splitting the code into multiple source files, no one of which should be terribly long.</p>

      <p class="para">There are two different kinds of source files: <span class="firstterm">header files</span> and <span class="firstterm">non-header files</span>.

      Header files are generally given names ending in <span class="quote">
      &#8220;<span class="filename">.h</span>&#8221;
    </span>. Non-header files are generally given names ending in <span class="quote">
      &#8220;<span class="filename">.cpp</span>&#8221;
    </span> for C++ code and <span class="quote">
      &#8220;<span class="filename">.c</span>&#8221;
    </span> for C code.<a onmouseover="DBshowBriefly('fn_fref39_live')" name="fn_fref39" id="fn_fref39" class="footnotemark" href="#fn_fnote39">39</a><div class="footnote_live" id="fn_fref39_live"><p class="para">There are variations, particularly for C++. Other less common endings accepted by some C++ compilers for non-header files include
<span class="quote">
      &#8220;<span class="filename">.C</span>&#8221;
    </span>
<span class="quote">
      &#8220;<span class="filename">.cc</span>&#8221;
    </span>
and 
<span class="quote">
      &#8220;<span class="filename">.cxx</span>&#8221;
    </span>.</p></div>
      </p>

<p class="para">Header and non-header files are treated differently when we build programs. Each non-header file is <span class="emphasis">compiled</span> separately from the others (<a linked="fig:compilation" href="#"/>). This helps keep the compilation times reasonable, particularly when we are fixing bugs in a program and may have changed only one or two non-header files. Only those changed files need to be recompiled.  </p>

<p class="para">Header files are not compiled directly, Instead, header files are <span class="emphasis">included</span> into other source files via  <span class="code">#include</span>. In fact, when you invoke a C/C++ compiler, before the <span class="quote">
      &#8220;real&#8221;
    </span> compiler starts, it runs a <span class="firstterm">pre-processor</span> whose job is to handle the special instructions that begin with <span class="code">#</span>. In the case of <span class="code">#include</span> statements, the pre-processor simply grabs the relevant header file and sticks its content into the program right at the spot of the <span class="code">#include</span>. 
</p>


<div class="figure" id="fig:compilation"><span class="inlinemediaobject"><img src="compilation.gif" fileref="compilation.gif" printwide="0.9"/></span><div class="info_figure"><div class="title_figure">Figure 15: Building 1 program from many files</div></div></div>



<div style="clear:right;"/><table class="sidebar" border="1" width="40%"><tr><td>
<div class="programlisting">
<xhtml:div xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="code"><span class="br"/>
<xhtml:span axle:forumAnchor="1"/><xhtml:span class="cpppreproc">#include &lt;iostream&gt;</xhtml:span><span class="br"/>
<xhtml:span axle:forumAnchor="1"/><xhtml:span class="cpppreproc">#include &lt;string&gt;</xhtml:span><span class="br"/>
<xhtml:span axle:forumAnchor="1"/><span class="br"/>
<xhtml:span axle:forumAnchor="1"/><xhtml:span class="cppid">using</xhtml:span> <xhtml:span class="cppid">namespace</xhtml:span> <xhtml:span class="cppid">std</xhtml:span><xhtml:span class="cppop">;</xhtml:span><span class="br"/>
<xhtml:span axle:forumAnchor="1"/><xhtml:span class="cppkeyword">int</xhtml:span> <xhtml:span class="cppid">main</xhtml:span><xhtml:span class="cppop">(</xhtml:span><xhtml:span class="cppop">)</xhtml:span><span class="br"/>
<xhtml:span axle:forumAnchor="1"/><xhtml:span class="cppop">{</xhtml:span><span class="br"/>
<xhtml:span axle:forumAnchor="1"/>  <xhtml:span class="cppid">string</xhtml:span> <xhtml:span class="cppid">greeting</xhtml:span> <xhtml:span class="cppop">=</xhtml:span> <xhtml:span class="cppliteral">"Hello!"</xhtml:span><xhtml:span class="cppop">;</xhtml:span><span class="br"/>
<xhtml:span axle:forumAnchor="1"/>  <xhtml:span class="cppid">cout</xhtml:span> <xhtml:span class="cppop">&lt;&lt;</xhtml:span> <xhtml:span class="cppid">greeting</xhtml:span> <xhtml:span class="cppop">&lt;&lt;</xhtml:span> <xhtml:span class="cppid">endl</xhtml:span><xhtml:span class="cppop">;</xhtml:span><span class="br"/>
<xhtml:span axle:forumAnchor="1"/>  <xhtml:span class="cppkeyword">return</xhtml:span> <xhtml:span class="cppliteral">0</xhtml:span><xhtml:span class="cppop">;</xhtml:span><span class="br"/>
<xhtml:span axle:forumAnchor="1"/><xhtml:span class="cppop">}</xhtml:span><span class="br"/>
<xhtml:span axle:forumAnchor="1"/><span class="br"/>
<xhtml:span axle:forumAnchor="1"/></xhtml:div>
</div>
</td></tr></table>
<p class="para">
This can result in a dramatic increase in the amount of code that actually gets processed. The code shown here, for example, is pretty basic. But the <span class="code">#include</span> statements bring in an entire library of I/O and string-related declarations from the C++ standard library.  <a url="../../html/preprocessorSample.html" href="../../html/preprocessorSample.html">Here</a>, for example, is the output of the pre-processor for one compiler. (If you look at the very end, you can recognize the main code for this program.)</p>


<p class="para">A header file can be <span class="code">#include</span>d from any number of other header and non-header files. That is, in fact, the whole point of having header files. <span class="emphasis-italic" role="italic">Header files should contain declarations of things that need to be <span class="emphasis">shared</span> by multiple other source files. Non-header files should declare only things that do not need to be shared.</span></p>

<p class="para">As we go through all thecompilation steps required to build a program, anything that appears in a non-header file will be processed exactly once by the compiler. Anything that appears in a header file may be processed multiple times by the compiler.</p>

<div class="sect6" id="section-7.1.1.1.1.1"><div class="info_sect6"><div class="title_sect7">What Goes Into a Header File? What Goes Into a Non-Header File?</div></div>
  

<p class="para">The short answer is that a header file contains shared <span class="firstterm">declarations</span>, a non-header file contains <span class="firstterm">definitions</span> and  local (non-shared) declarations.</p>

</div>

<div class="sect6" id="section-7.1.1.1.1.2"><div class="info_sect6"><div class="title_sect7">What is the difference between a declaration and a definition?</div></div>
  

<p class="para">Pretty much everything that has a <span class="quote">
      &#8220;name&#8221;
    </span> in C++ must be
declared before you can use it.  Many of these things must also be
defined, but that can generally be done at a much later time.</p>

<p class="para">You <span class="firstterm">declare</span> a name by saying what kind of thing it is:
<div class="programlisting">
<xhtml:div xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="code"> <xhtml:span class="cppkeyword">const</xhtml:span> <xhtml:span class="cppkeyword">int</xhtml:span> <xhtml:span class="cppid">MaxSize</xhtml:span><xhtml:span class="cppop">;</xhtml:span>          <xhtml:span class="cppcomment">// declares a constant</xhtml:span><span class="br"/>
<xhtml:span axle:forumAnchor="1"/> <xhtml:span class="cppkeyword">extern</xhtml:span> <xhtml:span class="cppkeyword">int</xhtml:span> <xhtml:span class="cppid">v</xhtml:span><xhtml:span class="cppop">;</xhtml:span>               <xhtml:span class="cppcomment">// declares a variable</xhtml:span><span class="br"/>
<xhtml:span axle:forumAnchor="1"/> <xhtml:span class="cppkeyword">void</xhtml:span> <xhtml:span class="cppid">foo</xhtml:span> <xhtml:span class="cppop">(</xhtml:span><xhtml:span class="cppkeyword">int</xhtml:span> <xhtml:span class="cppid">formalParam</xhtml:span><xhtml:span class="cppop">)</xhtml:span><xhtml:span class="cppop">;</xhtml:span> <xhtml:span class="cppcomment">// declares a function (and a formal parameter)</xhtml:span><span class="br"/>
<xhtml:span axle:forumAnchor="1"/> <xhtml:span class="cppkeyword">class</xhtml:span> <xhtml:span class="cppid">Bar</xhtml:span><xhtml:span class="cppop">{</xhtml:span><xhtml:span class="cppkeyword">&#8230;</xhtml:span><xhtml:span class="cppop">}</xhtml:span><xhtml:span class="cppop">;</xhtml:span>               <xhtml:span class="cppcomment">// declares a class</xhtml:span><span class="br"/>
<xhtml:span axle:forumAnchor="1"/> <xhtml:span class="cppkeyword">typedef</xhtml:span> <xhtml:span class="cppid">Bar</xhtml:span><xhtml:span class="cppop">*</xhtml:span> <xhtml:span class="cppid">BarPointer</xhtml:span><xhtml:span class="cppop">;</xhtml:span>    <xhtml:span class="cppcomment">// declares a type name</xhtml:span><span class="br"/>
<xhtml:span axle:forumAnchor="1"/></xhtml:div></div>
</p>

<p class="para">In most cases, once you have declared a name, you can write code that
uses it.  Furthermore, a program may declare the same thing any number
of times, as long as it does so consistently.  That's why a single header file
can be included by several different non-header files that make up a program
- header files contain only declarations.</p>

<p class="para">You <span class="firstterm">define</span> constants, variables, and functions as follows:
<div class="programlisting">
<xhtml:div xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="code"> <xhtml:span class="cppkeyword">const</xhtml:span> <xhtml:span class="cppkeyword">int</xhtml:span> <xhtml:span class="cppid">MaxSize</xhtml:span> <xhtml:span class="cppop">=</xhtml:span> <xhtml:span class="cppliteral">1000</xhtml:span><xhtml:span class="cppop">;</xhtml:span>                   <xhtml:span class="cppcomment">// defines a constant</xhtml:span><span class="br"/>
<xhtml:span axle:forumAnchor="1"/> <xhtml:span class="cppkeyword">int</xhtml:span> <xhtml:span class="cppid">v</xhtml:span><xhtml:span class="cppop">;</xhtml:span>                                      <xhtml:span class="cppcomment">// defines a variable</xhtml:span><span class="br"/>
<xhtml:span axle:forumAnchor="1"/> <xhtml:span class="cppkeyword">void</xhtml:span> <xhtml:span class="cppid">foo</xhtml:span> <xhtml:span class="cppop">(</xhtml:span><xhtml:span class="cppkeyword">int</xhtml:span> <xhtml:span class="cppid">formalParam</xhtml:span><xhtml:span class="cppop">)</xhtml:span> <xhtml:span class="cppop">{</xhtml:span><xhtml:span class="cppop">++</xhtml:span><xhtml:span class="cppid">formalParam</xhtml:span><xhtml:span class="cppop">;</xhtml:span><xhtml:span class="cppop">}</xhtml:span> <xhtml:span class="cppcomment">// defines a function</xhtml:span><span class="br"/>
<xhtml:span axle:forumAnchor="1"/></xhtml:div></div>
A definition must be seen by the compiler once and only once in all
the compilations that get linked together to form the final program.
A definition is itself also a declaration (i.e., if you define
something that hasn't been declared yet, that's OK. The definition
will serve double duty as declaration and definition.).</p>


<p class="para">
When a non-header file is compiled, we get an <span class="firstterm">object-code file</span>, usually ending in <span class="quote">
      &#8220;<span class="filename">.o</span>&#8221;
    </span>. These are binary files that are <span class="quote">
      &#8220;almost&#8221;
    </span> executable - for some variables and functions, instead of the actual address of that variable/function, they still have its name. This happens when the variable or function is decalred but not defined in that non-header file (after expansion of <span class="code">#include</span>s by the pre-processor). That name will be assigned an address only when a file contianing a definition of that name is compiled. And that address will only be recorded in the object code file corresponding to the non-header source file where the name was defined.
</p>

<p class="para">The complete executable program is then produced by <span class="firstterm">linking</span> all the object code files together. The job of the linker is to find, for each name appearing in the object code, the address that was eventually assigned to that name, make the substitution, and produce a true binary executable in which all names have been replaced by addresses.</p>

<p class="para">Understanding this difference and how the entire compilation/build process works (<a href="#fig:compilation">Figure 15: <span class="title_xref">Building 1 program from many files</span></a>) can help to explain some common but confusingly similar error messages:
<div class="itemizedlist"><ul><li>
  <p class="para">
    If the compiler says that a function is <span class="emphasis">undeclared</span>, it means that you tried to use it before presenting its declaration, or forgot 
to declare it at all.</p></li><li>
<p class="para">The compiler never complains about definitions, because an apparently missing
definition might just be in some other non-header file you are going to compile later.  But when you try to produce the executable
program by linking all the compiled object code files
files produced by the compiler, the <span class="emphasis">linker</span> may complain that a
symbol is 
<div class="itemizedlist"><ul><li>
<p class="para">
<span class="emphasis">undefined</span> (none of the compiled files provided a
definition) or is
</p>
</li><li>
<p class="para">
 <span class="emphasis">multiply defined</span> (you provided two definitions
for one name, or somehow compiled the same definition into more than
one object-code file).
</p>
</li></ul></div>
</p>
<p class="para">
  For example, if you forget a function body, the linker
will eventually complain that the function is undefined. If
you put a variable or function <span class="emphasis-bold" role="bold">definition</span> in a .h file and include
that file from more than one place, the linker will complain that the
name is multiply defined.</p>
</li></ul></div>
</p>
</div>
    <div name="fn_fnote39" id="fn_fnote39" class="footnote">39. <p class="para">There are variations, particularly for C++. Other less common endings accepted by some C++ compilers for non-header files include
<span class="quote">
      &#8220;<span class="filename">.C</span>&#8221;
    </span>
<span class="quote">
      &#8220;<span class="filename">.cc</span>&#8221;
    </span>
and 
<span class="quote">
      &#8220;<span class="filename">.cxx</span>&#8221;
    </span>.</p> (<a href="#fn_fref39">back</a>)
    </div></div>

    <div class="sect5" id="compilingSingle"><div class="info_sect5"><div class="title_sect6">Compiling a Program With Only One Non-Header File</div></div>
      
      <p class="para">The simplest case for each compiler involves compiling a single-file
program (or a program in which all files are combined by
<span class="code">#include</span> statements). For example, use an editor to prepare the
following files:</p>
      <p class="para">
        <span class="emphasis-bold" role="bold">     hello.cpp</span>
        <div class="code" axle:cppcode="1"><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cpppreproc">#include &lt;iostream&gt; </xhtml:span><span class="br"/>
<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" axle:forumAnchor="1"/><span class="br"/>
<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" axle:forumAnchor="1"/><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">using</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">namespace</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">std</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">;</xhtml:span><span class="br"/>
<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" axle:forumAnchor="1"/><span class="br"/>
<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" axle:forumAnchor="1"/><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppkeyword">int</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">main</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">(</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">)</xhtml:span> <span class="br"/>
<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" axle:forumAnchor="1"/><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">{</xhtml:span> <span class="br"/>
<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" axle:forumAnchor="1"/>  <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">cout</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">&lt;&lt;</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppliteral">"Hello from C++ !"</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">&lt;&lt;</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">endl</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">;</xhtml:span> <span class="br"/>
<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" axle:forumAnchor="1"/>  <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppkeyword">return</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppliteral">0</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">;</xhtml:span> <span class="br"/>
<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" axle:forumAnchor="1"/><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">}</xhtml:span><span class="br"/>
<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" axle:forumAnchor="1"/></div>
      </p>
      <p class="para">
        <span class="emphasis-bold" role="bold">     hello.c</span>
        <div class="code" axle:cppcode="1"><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cpppreproc">#include &lt;stdio.h&gt; </xhtml:span><span class="br"/>
<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" axle:forumAnchor="1"/><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppkeyword">int</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">main</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">(</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">)</xhtml:span> <span class="br"/>
<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" axle:forumAnchor="1"/><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">{</xhtml:span><span class="br"/>
<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" axle:forumAnchor="1"/>  <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">printf</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">(</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppliteral">"Hello from C!\n"</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">)</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">;</xhtml:span> <span class="br"/>
<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" axle:forumAnchor="1"/>  <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppkeyword">return</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppliteral">0</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">;</xhtml:span><span class="br"/>
<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" axle:forumAnchor="1"/><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">}</xhtml:span><span class="br"/>
<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" axle:forumAnchor="1"/></div>
      </p>
      <p class="para">To compile and run these, the commands are:
<div class="programlisting">
   g++ -g hello.cpp
   ./a.out
   gcc -g hello.c
   ./a.out
</div>
The compiler generates an executable program called
<span class="code">a.out</span>. If you don't like that name, you can use the <span class="code">mv</span>
command to rename it.  Alternatively, use a <span class="code">-o</span> option to
specify the name you would like for the compiled program:
<div class="programlisting">
   g++ -g -o hello1 hello.cpp
   ./hello1
   gcc -g -o hello2 hello.c
   ./hello2
</div></p>
    </div>
    <div class="sect5" id="compilingMultiple"><div class="info_sect5"><div class="title_sect6">Compiling With Multiple Non-Header Files</div></div>
      

      <p class="para">A typical program will consist of many <span class="code">.cpp</span> files. (See <a href="#fig:compilation">Figure 15: <span class="title_xref">Building 1 program from many files</span></a>) Usually, each class or group of utility
functions will have their definitions in a separate <span class="code">.cpp</span> file
that defines everything declared in the corresponding <span class="code">.h</span>
file. The <span class="code">.h</span> file can then be <span class="code">#include</span>d by many different
parts of the program that use those classes or functions, and the
<span class="code">.cpp</span> file can be separately compiled once, then the resulting
object code file is <span class="firstterm">linked</span> together with the object code from
other <span class="code">.cpp</span> files to form the complete program.</p>
      <p class="para">Splitting the program into pieces like this helps, among other things,
divide the responsibility for who can change what and reduces the amount
of compilation that must take place after a change to a function body.
</p>
      <p class="para">When you have a program consisting of multiple files to be compiled
separately, add a <span class="code">-c</span> option to each compilation. This will cause
the compiler  to generate a <span class="code">.o</span> object code file instead of an executable.
Then invoke the compiler on all the <span class="code">.o</span> files together without
the <span class="code">-c</span> to link them together and produce an executable:
<div class="programlisting">
   g++ -g -c file1.cpp
   g++ -g -c file2.cpp
   g++ -g -c file3.cpp
   g++ -g -o programName file1.o file2.o file3.o
</div>
(If there are no other .o files in that directory, the last command
can often be abbreviated to 
<span class="quote">
      &#8220;<span class="code">g++ -o programName -g *.o</span>&#8221;
    </span>.) 
The same procedure works for the <span class="code">gcc</span> compiler as well.</p>
      <p class="para">Actually, you don't have to type separate compilation commands for
each file. You can do the whole thing in one step:
<div class="programlisting">
   g++ -g -o programName file1.cpp file2.cpp file3.cpp
</div>
But the step-by-step procedure is a good habit to get into. As you
begin debugging your code, you are likely to make changes to only one
file at a time. If, for example, you find and fix a bug in
<span class="code">file2.cpp</span>, you need to only recompile that file and relink:
<div class="programlisting">
   g++ -g -c file2.cpp
   g++ -g -o programName file1.o file2.o file3.o
</div>
An even better way to manage multiple source files is to use the
<a href="../make/"><span class="code">make</span> command</a>.</p>

    </div>

    <div class="sect5" id="compilerOptions"><div class="info_sect5"><div class="title_sect6">Some Useful Compiler Options</div></div>
      




      <p class="para">Another useful option in these compilers is <span class="code">-D</span>. If you add
an option <span class="code">-D<span class="emphasis">name</span>=<span class="emphasis">value</span></span>, then all occurrences of the
identifier <span class="emphasis">name</span> in the program will be replaced by <span class="emphasis">value</span>. 
This can be useful as a way of customizing programs without editing
them. If you use this option without a value, <span class="code">-D<span class="emphasis">name</span></span>,
then the compiler still notes that <span class="emphasis">name</span> has been <span class="quote">
      &#8220;defined&#8221;
    </span>. This
is useful in conjunction with compiler directive <span class="code">#ifdef</span>, which
causes certain code to be compiled only if a particular name is
defined. For example, many programmers will insert debugging output
into their code this way:
<div class="code" axle:cppcode="1"><img xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" xmlns:xhtml="http://www.w3.org/1999/xhtml" src="_axle/vdots.gif"/><span class="br"/>
<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" axle:forumAnchor="1"/><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">x</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">=</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">f</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">(</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">x</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">,</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">y</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">,</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">z</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">)</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">;</xhtml:span><span class="br"/>
<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" axle:forumAnchor="1"/><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cpppreproc">#ifdef DEBUG</xhtml:span><span class="br"/>
<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" axle:forumAnchor="1"/>   <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">cerr</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">&lt;&lt;</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppliteral">"the value of X is: "</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">&lt;&lt;</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">x</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">&lt;&lt;</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">endl</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">;</xhtml:span><span class="br"/>
<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" axle:forumAnchor="1"/><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cpppreproc">#endif</xhtml:span><span class="br"/>
<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" axle:forumAnchor="1"/><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">y</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">=</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">g</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">(</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">z</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">,</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">x</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">)</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">;</xhtml:span><span class="br"/>
<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" axle:forumAnchor="1"/><img xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" xmlns:xhtml="http://www.w3.org/1999/xhtml" src="_axle/vdots.gif"/><span class="br"/>
<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" axle:forumAnchor="1"/></div>
The output statement in this code will be ignored by the compiler
unless the option <span class="code">-DDEBUG</span> is included in the command line when
the compiler is run.<a onmouseover="DBshowBriefly('fn_fref40_live')" name="fn_fref40" id="fn_fref40" class="footnotemark" href="#fn_fnote40">40</a><div class="footnote_live" id="fn_fref40_live">Zeil's 1st Rule of Debugging: Never
remove debugging output. Just make it conditional. If you remove it, you're
bound to want it again later.

<p class="para">Zeil's 2nd Rule of Debugging: Never leave your debugging code
active when you submit your programs for grading. If the grader is
using an automatic program to check the correctness of the output,
unexpected output will make your program fail the tests. On the other
hand, if the grader is reading the output to check its correctness,
wading through extra output really ticks the grader off!</p></div></p>
      <p class="para">Sometimes your program may need functions from a previously-compiled
library. For example, the <span class="code">sqrt</span> and other mathmatical functions
are kept in the <span class="quote">
      &#8220;<span class="code">m</span>&#8221;
    </span> library (the filename is actually
<span class="code">libm.a</span>). To add functions from this library to your program, you
would use the <span class="quote">
      &#8220;<span class="code">-lm</span>&#8221;
    </span> option.  (The <span class="quote">
      &#8220;m&#8221;
    </span> in <span class="quote">
      &#8220;<span class="code">-lm</span>&#8221;
    </span> is the
library name.) This is a linkage option, so it goes at the end of the
command:
<div class="programlisting">
   g++ -g -c file1.cpp
   g++ -g -c file2.cpp
   g++ -g -c file3.cpp
   g++ -g -o programName file1.o file2.o file3.o -lm
</div>
The general form of gcc/g++ commands is
<span class="a" href=""><span class="emphasis">
            Fix this xref: 
          </span><span class="code">g++</span> <span class="emphasis">compilation-options</span> <span class="emphasis">files</span> <span class="emphasis">linkage-options</span></span></p>
      <p class="para">Here is a summary of the most commonly used options<a onmouseover="DBshowBriefly('fn_fref41_live')" name="fn_fref41" id="fn_fref41" class="footnotemark" href="#fn_fnote41">41</a><div class="footnote_live" id="fn_fref41_live">A note for CygWin users: 
By default, CygWin gcc and g++ produce 
Windows <span class="quote">
      &#8220;console&#8221;
    </span> 
applications ---
applications designed to run from within a shell (<span class="code">bash</span>
or the
Windows command line tool). They can, however, produce GUI
applications with windows, menus, etc., by using <span class="code">-l</span> to link in
the windowing libraries. 
The list of libraries involved is rather long,
so a shortcut option is provided: <span class="code">-mwindows</span>.

<p class="para">Programming windowing code is a fairly involved process. I
suggest getting a library that simplifies this process for
beginners. The 
<a url="http://www.objectcentral.com" href="http://www.objectcentral.com">V library</a>
is a good choice, and has the additional advantage that code written
for use with V can be compiled to produce either Microsoft Windows or
Unix X windows programs.</p></div>
 for gcc/g++:
<p class="para" align="center"><table border="1" width="75%"><tr xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML"><th colspan="2">Compilation Flags</th></tr><tr xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML"><td><span class="emphasis-bold" role="bold">-c</span></td><td>compile only, do not link </td></tr><tr xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML"><td><span class="emphasis-bold" role="bold">-o <span class="emphasis-italic" role="italic">filename</span></span></td><td>Use <span class="emphasis-italic" role="italic">filename</span> as the name of the compiled
program </td></tr><tr xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML"><td><span class="emphasis-bold" role="bold">-D<span class="emphasis-italic" role="italic">symbol</span>=<span class="emphasis-italic" role="italic">value</span></span></td><td>Define <span class="emphasis-italic" role="italic">symbol</span> during compilation. </td></tr><tr xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML"><td><span class="emphasis-bold" role="bold">-g</span></td><td>Include debugging information in compiled code (required if you
want to be able to run the gdb debugger. </td></tr><tr xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML"><td><span class="emphasis-bold" role="bold">-O</span></td><td>Optimize the compiled code (produces smaller, faster programs but
takes longer to compile) </td></tr><tr xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML"><td><span class="emphasis-bold" role="bold">-I <span class="emphasis-italic" role="italic">directory</span></span></td><td>Add <span class="emphasis-italic" role="italic">directory</span> to the list of places
searched when a ``system'' include (<span class="code">#include &#8230;</span>) is
encountered. </td></tr><tr xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML"><th colspan="2">Linkage Flags</th></tr><tr xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML"><td><span class="emphasis-bold" role="bold">-L <span class="emphasis-italic" role="italic">directory</span></span></td><td>Add <span class="emphasis-italic" role="italic">directory</span> to the list of places
searched for pre-compiled libraries. </td></tr><tr xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML"><td><span class="emphasis-bold" role="bold">-l<span class="emphasis-italic" role="italic">libname</span></span></td><td>Link with the precompiled library <span class="code">lib<span class="emphasis-italic" role="italic">libname</span>.a</span> </td></tr></table></p>
</p>
    <div name="fn_fnote40" id="fn_fnote40" class="footnote">40. Zeil's 1st Rule of Debugging: Never
remove debugging output. Just make it conditional. If you remove it, you're
bound to want it again later.

<p class="para">Zeil's 2nd Rule of Debugging: Never leave your debugging code
active when you submit your programs for grading. If the grader is
using an automatic program to check the correctness of the output,
unexpected output will make your program fail the tests. On the other
hand, if the grader is reading the output to check its correctness,
wading through extra output really ticks the grader off!</p> (<a href="#fn_fref40">back</a>)
    </div><div name="fn_fnote41" id="fn_fnote41" class="footnote">41. A note for CygWin users: 
By default, CygWin gcc and g++ produce 
Windows <span class="quote">
      &#8220;console&#8221;
    </span> 
applications ---
applications designed to run from within a shell (<span class="code">bash</span>
or the
Windows command line tool). They can, however, produce GUI
applications with windows, menus, etc., by using <span class="code">-l</span> to link in
the windowing libraries. 
The list of libraries involved is rather long,
so a shortcut option is provided: <span class="code">-mwindows</span>.

<p class="para">Programming windowing code is a fairly involved process. I
suggest getting a library that simplifies this process for
beginners. The 
<a url="http://www.objectcentral.com" href="http://www.objectcentral.com">V library</a>
is a good choice, and has the additional advantage that code written
for use with V can be compiled to produce either Microsoft Windows or
Unix X windows programs.</p> (<a href="#fn_fref41">back</a>)
    </div></div>
  <div name="fn_fnote38" id="fn_fnote38" class="footnote">38. Actually, <span class="code">gcc</span> and <span class="code">g++</span> are the 
same compiler being invoked with slightly different options. (<a href="#fn_fref38">back</a>)
    </div></div><div class="sect4" id="errmsgs"><div class="info_sect4"><div class="title_sect5">7.1.1.2. Error Messages</div></div><div class="TOC">Contents:<div class="TOC-section4"><a href="#capturing">7.1.1.2.1 Capturing the Error Messages</a></div><div class="TOC-section4"><a href="#understanding">7.1.1.2.2 Understanding the Error Messages</a></div></div>
    
    <p class="para">
Unfortunately, once you start writing your own code, you will almost
certainly make some mistakes and get some error messages from the
compiler.</p>
    <p class="para">This is likely to lead to two problems: reading the messages, and
understanding the messages.</p>
    <div class="sect5" id="capturing"><div class="info_sect5"><div class="title_sect6">Capturing the Error Messages</div></div>
      
      <p class="para">Unless you are a far better programmer than I, you will not only get
error messages, you will get so many that they overflow your
telnet/xterm window.</p>
      <p class="para">How you handle this problem depends upon what command shell you are
running, but there are two general approaches. You can use redirection
and pipes to send the error messages somewhere more convenient, or you
can use programs that try to capture all output from a running program
(i.e., the compiler).</p>
      <p class="para">We've talked before about how many Unix commands are <span class="quote">
      &#8220;filters&#8221;
    </span>,
working from a single input stream and producing a single output stream.
Actually, there are 3 standard streams in most operating systems: standard
input, standard output, and standard error.  These generally default
to the keyboard for standard input and the screen for the other two,
unless either the program or the person running the program
redirects one or more of these streams to a file or pipes the stream
to/from another program.</p>
      <p class="para">
        <div class="orderedlist"><ol><li>Pipes and redirection

          <p class="para">We introduced pipes and redirection <a href="../redirection/">earlier</a>.
The complicating factor here is that what you want to pipe or redirect
is not the standard output stream, but the standard error stream.  So,
for example, doing something like
<div class="programlisting">
  g++ myprogram.cpp &gt; compilation.log
</div>
or
<div class="programlisting">
  g++ myprogram.cpp | more
</div>
won't work, because these commands are only redirecting the standard
output stream.   The error messages will continue to blow on by.</p>

<p class="para">How you pipe or redirect the standard error stream depends on the
shell you are running:
<div class="variablelist"><dl><dt class="varlistentry"><span class="term">Unix, running C-shell or TC-shell</span></dt><dd class="varlistitem">  The <span class="code">&gt;</span> and <span class="code">|</span>
symbols can be modified to affect the standard error stream by
appending a '&amp;' character. So these commands do work: 
<div class="programlisting">
  g++ myprogram.cpp &gt;&amp; compilation.log
  g++ myprogram.cpp |&amp; more
</div>
A useful program in this regard is <span class="code">tee</span>, which copies its standard
input both into the standard output  and into a named file: 
<div class="programlisting">
  g++ myprogram.cpp |&amp; tee compilation.log
</div></dd><dt class="varlistentry"><span class="term">Win98/98/NT, running bash</span></dt><dd class="varlistitem">  The sequence "<span class="code">2&gt;&amp;1</span>" in a
command means "force the standard error to go wherever the standard
output is going".  So we can do any of the following: 
<div class="programlisting">
  g++ myprogram.cpp 2&gt;&amp;1 &gt; compilation.log
  g++ myprogram.cpp 2&gt;&amp;1 | more
</div>
and we can still use <span class="code">tee</span>:
<div class="programlisting">
  g++ myprogram.cpp 2&gt;&amp;1 | tee compilation.log
</div></dd></dl></div></p></li><li>Capturing compiler output

<p class="para">There are other ways to capture the output of a compiler (or of any
running program).   You can <a href="../emacscompile/">run the compiler
within the emacs editor</a>, which then gives you a simple
command to move from error message to error message, automatically
bringing up the source code file on the line cited in the error
message. This works with both the Unix and the
MS Windows ports of 
emacs, and is the technique I use myself. 
<span class="code">vim</span>, the <span class="quote">
      &#8220;vi improved&#8221;
    </span> editor will do the same.</p>

<p class="para">
Finally, in Unix there is a command called "<span class="code">script</span>" that causes all
output to your screen to be captured in a file. Just say 
<div class="programlisting">
   script log.txt
</div>
and all output to your screen will be copied into log.txt until you say
<div class="programlisting">
   exit
</div>
<span class="code">script</span> output can be kind of ugly, because it includes all the control
characters that you type or that your programs use to control
formatting on the screen, but it's still useful.<a onmouseover="DBshowBriefly('fn_fref42_live')" name="fn_fref42" id="fn_fref42" class="footnotemark" href="#fn_fnote42">42</a><div class="footnote_live" id="fn_fref42_live">In
particular, if you
ever want to capture both the output of some program AND the stuff you
typed to produce that output (e.g., so you can send it in an e-mail to
someone saying "what am I doing wrong here?"), then <span class="code">script</span> is the way
to go.</div> </p></li></ol></div>
      </p>
    <div name="fn_fnote42" id="fn_fnote42" class="footnote">42. In
particular, if you
ever want to capture both the output of some program AND the stuff you
typed to produce that output (e.g., so you can send it in an e-mail to
someone saying "what am I doing wrong here?"), then <span class="code">script</span> is the way
to go. (<a href="#fn_fref42">back</a>)
    </div></div>
    <div class="sect5" id="understanding"><div class="info_sect5"><div class="title_sect6">Understanding the Error Messages</div></div>
      
      <p class="formalpara"><span class="title_formalpara">Cascading: </span></p>
      <p class="para">
One thing to keep in mind is that errors, especially errors in
declarations, can cascade, with one <span class="quote">
      &#8220;misunderstanding&#8221;
    </span> by the
compiler leading to a whole host of later messages. For example, if
you meant to write
<div class="code" axle:cppcode="1"><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">string</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">s</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">;</xhtml:span></div>
but instead wrote
<div class="code" axle:cppcode="1"><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">strng</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">s</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">;</xhtml:span></div>
you will certainly get an error message for the unknown symbol
<span class="code">strng</span>. However, there's also the factor that the compiler really
doesn't know what type <span class="code">s</span> is supposed to be. Often the compiler
will assume that any symbol of unknown type is supposed to be an <span class="code">int</span>.
So every time you
subsequently use <span class="code">s</span> in a <span class="quote">
      &#8220;string-like&#8221;
    </span> manner, e.g.,
<div class="code" axle:cppcode="1"><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">s</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">=</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">s</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">+</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppliteral">"abcdef"</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">;</xhtml:span></div>
or
<div class="code" axle:cppcode="1"><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">string</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">t</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">=</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">s</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">.</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">substring</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">(</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">k</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">,</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">m</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">)</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">;</xhtml:span></div>
the compiler will probably issue further complaints. Sometimes,
therefore, it's best to stop after fixing a few declaration errors and
recompile to see how many of the other messages need to be taken
seriously.</p>
      <p class="formalpara"><span class="title_formalpara">Backtracking: </span></p>
      <p class="para">
A compiler can only report where it <span class="emphasis">detected</span> a problem. Where you
actually <span class="emphasis">committed</span> a mistake may be someplace entirely different.</p>
      <p class="para">The vast majority of error messages that C++ programmers will see are
<div class="itemizedlist"><ul><li>syntax errors (missing brackets, semi-colons, etc.)</li><li>undeclared symbols</li><li>undefined symbols</li><li>type errors (usually <span class="quote">
      &#8220;cannot find a matching function&#8221;
    </span>
complaints)</li><li>const errors</li></ul></div></p>
      <p class="para">Let's look at these from the point of view of the compiler.
<div class="variablelist"><dl><dt class="varlistentry"><span class="term">Syntax errors</span></dt><dd class="varlistitem"> Assume that the compiler has read part, but not
all, of your program. The part that has just been read contains a
syntax error. For the sake of example, let's say you wrote:
<div class="code" axle:cppcode="1"><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">x</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">=</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">y</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">+</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppliteral">2</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">*</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">x</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppcomment">// missing semi-colon</xhtml:span><span class="br"/>
<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" axle:forumAnchor="1"/></div>
Now, when the compiler has read only the first line, it can't tell that
anything is wrong. That's because it is still possible, as far as the
compiler knows, that the next line of source code wil start with a
<span class="quote">
      &#8220;;&#8221;
    </span> or some other valid expression.  So the compiler will <span class="emphasis">never</span>
complain about this line.

<p class="para">If the compiler reads another line, and discovers that you had
written:
<div class="code" axle:cppcode="1"><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">x</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">=</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">y</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">+</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppliteral">2</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">*</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">x</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppcomment">// missing semi-colon</xhtml:span><span class="br"/>
<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" axle:forumAnchor="1"/><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">++</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">i</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">;</xhtml:span><span class="br"/>
<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" axle:forumAnchor="1"/></div>
it still won't conclude that there's a missing semi-colon. For all it
knows, the <span class="quote">
      &#8220;real&#8221;
    </span> mistake might be that you meant to type <span class="quote">
      &#8220;+&#8221;
    </span>
instead of <span class="quote">
      &#8220;++&#8221;
    </span>.</p>

<p class="para">Now, things can be much worse. Suppose that inside a file <span class="code">foo.h</span> you
write
<div class="code" axle:cppcode="1"><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppkeyword">class</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">Foo</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">{</xhtml:span><span class="br"/>
<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" axle:forumAnchor="1"/>   <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">Foo</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">(</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">)</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">;</xhtml:span><span class="br"/>
<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" axle:forumAnchor="1"/>   <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppkeyword">int</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">f</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">(</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">)</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">;</xhtml:span><span class="br"/>
<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" axle:forumAnchor="1"/>   <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppcomment">// missing };</xhtml:span><span class="br"/>
<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" axle:forumAnchor="1"/></div>
and inside another file, <span class="code">bar.cpp</span>, you write
<div class="code" axle:cppcode="1"><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cpppreproc">#include "foo.h"</xhtml:span><span class="br"/>
<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" axle:forumAnchor="1"/><span class="br"/>
<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" axle:forumAnchor="1"/><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppkeyword">int</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">g</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">(</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">)</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">{</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppkeyword">&#8230;</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">}</xhtml:span><span class="br"/>
<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" axle:forumAnchor="1"/><span class="br"/>
<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" axle:forumAnchor="1"/><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppkeyword">void</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">h</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">(</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">Foo</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">)</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">{</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppkeyword">&#8230;</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">}</xhtml:span><span class="br"/>
<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" axle:forumAnchor="1"/><span class="br"/>
<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" axle:forumAnchor="1"/><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppkeyword">int</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">main</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">(</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">)</xhtml:span>  <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">{</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppkeyword">&#8230;</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">}</xhtml:span><span class="br"/>
<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" axle:forumAnchor="1"/></div>
Where will the error be reported? Probably on the very last line of
<span class="code">bar.cpp</span>! Why? Because until then, it's still possible, as far as
the compiler knows, for the missing <span class="quote">
      &#8220;<span class="code">\</span>;}&#8221;
    </span> to come, in which
case <span class="code">g</span>, <span class="code">h</span>, and <span class="code">main</span> would just be additional member
functions of the class <span class="code">Foo</span>.</p>

<p class="para">So, with syntax errors, you know only that the real mistake occurred
on the line reported <span class="emphasis">or earlier</span>, possibly in an
earlier-<span class="code">#include</span>'d file.</p></dd><dt class="varlistentry"><span class="term">undeclared and undefined symbols</span></dt><dd class="varlistitem"> When you forget to declare or
define a type, variable, funciton, or other symbol, the compiler
doesn't discover that anything is wrong until you try to use the
unknown symbol. That, of course, may be far removed from the pace
where you <span class="emphasis">should</span> have declared it.</dd><dt class="varlistentry"><span class="term">type errors</span></dt><dd class="varlistitem"> When you use the wrong object in an expression or
try to apply the wrong operator/function to an object, the compiler
may detect this as a type mismatch between the function and the
expression supplied as the parameter to that function. These messages
seem to cause students the most grief, and yet the compiler is usually
able to give very precise descriptions of what is going wrong. The
line numbers are usually correct, and the compiler will often tell you
exactly what is going wrong. That explanation, however, may be quite
lengthy, for three reasons:
<div class="orderedlist"><ol><li>Type names, especially when templates are involved, can be very
long and messy-looking.</li><li>Because C++ allows overloading, there may
be many functions with the same name. The compiler will have to look
at each of these to see if any one matches the parameter types you
supplied. Some compilers report on each function tried, explaining why
it didn't match the parameters in the faulty call.</li><li>If the function call was itself produced by a template
instantiation or an inline function, then the problem is detected at
the function call 
(often inside a C++ standard library routine) but the actual problem
lies at the place where the template was used/instantiated. So most
compilers will list both the line where the error was detected and all
the lines where templates were instantiated that led to the creation
of the faulty call.</li></ol></div>
So, to deal with these, look at the error message on the faulty function
call. Note what function/operator name is being complained about. Then
look at the line where the faulty call occurred. If it's inside a
template or inline function that is not your own code, look back
through the <span class="quote">
      &#8220;instantiated from&#8221;
    </span> or <span class="quote">
      &#8220;called from&#8221;
    </span> lines until you
get back into your own code. That's probably where the problem lies.

<p class="para">Here's an example taken from a student's code:
<div class="screen">
g++ -g -MMD -c testapq.cpp
/usr/local/lib/gcc-lib/sparc-sun-solaris2.7/2.95.2/../../../../include/g++-3/
stl_relops.h: In function `bool operator &gt;&lt;_Rb_tree_iterator&lt;pair&lt;const 
 PrioritizedNames,int&gt;,pair&lt;const PrioritizedNames,int&gt; &amp;,pair&lt;const 
 PrioritizedNames,int&gt; *&gt; &gt;(const _Rb_tree_iterator&lt;pair&lt;const 
 PrioritizedNames,int&gt;,pair&lt;const PrioritizedNames,int&gt; &amp;,pair&lt;const 
 PrioritizedNames,int&gt; *&gt; &amp;, const _Rb_tree_iterator&lt;pair&lt;const 
 PrioritizedNames,int&gt;,pair&lt;const PrioritizedNames,int&gt; &amp;,pair&lt;const 
 PrioritizedNames,int&gt; *&gt; &amp;)':
adjpq.h:234:   instantiated from `adjustable_priority_queue&lt;
 PrioritizedNames,map&lt;PrioritizedNames,int,CompareNames,allocator&lt;int&gt; &gt;,
 ComparePriorities&gt;::percolateDown(unsigned int)'
adjpq.h:177:   instantiated from `adjustable_priority_queue&lt;PrioritizedNames,
 map&lt;PrioritizedNames,int,CompareNames,allocator&lt;int&gt; &gt;,
 ComparePriorities&gt;::makeHeap()'
adjpq.h:84:   instantiated from here
 /usr/local/lib/gcc-lib/sparc-sun-solaris2.7/2.95.2/../../../../include/
 g++-3/stl_relops.h:43: no match for `const _Rb_tree_iterator&lt;pair&lt;const 
 PrioritizedNames,int&gt;,pair&lt;const PrioritizedNames,int&gt; &amp;,pair&lt;const 
 PrioritizedNames,int&gt; *&gt; &amp; &lt; const _Rb_tree_iterator&lt;pair&lt;const 
 PrioritizedNames,int&gt;,pair&lt;const PrioritizedNames,int&gt; &amp;,pair&lt;const 
 PrioritizedNames,int&gt; *&gt; &amp;'
</div>
Now, that may look intimidating, but that's mainly because of the long
type names (due to template use) and the long path names to files from
the C++ standard library. Let's strip that down to the essentials:
<div class="screen">
g++ -g -MMD -c testapq.cpp
stl_relops.h: In function `bool operator &gt;:
adjpq.h:234:   instantiated from `percolateDown(unsigned int)'
adjpq.h:177:   instantiated from `makeHeap()'
adjpq.h:84:   instantiated from here
stl_relops.h:43 no match for ... &lt; ...
</div>
(This one is actually worse than most error messages, becuase it's
easy to miss the <span class="quote">
      &#8220;<span class="code">&lt;</span>&#8221;
    </span> operator amist all the <span class="code">&lt;&#8230;&gt;</span>
template markers.)</p>

<p class="para">The problem is a <span class="quote">
      &#8220;no match for&#8221;
    </span> a less-than operator call in line 43
of a template within the standard library file <span class="code">stl<span class="emphasis"><span class="code">&lt;under&gt;</span><span class="code">&lt;/under&gt;</span></span>relops.h</span>.
But that template is
instantiated from the student's own code (adjpq.h) and so the thing to
do is to look at those three lines (234, 177, and 84) for a data type
that is supposed to support a less-than operator, but doesn't.</p></dd><dt class="varlistentry"><span class="term">const errors</span></dt><dd class="varlistitem"> Technically, <span class="quote">
      &#8220;const&#8221;
    </span>-ness is part of a type, so
while sometimes these get special messages of their own, often they
masquerade as ordinary type errors and must be interpreted in the same way.</dd></dl></div></p>
    </div>
  </div><div class="sect4" id="javacomp"><div class="info_sect4"><div class="title_sect5">7.1.1.3. Compiling Java in the Shell (Optional)</div></div>
    
    <p class="para">Java programs get compiled into object code for an imaginary CPU
called the <span class="quote">
      &#8220;Java Virtual Machine&#8221;
    </span> (JVM). Consequently, you can't
execute compiled Java code directly. You must run a program that
simulates a JVM and let that simulated computer execute the Java code.</p>
    <p class="para">That may seem a little convoluted, but the JVM simulator is easier to
write than a <span class="quote">
      &#8220;true&#8221;
    </span> compiler. Consequently, JVM simulators can be
built into other programs (such as web browsers), allowing Java code
compiled on one machine to be executed on almost any other machine. By
contrast, a true native-code compiler (e.g., g++) produces executables
that can only be run on a single kind of computer.</p>
    <p class="para">The command to compile Java code is <span class="quote">
      &#8220;<span class="code">javac</span>&#8221;
    </span> (<span class="quote">
      &#8220;c&#8221;
    </span> for
compiler) and the command to execute compiled Java code is
<span class="quote">
      &#8220;<span class="code">java</span>&#8221;
    </span>. So a typical sequence to compile and execute a
single-file Java program would be
<div class="screen"><span class="userinput">
javac -g MyProgram.java
java MyProgram
</span></div>
Unlike most programming languages, Java includes some important
restrictions on the file names used to store source code. 
<div class="itemizedlist"><ul><li>Java source code is stored in files ending with the extension
<span class="quote">
      &#8220;<span class="code">.java</span>&#8221;
    </span>.</li><li>Each Java source code file must contain exactly one public class
declaration. </li><li>The base name of the file (the part before the extension) must
be the same (including upper/lower case characters) as the name of the
public class it contains.</li></ul></div>
So the command
<div class="screen"><span class="userinput">
javac -g MyProgram.java
</span></div>
compiles a file that must contain the code:
<div class="code" axle:cppcode="1"><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppkeyword">public</xhtml:span><span class="br"/>
<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" axle:forumAnchor="1"/><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppkeyword">class</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">MyProgram</xhtml:span> ..<span class="br"/>
<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" axle:forumAnchor="1"/></div>
The output of this compilation will be a file named
<span class="code">MyProgram.class</span> (and possibly some other <span class="code">.class</span> files as
well).</p>
    <p class="para">If we have a program that consists of multiple files, we can simply
compile each file in turn:
<div class="screen"><span class="userinput">
javac -g MyProgram.java
javac -g MyADT.java
</span></div>
but this might not be necessary. If one Java file imports another,
then the imported file will be automatically compiled if no
<span class="code">.class</span> file for it exists.</p>
    <p class="para">So, if the file <span class="code">MyProgram.java</span> looked like this
<div class="code" axle:cppcode="1"><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">import</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">MyADT</xhtml:span><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppop">;</xhtml:span><span class="br"/>
<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" axle:forumAnchor="1"/><span class="br"/>
<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" axle:forumAnchor="1"/><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppkeyword">public</xhtml:span><span class="br"/>
<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" axle:forumAnchor="1"/><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppkeyword">class</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppid">MyProgram</xhtml:span> ..<span class="br"/>
<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" axle:forumAnchor="1"/></div>
then compiling <span class="code">MyProgram.java</span> would also compile <span class="code">MyADT.java</span>.<a onmouseover="DBshowBriefly('fn_fref43_live')" name="fn_fref43" id="fn_fref43" class="footnotemark" href="#fn_fnote43">43</a><div class="footnote_live" id="fn_fref43_live">Beware, however, after the first compilation. <span class="code">javac</span>
by default only checks to see if an appropriately named <span class="code">.class</span>
file exists. If you subsequently make changes to <span class="code">MyADT.java</span> and then
recompile <span class="code">MyProgram.java</span>, the compiler will not realize that
<span class="code">MyADT.java</span> needs to be recompiled as well.</div></p>
    <p class="para">Java programs come in two forms: applets and applications. Applets are
placed on web servers and can be launched from HTML web pages so that
the Java code runs whenever someone browses that page. Applications,
on the other hand, are more like traditional programs that get invoked
directly by the user.</p>
    <p class="para">To run a Java application, we use <span class="code">java</span>:
<div class="screen"><span class="userinput">
java MyProgram
</span></div>
which looks for a file named <span class="code">MyProgram.class</span>. Within that file,
it looks for a compiled version of a function <span class="code">Main</span> that must have
been declared this way:
<div class="code" axle:cppcode="1"><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppkeyword">public</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppkeyword">static</xhtml:span> <span class="br"/>
<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" axle:forumAnchor="1"/><xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:parsetree="http://chaperon.sourceforge.net/schema/syntaxtree/2.0" class="cppkeyword">void</xhtml:span> <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:m="http://www.w3