VC source code encoding

zhaozj2021-02-16  120

VC source code encoding

1 project style

1.1 item name

In the VC, the project name is the last executable file name, so the project name is best consistent with the final executable file name.

1.2 Project Directory Settings

In order to ensure the backup of the VC project, all the items related to all the projects are all under the unified directory, and each project is established under the directory, the public part of the project is built in the public directory. Next, the base library required by the project determines different directories according to the number of basic libraries required, and the project-related test procedures are uniformly placed under the TEST directory. The following table shows a directory setting table for a software engineering PSS system:

The PSS system has two modules PSS_MOD1 and PSS_MOD2, and two modules have part of the shared code. Three test programs PSS_TEST1, PSS_TEST2, PSS_TEST3, and PSS system development processes are written in the engineering development process, and the PSS system development process is used. Then the directory of the system is set as follows:

First class catalog

Secondary directory

Three-level catalog

Note

Work

PSS_MOD1

Debug

Debugging version directory generated by VC integrated environment

RELEASE

VC Integrated Environment Generated Release Directory

RES

VC integrated environment generated resource file directory

Include

The header file of the MOD1

Source

The header file of the MOD2

PSS_MOD2

Debug

Debugging version directory generated by VC integrated environment

RELEASE

VC Integrated Environment Generated Release Directory

RES

VC integrated environment generated resource file directory

Include

The header file of the MOD1

Source

The header file of the MOD2

Public

Include

MOD1 and MOD2 common header files

Source

MOD1 and MOD2 common source code files

Lib

MOD1 and MOD2 public library files

Test

PSS_TEST1

Test item one

PSS_TEST2

Test item three

PSS_TEST3

Test item three

Third_MOD

Third-party public module

1.3 Item directory settings in the integrated environment

Each project is equipped with a relative path setting in the VC-compiled environment, which does not use an absolute path to ensure that it is backup to the disc device or when it is restored to the hard disk, it is directly compiled. Also do not have too many directory searches with a #include statement, as shown below:

#include "../../../somehead.h"

Change to:

#include "headfile.h"

Or #incldue "Dir / Headfile.h"

And pay attention to #include "headfile.h" difference with #include

Then add the directory of the header file in the Project Setting.

1.4 Project Modification Record Tracking

Each VC project must exist in changes.log to record all changes since the project produce, which must be as follows:

Date: 2000/4/28

Modify: **

Modify the topic:

Related modified files: hello.cpp

Modify content detailed description:

You can also make full use of the README.TXT file that Visual C automatically generated to record the item related information.

2 file style

2.1 file generation

The semantics of the file name should be able to summarize what functionality is intended to express the functionality of this file. The file name is expressed in lowercase English letters, which is strictly forbidden to use Chinese; for the file name expressed in several words, the words are separated from the _ symbol.

File name suffix definition:

a. VC automatically generated source file and header suffix are: *. CPP and .h. B. Other source files and header suffixes are: *. Cxx and * .hxx. For specification VC derived classes, try to generate file formats with Class Wizard to avoid manual header files / implement files.

// constructors // Construction

// attributes // attribute, quality, feature, plus,

// Operations // operation, operation, implementation, role, business, work, surgery, military action

// Overridables // overloaded

// Implementation // implementation

Every class has at least one // importation, doing different processing in different positions MFC, the best when writing code

The same consistent with MFC.

2.2 Document Head Note

The header of the file is mainly indicating some of the information of the file, its format is as follows:

///// file name: MANGE_FUN.CXX // Version: // Destination and Main Power: Setting // Creating System Parameters: 1999.09.14 // Modify Date: // Author: *** // Modify By :

2.3 File Specification Function Keys

Source files are written, Visual C provides the Alt F8 function key to make file specifications, often use this button to keep the files (Note, the Alt F8 function key to continuous two case statements will handle errors , Cannot be regulated).

3 function style

3.1 Convention of function names.

The semantics of the function name should reflect the functionality of the function.

The naming rules for the API function are: a. The function will begin in API_LM_; LM indicates that this function is a function of the Lonicra-MDA subsystem, and the function name of the PDM module is starting with API_LP_. B. The latter name is based on a function semantic, such as creating a single function full function named API_LM_ceate_point ().

Naming rules for DI functions: a. Function name = LM _ (Semantic Semantics). B. For a function name expressed in several words, each word is separated from the _ symbol.

3.2 Function Notes

ClassWizard automatically generates functions, such as message response functions, do not have to have much notes and explanations;

For functions written by self, if the system key function, the information of the function must be indicated above the function implementation, the format is as follows:

/ / =========================================================================================================================================================================================== ====================== // Function name: InsureHasoutputInfo // function description: Make sure there is an appropriate output information // input parameters: nProductID: the corresponding product ID // Output parameter: Void // Create Date: 00-2-21 // Modify Date: 00-2-21 // Author: *** // Additional instructions: / / ========= ============================================================================================================================================================================================================= =========== 3.3 Code indent

Each nesting function block uses a Tab indent (can be set to 3 spaces), the braces must be placed next to the conditional statements, alone, easy to match the anti-big brackets should be single, In most cases, the reverse enrollment should have an comment. For example, as follows:

IF (condition1) {while (condition2) {... .. ... ..} // end while (condition2)} // endiff (condition1)

or

IF (condition1) {while (condition2) {.... ... // end while (condition2)} // endiff

3.4 other specifications

1. The function of each source file is not more than 20, and each function should not exceed 120 line original code. 2, the input parameter of the function is not more than 5, and the output parameter is not more than 5. 3. For more than 3 sentences, the statement is repeatedly called, and it should be packaged as function calls. 4, try to avoid the three-layer nesting cycle; minimize the IF statement of the program; use a statement that is difficult to understand such as I * = B, A = C D * B . 5, make full use of C ideas, truly use C language to program; the class expansion member function.

4 variable style

The variable is trying to use Hungarian nomenclature, combined with the principle of VC; in general, the variable is named:

. Range prefix _, type prefix _, limit words.

Special type name, prefix representation: class, interface

Prefix

Types of

example

Note

LM

Class

LmObject

Indicates that the type itself is not used in combination with the range prefix.

I

Interface interface

Iunknown

Note: The class prefix is ​​changed to LM, and the non-global class is best to represent the module. The instance name of the class is approximately the same, just that the class name semantic represents the generic meaning of the class, and the class name represents the specific semantics of this instance. If the class lmsketpoint represents the class definition of the sketch point, and its two instances _startpoint, _endpoint represent the semantics of the start and end points, respectively. The instance of the class is named on a prefix. Special agreement: a. MouseTool's prefix is ​​_mt. B. The prefix of the dialog class is CDLG. C. The prefix of the eraser is _rb.

Range prefix:

Prefix

Types of

example

Note

g_

Global role domain

g_servers

M_

Member variables

M_PDOC,

l_

Local role domain

L_StrName

use less

Note: Try to use the full variable when programming, and add the following keywords for the full range of variables:

Feature Module: FEA Sketch Module: Sket Assembly Module: ASM Project Module: Lay Surface Module: SURF Interface Module: UI

Type prefix 1 ,:

Commonly used general data type prefix representation (this is only part)

Prefix

Types of

Memory specification description

example

CH

charr

8-bit character

Chgrade

CH

TCHAR

16-bit character if _unicode is defined

Chname

B

Bool

Boolean Value

Benabled

n

int

Integer (Size Dependent On ON Operating System)

NLENGTH

n

Uint

Unsigned value (Size Dependent On ON ON ON ON OPERATING SYSTEM)

NLENGTH

w

Word

16-bit unsigned value

WPOS

l

Long

32-bit signed integer

Loffset

DW

DWORD

32-bit unsigned integer

DwRange

p

*

Ambient Memory Model Pointer

PDOC

LP

Far *

Far Pointer

LPDOC

LPSZ

LPSTR

32-Bit Pointer to Character String

lpszname

LPSZ

LPCSTR

32-Bit Pointer to Constant Character String

lpszname

LPSZ

LPCTSTR

32-Bit Pointer to Constant Character String IF_Unicode is defined

lpszname

hide

Handle

Handle to Windows Object

HWnd

lpfn

(* fn) ()

Callbackfar Pointer to Callback Function

LPFNABORT

Common use of Windows object name abbreviations:

These names are abbreviated in many cases directly, and the names of the variable are directly used.

Windows object

Example variable

MFC class

Example object

HWnd

HWnd;

CWND *

PWND;

HDLG

HDLG;

CDIALOG *

PDLG;

HDC

HDC;

CDC *

PDC;

HgDiobj

HgDiobj;

CGDIObject *

PgDiobj;

HPEN

HPEN

CPEN *

Ppen;

Hbrush

Hbrush;

CBRUSH *

PBRUSH;

Hfont

HFont;

Cfont *

PFont;

Hbitmap

Hbitmap;

CBitmap *

Pbitmap;

HPALETTE

HPALETTE;

CPALETTE *

PPALETTE;

HRGN

HRGN;

CRGN *

PRGN;

Hmenu

HMENU;

Cmenu *

PMenu;

HWnd

HCTL;

CSTATIC *

PSTATIC;

HWnd

HCTL;

CButton *

PBTN;

HWnd

HCTL;

Cedit *

Pedit;

HWnd

HCTL;

Clistbox *

Plistbox;

HWnd

HCTL;

CCOMBOBOX *

PCOMBOBOX;

Other macro definitions

It is recommended to use uppercase letters and separated by underscore. Visual C common macro defined list:

Prefix

Symbol type

Symbolic example

range

IDR_

Logo the type of multiple resource sharing

IDR_MAINFRAME

1 TO 0x6FFF

IDD_

Dialog Box Resources (Dialog)

IDD_SPELL_CHECK

1 TO 0x6FFF

HIDD_

Context Help Based on dialog box

Hidd_spell_check

0x20001 to 0x26FF

IDB_

Bitmap Resources (Bitmap)

IDB_COMPANY_LOGO

1 TO 0x6FFF

IDC_

Cursor Resource (CURSOR)

IDC_PENCIL

1 TO 0x6FFF

IDI_

Icon Resource (icon)

IDI_NOTEPAD

1 TO 0x6FFF

ID_IDM_

Toolbar or menu bar command item

ID_Tools_Spelling

0x8000 to 0xDFFFFFF

HID_

Command Context Help (Command Help Context)

HID_TOOLS_SPELING

0x18000 to 0x1DFFF

IDP_

Message box prompt text resources

IDP_INVALID_PARTNO

8 TO 0xDFFF

HIDP_

Message box context help (Message-Box Help Context)

HIDP_INVALID_PARTNO

0x30008 to 0x3DFFF

IDS_

String resource (String)

IDS_COPYRIGHT

1 TO 0x7FFF

IDC_

Control resource in the dialog

IDC_Recalc

8 TO 0xDFFF

5 comment style

Untrue annotations are annotated with doubles;

Multi-line annotation with / * * /

There is no more annotation left by debugging in the source code of the presented version.

Note Don't be too much, generally 60 characters (guaranteed to ensure the visible area of ​​the VC integration), if there is more than, then the wrap processing.

转载请注明原文地址:https://www.9cbs.com/read-7727.html

New Post(0)