C/C ++ encoding specifications-header files

Source: Internet
Author: User

From Google

Http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Classes

1. Use # define to prevent repeated inclusion

If the header file is under the bar of the Project Foo folder and the header file name is Baz. H, it is defined as follows:

#ifndef FOO_BAR_BAZ_H_#define FOO_BAR_BAZ_H_...#endif  // FOO_BAR_BAZ_H_

2. If the pre-declaration can solve the dependency, do not use the header file to include (kiss)

//#include "otherclass.h"//#include "anohterclass.h"class OtherClass;class AnotherClass;class Sample{    OtherClass * m_pOhter;    AnotherClass * m_pAnother;    static OtherClass m_sOther;    const OtherClass & m_other;    void Use(OtherClass po);};

In both cases, you can use the pre-declaration to solve the dependency, because you do not need to know the definition and size of other classes when compiling the sample. Do not include the header file in the header file, unless you have to (inheritance, etc.). Of course, you can include the header file in the. CC file.

3. inline functions

A small inline can reduce the entire size of the program, and vice versa. Suggestion: if there are more than 10 rows of functions, it is better not to inline them. If there are loops and branches in the inline, it is better not to inline, it is not cost-effective.

4,-inL. h header file

Some implementation code can be put here, but do not participate in compilation as CPP alone (only code that is included by some CPP and indirectly involved in compilation can be successful ).

Some C/C ++ coding suggestions for Misra:

Save as (ZIP)

Http://hi.csdn.net/attachment/201202/23/0_13300094632KhX.gif

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.