C/C++/VC++ 变量命名规则
C/C++/VC++ 变量命名规则
是VC++的么?
4.变量风格
变量尽量采用匈牙利命名法,同时结合VC的原则;一般情况下,变量的取名方式为:
<scope><prefix><qualifier>
有关项目的全局变量必须用g_开始,类成员变量用m_,局部变量若函数较大则可考虑用l_用以显示说明其是局部变量。
前缀
类型
示例
g_
GlobalVariable(全局变量)
G_Servers
C
Classorstructure(类或者结构)
CDocument,CPrintInfo
m_
Membervariable(类成员变量)
m_pDoc,m_nCustomers
VisualC++常用变量前缀列表:
前缀
类型
描述
例子
ch
Char
8-bitcharacter
chGrade
ch
TCHAR
16-bitcharacterif_UNICODEisdefined
chName
b
BOOL
Booleanvalue
bEnabled
i
Int
Integer(sizedependentonoperatingsystem)
iLength
n
UINT
Unsignedvalue(sizedependentonoperatingsystem)
nLength
w
WORD
16-bitunsignedvalue
wPos
l
LONG
32-bitsignedinteger
lOffset
dw
DWORD
32-bitunsignedinteger
dwRange
p
*
Ambientmemorymodelpointer
pDoc
lp
FAR*
Farpointer
lpDoc
lpsz
LPSTR
32-bitpointertocharacterstring
lpszName
lpsz
LPCSTR
32-bitpointertoconstantcharacterstring
lpszName
lpsz
LPCTSTR
32-bitpointertoconstantcharacterstringif_UNICODEisdefined
lpszName
h
Handle
HandletoWindowsobject
hWnd
lpfn
(*fn)()
callbackFarpointertoCALLBACKfunction
lpfnAbort
Windows对象名称缩写:
Windows对象
例子变量
MFC类
例子对象
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;
VisualC++常用宏定义命名列表(对于资源的定义全部采用大写):
前缀
符号类型
符号例子
范围
IDR_
标识多个资源共享的类型
IDR_MAINFRAME
1to0x6FFF
IDD_
对话框资源(Dialog)
相关文档:
前几天参加某公司的笔试,有一道题是用纯C实现一个泛型函数。郁闷了好久用C++模板实现了。
宏有如下的特点:
1.与const相比,宏是在预编译的时候完成的
2.define 只做简单的替换,不做类型安全检查
3.使用不当会引起很多问题
宏的用法:
1.简单的宏定义
#define MAX 1024
2.宏定义功能块
#define MAX(a,b) ( ......
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <stdio.h>
#include <netinet/in.h>
#include <arpa/inet.h>
int main(){
int sockfd;
int len;
struct sockaddr_in address;
int result;
char *strings="GET /svnup/rewrite.php HTTP/1 ......
根本原因在与左值和右值
char a[10]=“hello”;
sizeof(a);//数组名做左值,具有数组名的属性,是一个指向数组首地址的常量指针
strcpy(a,"abc");//数组名做右值,退化为普通的指针
原文链接:
http://hi.baidu.com/%D2%C0%BD%A3%D0%F9/blog/item/7bbf36966c92f36a54fb9663.html
作者:宋宝华 e ......
wchar_t wsWorkingDir[256] = _T("");
CString strPDF(_T(""));
::GetCurrentDirectory(256, wsWorkingDir);
strPDF.Format(_T("%s"), wsWorkingDir);
if (strPDF.GetAt(strPDF.GetLength()-1) != '\\')
{
strPDF += '\\';
}
strPDF += "doc\\my.pdf" ......
以下文章转载于:为了学习和收藏
http://tech.163.com/school · 2005-08-23 11:05:18 · 来源: 天极网
C/C++数组名与指针区别
引言
指针是C/C++语言的特色,而数组名与指针有太多的相似,甚至很多时候,数组名可以作为指针使用。于是乎,很多程序设计者就被搞糊涂了。而许多的大学老师,他们 ......