谷歌C++编程规范补充--windows编程规范

之前博客《谷歌C++编程规范笔记》整理了一些关于C++ Style方面的东西,看的是中文版本的。

但是今天翻阅英文版本的,在最后,发现了 Google C++ Style 关于windows的。

Windows programmers have developed their own set of coding conventions, mainly derived from the conventions in Windows headers and other Microsoft code.

We want to make it easy for anyone to understand your code, so we have a single set of guidelines for everyone writing C++ on any platform.

It is worth reiterating a few of the guidelines that you might forget if you are used to the prevalent Windows style:

Do not use Hungarian notation (for example, naming an integer iNum).
不要使用匈牙利命名法

Use the Google naming conventions, including the .cc extension for source files.
使用Google的命名规则,包括使用.cc后缀命名源文件

Windows defines many of its own synonyms for primitive types, such as DWORD, HANDLE, etc.
It is perfectly acceptable, and encouraged, that you use these types when calling Windows API functions.
可以使用windows定义的符号,如DWORD HANDLE等

Even so, keep as close as you can to the underlying C++ types. For example, use const TCHAR * instead of LPCTSTR.
使用const TCHAR*代替LPCTSTR

When compiling with Microsoft Visual C++, set the compiler to warning level 3 or higher, and treat all warnings as errors.
把警告当做错误来处理

Do not use #pragma once; instead use the standard Google include guards. The path in the include guards should be relative to the top of your project tree.
In fact, do not use any nonstandard extensions, like #pragma and __declspec, unless you absolutely must.
Using __declspec(dllimport) and __declspec(dllexport) is allowed;
however, you must use them through macros such as DLLIMPORT and DLLEXPORT, so that someone can easily disable the extensions if they share the code.
不要使用#pragma;可以使用__declspec(dllimport)和__declspec(dllexport),但是必须通过定义成宏来使用DLLIMPORT and DLLEXPORT

However, there are just a few rules that we occasionally need to break on Windows:

Normally we forbid the use of multiple implementation inheritance; however, it is required when using COM and some ATL/WTL classes.
正常情况下我们是禁止多重继承的,但是对于COM和一些ATL/WTL类,如果需要可以采用多重继承。

You may use multiple implementation inheritance to implement COM or ATL/WTL classes and interfaces.

Although you should not use exceptions in your own code, they are used extensively in the ATL and some STLs, including the one that comes with Visual C++.
When using the ATL, you should define _ATL_NO_EXCEPTIONS to disable exceptions.

You should investigate whether you can also disable exceptions in your STL, but if not, it is OK to turn on exceptions in the compiler.
(Note that this is only to get the STL to compile. You should still not write exception handling code yourself.)

The usual way of working with precompiled headers is to include a header file at the top of each source file, typically with a name like StdAfx.h or precompile.h.
使用预编译的话,包含的头文件要放在头文件的最前头。

To make your code easier to share with other projects, avoid including this file explicitly (except in precompile.cc), and use the /FI compiler option to include the file automatically.

Resource headers, which are usually named resource.h and contain only macros, do not need to conform to these style guidelines.
资源文件可以命名为resource.h,并且只能定义一些宏。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一苇渡江694

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值