mirror of https://github.com/tLDP/LDP
updated
This commit is contained in:
parent
13d582f323
commit
7f456a625d
|
@ -42,7 +42,7 @@ C++ Programming HOW-TO
|
|||
<author>Al Dev (Alavoor Vasudevan)
|
||||
<htmlurl url="mailto:alavoor@yahoo.com"
|
||||
name="alavoor@yahoo.com">
|
||||
<date>v26.0, 18 Dec 2000
|
||||
<date>v27.0, 26 Dec 2000
|
||||
<abstract>
|
||||
This document discusses methods to avoid memory problems in C++ and
|
||||
also will help you to program properly in C++ language.
|
||||
|
@ -1419,36 +1419,45 @@ click on Open Books.
|
|||
-->
|
||||
<sect> C++ Coding Standards
|
||||
<p>
|
||||
Coding standard is very essential for readability and maitainence of programs. The GNU
|
||||
C++ compiler <bf>must enforce</bf> coding discipline. The following is suggested :
|
||||
Coding standard is very essential for readability and maitainence of programs. And
|
||||
it also greatly inproves the productivity of the programmer. The GNU
|
||||
C++ compiler <bf>must enforce</bf> coding discipline. The following is suggested -
|
||||
inside class definition:
|
||||
<itemize>
|
||||
<item> All public variables must begin with any m like <bf>mFooVar</bf>
|
||||
<item> All protected variables must begin with mt, like <bf>mtFooVar</bf> and methods with t
|
||||
<item> All private variables must begin with mv, like <bf>mvFooVar</bf> and methods with v
|
||||
<item> All public, protected and private variables must begin with uppercase after m like F in <bf>mFooVar</bf>
|
||||
<item> All public variables must begin with <bf>m</bf> like <bf>mFooVar</bf>.
|
||||
The <bf>m</bf> stands for <it>member</it>.
|
||||
<item> All protected variables must begin with <bf>mt</bf>,
|
||||
like <bf>mtFooVar</bf> and methods with t, like <bf>tFooNum()</bf>.
|
||||
The <bf>t</bf> stands for <it>protected</it>.
|
||||
<item> All private variables must begin with <bf>mv</bf>, like <bf>mvFooVar</bf> and
|
||||
methods with v, like <bf>vFooLone()</bf>. The <bf>v</bf> stands for <it>private</it>.
|
||||
<item> All public, protected and private variables must begin with
|
||||
uppercase after <bf>m</bf> like F in <bf>mFooVar</bf>.
|
||||
<item> All pointer variables must be prefixed with p, like
|
||||
<itemize>
|
||||
<item>Public variables <bf>pFooVar</bf>
|
||||
<item>Protected variables <bf>mtpFooVar</bf> and methods with t
|
||||
<item>Private variables <bf>mvpFooVar</bf> and methods with v
|
||||
<item>Public variables <bf>mpFooVar</bf> and methods like FooNum()
|
||||
<item>Protected variables <bf>mtpFooVar</bf> and methods with t like tFooNum()
|
||||
<item>Private variables <bf>mvpFooVar</bf> and methods with v like vFooNum()
|
||||
</itemize>
|
||||
</itemize>
|
||||
The compiler should generate error if the code does not follow standard.
|
||||
The compiler should generate error if the code does not follow above standard.
|
||||
The C++ compiler can provide a flag option to bypass strict coding standard to compile
|
||||
old source code, and for all new code being developed will follow the
|
||||
uniform world-wide coding standard.
|
||||
|
||||
In sample code given below <bf>t</bf> stands for <bf>protected</bf>,
|
||||
In the sample code given below <bf>t</bf> stands for <bf>protected</bf>,
|
||||
<bf>v</bf> stands for <bf>private</bf>,
|
||||
<bf>m</bf> stands for <bf>member-variable</bf> and
|
||||
<bf>p</bf> stands for <bf>pointer</bf>.
|
||||
<code>
|
||||
class SomeFunName
|
||||
class SomeFunMuncho
|
||||
{
|
||||
public:
|
||||
int mZimboniMacho;
|
||||
float *mpArrayNumbers;
|
||||
int mTempZimboniMacho; // Only temporary variables should be public as per OOP
|
||||
float *mpTempArrayNumbers;
|
||||
int HandleError();
|
||||
float getBonyBox(); // Public accessor as per OOP design
|
||||
float setBonyBox(); // Public accessor as per OOP design
|
||||
protected:
|
||||
float mtBonyBox;
|
||||
int *mtpBonyHands;
|
||||
|
@ -1462,19 +1471,32 @@ class SomeFunName
|
|||
int vGetNumbers();
|
||||
};
|
||||
</code>
|
||||
When your program grows by millions of lines of code, then you will greatly
|
||||
appreciate the naming convention as above. The readability of code improves,
|
||||
because just by looking at the variable name like <bf>mvFirstName</bf> you can
|
||||
tell that it is member of a class and is a private variable.
|
||||
|
||||
Visit the C++ Coding Standards URLs
|
||||
<itemize>
|
||||
<item> C++ FAQ Lite - Coding standards <url url="http://new-brunswick.net/workshop/c++/faq/coding-standards.html">
|
||||
<item> Rice univ <url url="http://www.cs.rice.edu/~dwallach/CPlusPlusStyle.html">
|
||||
<item> C++ coding standard <url url="http://www.cs.umd.edu/users/cml/cstyle/CppCodingStandard.html">
|
||||
<item> Rice university coding standard <url url="http://www.cs.rice.edu/~dwallach/CPlusPlusStyle.html">
|
||||
<item> Identifiers to avoid in C++ Programs <url url="http://oakroadsystems.com/tech/cppredef.htm">
|
||||
<item> Coding standards from Possibility <url url="http://www.possibility.com/Cpp/CppCodingStandard.html">
|
||||
<item> Coding standards from Ambysoft <url url="http://www.ambysoft.com/javaCodingStandards.html">
|
||||
|
||||
and <url name="mirror site" url="http://www.cs.umd.edu/users/cml/cstyle/CppCodingStandard.html">
|
||||
<item> Coding standards for Java and C++ from Ambysoft <url url="http://www.ambysoft.com/javaCodingStandards.html">
|
||||
<item> Rules and recommendations <url url="http://www.cs.umd.edu/users/cml/cstyle/">
|
||||
<item> Indent and annotate <url url="http://www.cs.umd.edu/users/cml/cstyle/indhill-annot.html">
|
||||
<item> Elemental rules <url url="http://www.cs.umd.edu/users/cml/cstyle/Ellemtel-rules.html">
|
||||
<item> C++ style doc <url url="http://www.cs.umd.edu/users/cml/cstyle/Wildfire-C++Style.html">
|
||||
<item> C++ Coding Standards by Brett Scolcum <url url="http://www.skypoint.com/~slocum/prog/cppstds.html">
|
||||
<item> Logikos C++ Coding Standards <url url="http://www.logikos.com/standards/cpp_std.html">
|
||||
<item> NRad C++ coding standards <url url="http://cadswes.colorado.edu/~billo/standards/nrad">
|
||||
<item> BEJUG C++ coding standards <url url="http://www.meurrens.org/ip-Links/java/joodcs/ToddHoff.html">
|
||||
<p>
|
||||
See also
|
||||
<item> For rapid navigation with ctags
|
||||
<url name="Vim color text editor" url="http://metalab.unc.edu/LDP/HOWTO/Vim-HOWTO.html">
|
||||
<item> To improve productivity see <url name="C++ Beautifier HOWTO" url="http://metalab.unc.edu/LDP/HOWTO/C-C++Beautifier-HOWTO.html">
|
||||
</itemize>
|
||||
<!--
|
||||
*******************************************
|
||||
|
@ -1648,12 +1670,12 @@ Mirror at: <url url="http://www.mike95.com/c_plusplus/tutorial/templates">
|
|||
<url url="http://www.dgp.toronto.edu/people/JamesStewart/270/9697f/notes/Nov25-tut.html">
|
||||
<p>
|
||||
|
||||
<item> Very GOOD site!! good site:
|
||||
<item> Very GOOD site:
|
||||
<url url="http://www.cplusplus.com/doc/tutorial/tut5-1.html">
|
||||
<url url="http://www.cplusplus.com/doc/tutorial">
|
||||
<p>
|
||||
|
||||
<item> very good for certification of C++: goto <url url="http://examware.com"> and click on "Tutorials" and then C/C++ button
|
||||
<item> For certification of C++: goto <url url="http://examware.com"> and click on "Tutorials" and then C/C++ button
|
||||
<p>
|
||||
|
||||
<item> C++ Open books: <url url="http://www.softpanorama.org/Lang/cpp.shtml">
|
||||
|
@ -2955,9 +2977,10 @@ and at <url url="http://www.strangecreations.com/library/snippets" name="snippet
|
|||
-->
|
||||
<sect> Other Formats of this Document
|
||||
<p>
|
||||
This document is published in 11 different formats namely - DVI, Postscript,
|
||||
This document is published in 12 different formats namely - DVI, Postscript,
|
||||
Latex, Adobe Acrobat PDF,
|
||||
LyX, GNU-info, HTML, RTF(Rich Text Format), Plain-text, Unix man pages and SGML.
|
||||
LyX, GNU-info, HTML, RTF(Rich Text Format), Plain-text, Unix man pages,
|
||||
single HTML file and SGML.
|
||||
<itemize>
|
||||
<item>
|
||||
You can get this HOWTO document as a single file tar ball in HTML, DVI,
|
||||
|
@ -3094,6 +3117,7 @@ You can <bf>download all programs as a single tar.gz</bf> file from
|
|||
<ref id="Download String">
|
||||
and give the following command to unpack
|
||||
<code>
|
||||
bash$ man tar
|
||||
bash$ tar ztvf C++Programming-HOWTO.tar.gz
|
||||
This will list the table of contents
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ LILO, Linux Crash Rescue HOW-TO
|
|||
<author>Al Dev (Alavoor Vasudevan)
|
||||
<htmlurl url="mailto:alavoor@yahoo.com"
|
||||
name="alavoor@yahoo.com">
|
||||
<date>v5.0, 05 Dec 2000
|
||||
<date>v6.0, 25 Dec 2000
|
||||
<abstract>
|
||||
This document discusses methods to recover from Linux system failures.
|
||||
Various reasons for linux system failures can be -
|
||||
|
@ -99,7 +99,8 @@ Follow these steps to recover from LILO or system failures.
|
|||
root partition by doing this -
|
||||
<code>
|
||||
bash# fdisk /dev/hda
|
||||
bash# mkdir /dev/hda1 /test
|
||||
bash# mkdir /test
|
||||
bash# mount /dev/hda1 /test
|
||||
bash# ls /test
|
||||
You should see root-partition list like this -
|
||||
bin fd lib mnt proc sbin usr
|
||||
|
@ -107,16 +108,17 @@ boot dev etc home lost+found opt root tmp var
|
|||
</code>
|
||||
If this is not a root partition, then try the next partition /dev/hda2.
|
||||
Next try hda3, hda4, hda5, etc.. untill you find the root partition.
|
||||
Still not found then repeat for other devices like hdb, hdc, hdd etc..
|
||||
Still not found in <bf>hda</bf> then repeat the above steps for other devices
|
||||
like <bf>hdb</bf>, <bf>hdc</bf>, <bf>hdd</bf> etc..
|
||||
Also the /usr, /var, and /boot partition are needed as these are
|
||||
required to create new lilo configuration.
|
||||
|
||||
In my case the root partition is /dev/hda4 which is used in examples below:
|
||||
In my case the root partition is /dev/hda4 which is used in the examples below:
|
||||
<code>
|
||||
bash# mkdir /hda4
|
||||
bash# mount /dev/hda4 /hda4
|
||||
bash# cat /hda4/etc/fstab
|
||||
Read the output of fstab and mount partitions as below -
|
||||
Read the output of fstab and mount partitions as per fstab file, see below -
|
||||
bash# mount /dev/hda5 /hda4/boot
|
||||
bash# mount /dev/hda6 /hda4/usr
|
||||
bash# mount /dev/hda7 /hda4/var
|
||||
|
@ -124,9 +126,12 @@ bash# mount /dev/hda8 /hda4/opt
|
|||
bash# mount /dev/hda9 /hda4/root
|
||||
bash# mount /dev/hda10 /hda4/home
|
||||
</code>
|
||||
In my case, as per fstab file hda5 was boot, hda6 was usr, hda7 was var, hda8 was opt,
|
||||
hda9 was root, hda10 was home and hda11 was windows95 directory.
|
||||
|
||||
Edit /etc/fstab (not /hda4/etc/fstab) and put (sample code given here) -
|
||||
<code>
|
||||
/dev/hda4 /hda4 ext2 defaults 1 1
|
||||
/dev/hda5 /hda4/boot ext2 defaults 1 1
|
||||
/dev/hda6 /hda4/usr ext2 defaults 1 1
|
||||
/dev/hda7 /hda4/var ext2 defaults 1 1
|
||||
|
@ -134,22 +139,22 @@ Edit /etc/fstab (not /hda4/etc/fstab) and put (sample code given here) -
|
|||
/dev/hda9 /hda4/root ext2 defaults 1 1
|
||||
/dev/hda10 /hda4/home ext2 defaults 1 1
|
||||
/dev/hda11 /hda4/win95part vfat defaults 1 1
|
||||
On my computer hda4 contains the linux boot/root partition and
|
||||
|
||||
On my computer hda4 contains the linux root partition, hda5 had boot partition and
|
||||
hda11 has windows 95 vfat system.
|
||||
|
||||
bash# mkdir /hda4/win95part
|
||||
bash# mount /hda4/win95part
|
||||
And repair the system using fsck or e2fsck commands.
|
||||
And repair the system using fsck or e2fsck commands.
|
||||
bash# man fsck
|
||||
bash# man e2fsck
|
||||
</code>
|
||||
<p>
|
||||
<item> <bf>SCENE 2:</bf> If LILO is not working..
|
||||
<p>
|
||||
Follow scene 1 above, if that fails then
|
||||
Follow scene 1 above, if that fails then follow these steps. Now you should have
|
||||
already mounted /hda4 and have created /etc/fstab file.
|
||||
<code>
|
||||
bash# mkdir /hda4
|
||||
bash# mount /hda4
|
||||
bash# mount -a
|
||||
bash# chroot /hda4 /sbin/lilo -q
|
||||
bash# man chroot
|
||||
|
@ -157,7 +162,7 @@ bash# chroot /hda4 /sbin/lilo
|
|||
</code>
|
||||
Alternatively, you can directly use /sbin/lilo instead of chroot. The
|
||||
-r option of lilo actually does chroot.
|
||||
It is very strongly recommended that you use chroot, instead of lilo -r,
|
||||
It is very <bf>strongly recommended</bf> that you use chroot, instead of lilo -r,
|
||||
as it is more convenient and can catch errors more easily.
|
||||
<code>
|
||||
bash# man lilo
|
||||
|
@ -188,17 +193,24 @@ bash# mkbootdisk /dev/fd0
|
|||
Make sure you move the /etc/lilo-original.conf back to /etc/lilo.conf!! And
|
||||
then take this floppy and goto scene 3
|
||||
<p>
|
||||
<item> <bf>SCENE 5: </bf>If scenes 1, 2, 3 and 4 above fails then
|
||||
<item> <bf>SCENE 5: </bf> This is the worst scenerio, hopefully you do not come to this
|
||||
stage. Scenes from 1 to 4 take care of majority of cases. But in case above
|
||||
scenes 1, 2, 3 and 4 all fail then -
|
||||
<p>
|
||||
<it><bf>Step 1: </bf></it>
|
||||
Boot tomsrtbt and mount the partitions and backup the root
|
||||
partition to another partition having disk space with comamnds -
|
||||
<code>
|
||||
Edit /etc/fstab and put (sample code given here) -
|
||||
/dev/hdb1 /b1 vfat defaults 1 1
|
||||
Edit /etc/fstab and put (sample code given here, you may have to
|
||||
change as per your disk layout) -
|
||||
/dev/hda4 /hda4 ext2 defaults 1 1
|
||||
/dev/hda11 /b1 vfat defaults 1 1
|
||||
bash$ mkdir /hda4; mount /hda4
|
||||
bash$ mkdir /b1; mount /b1
|
||||
bash$ cd /
|
||||
bash$ tar cvf /b1/root-a4.tar a4
|
||||
bash$ df
|
||||
And see that there is enough disk space in /b1 to tar up the root partition
|
||||
bash$ tar cvf /b1/root-hda4.tar /hda4
|
||||
</code>
|
||||
<p>
|
||||
<it><bf>Step 2: </bf></it>
|
||||
|
@ -218,10 +230,9 @@ bash# cp /etc/lilo.conf /etc/lilo-original.conf
|
|||
bash# mkbootdisk /dev/fd0
|
||||
bash# cp /etc/lilo-original.conf /etc/lilo.conf
|
||||
</code>
|
||||
Take this floppy to problem machine and
|
||||
test this boot floppy to see that this works and then
|
||||
Test this boot floppy to see that this works and then
|
||||
restore back the all the files which you backedup using tar on
|
||||
/b1/root-a4.tar as in step 1 above.
|
||||
/b1/root-hda4.tar as in step 1 above.
|
||||
</enum>
|
||||
<!--
|
||||
*******************************************
|
||||
|
@ -273,7 +284,8 @@ bash# tar cvf /b1/linux-boot-partition-hda1.tar a1/boot
|
|||
-->
|
||||
<sect1> Removing LILO
|
||||
<p>
|
||||
You can replace the boot sector with the DOS boot loader by issuing the DOS command:
|
||||
You can replace the boot sector with the DOS boot loader by issuing the DOS
|
||||
command at MS DOS prompt:
|
||||
<code>
|
||||
FDISK /MBR
|
||||
</code>
|
||||
|
@ -289,7 +301,7 @@ uninstalling the LILO. And see also 'man lilo'.
|
|||
-->
|
||||
<sect1> Common mistakes
|
||||
<p>
|
||||
After making changes to /etc/lilo.conf you MUST run lilo to make changes
|
||||
After making changes to /etc/lilo.conf you <bf>MUST run lilo</bf> to make changes
|
||||
to go in effect. It is a very common mistake committed by newusers. Type -
|
||||
<code>
|
||||
bash# lilo -v -v -v
|
||||
|
@ -337,7 +349,8 @@ Visit following locators which are related to LILO, Rescue Linux, crash recovery
|
|||
<p>
|
||||
This document is published in 11 different formats namely - DVI, Postscript,
|
||||
Latex, Adobe Acrobat PDF,
|
||||
LyX, GNU-info, HTML, RTF(Rich Text Format), Plain-text, Unix man pages and SGML.
|
||||
LyX, GNU-info, HTML, RTF(Rich Text Format), Plain-text, Unix man pages,
|
||||
single HTML file and SGML.
|
||||
<itemize>
|
||||
<item>
|
||||
You can get this HOWTO document as a single file tar ball in HTML, DVI,
|
||||
|
|
|
@ -796,10 +796,10 @@ main(int argc, char **argv)
|
|||
for ( ; fgets(buff, BUFF_LEN, fpin) != NULL; )
|
||||
{
|
||||
char aa[BUFF_LEN + 100];
|
||||
char *aapointer;
|
||||
char aapointer[BUFF_LEN + 100];
|
||||
memset(aa, 0, BUFF_LEN +10);
|
||||
strcpy(aa, buff);
|
||||
aapointer = ltrim(aa);
|
||||
strcpy(aapointer, ltrim(aa));
|
||||
strcpy(aa, aapointer);
|
||||
|
||||
// Remove the trailing new line..
|
||||
|
|
Loading…
Reference in New Issue