wuliang142857 / sya Goto Github PK
View Code? Open in Web Editor NEWC++ check
License: Apache License 2.0
C++ check
License: Apache License 2.0
来自Google C++ Style的建议:C/C++ 函数参数分为输入参数, 输出参数, 和输入/输出参数三种. 输入参数一般传值或传 const 引用, 输出参数或输入/输出参数则是非-const 指针. 对参数排序时, 将只输入的参数放在所有输出参数之前. 尤其是不要仅仅因为是新加的参数, 就把它放在最后; 即使是新加的只输入参数也要放在输出参数之前.
Google C++ Style的建议:
当一个头文件被包含的同时也引入了新的依赖, 一旦该头文件被修改, 代码就会被重新编译. 如果这个头文件又包含了其他头文件, 这些头文件的任何改变都将导致所有包含了该头文件的代码被重新编译. 因此, 我们倾向于减少包含头文件, 尤其是在头文件中包含头文件.
使用前置声明可以显著减少需要包含的头文件数量. 举例说明: 如果头文件中用到类 File, 但不需要访问 File 类的声明, 头文件中只需前置声明 class File; 而无须 #include "file/base/file.h".
不允许访问类的定义的前提下, 我们在一个头文件中能对类 Foo 做哪些操作?
另外,这篇文章对上述几种情况也做了阐述:如何使用前置声明取代包括头文件
我试了你的方法,可以获得函数名称什么的,但是却无法得到行号,请问有什么办法得到每个函数的起始位置呢?
谢谢。
Google C++ Style的建议:
当函数体比较小的时候, 内联该函数可以令目标代码更加高效. 对于存取函数以及其它函数体比较短, 性能关键的函数, 鼓励使用内联.
但有些例外情况:
一个比较合理的顺序:使用标准的头文件包含顺序可增强可读性, 避免隐藏依赖: C 库, C++ 库, 其他库的 .h, 本项目内的 .h
根据Google C++ Style Guide中对智能指针的建议,尽量不要使用std::auto_ptr scoped_ptr * linked_ptr* 。即使真的要使用,也尽量使用 std::unique_ptr 或者 std::tr1::shared_ptr。
因此,工具会检查代码中使用std::auto_ptr的情况,如果发现了使用,则给出警告信息。
#include <iostream>
#include <memory>
using namespace std;
int main () {
auto_ptr<int> p1 (new int);
*p1.get()=10;
auto_ptr<int> p2 (p1); // auto_ptr in here
cout << "p2 points to " << *p2 << "\n";
// (p1 is now null-pointer auto_ptr)
return 0;
}
#include <iostream>
#include "boost/shared_ptr.hpp" // include "boost/shared_ptr.hpp"
using namespace std;
int main () {
auto_ptr<int> p1 (new int);
*p1.get()=10;
boost::shared_ptr<int> p2 (p1); // boost::shared_ptr is OK
cout << "p2 points to " << *p2 << "\n";
return 0;
}
根据Google C++ Style的建议,对所有的头文件都使用#define 防止头文件被多重包含。
以下这些函数会造成缓冲区溢出(buffer overflow):
一直好奇基于CDT部分的API的样例代码是基础一个单独cpp file进行解析AST获取一个TranslationUnit,但是如果说除了头文件和cpp源码,其他源码之间也互相调用。在Eclipse CDT这个IDE里面肯定能通过找定义点 调用图这些功能。我感觉必然dom模型里面肯定也能存在这种关系,这个用分别创建TranslationUnit应该做不到吧。。怎么能获取这样一个完整工程结构呢?
请教一个问题:
头文件a.h内容如下:
#include "b.h"
#pragma once
#define DLL_EXPORT __declspec(dllexport)
extern "C" DLL_EXPORT int One(int a, int b);
头文件b.h内容如下:
#pragma once
#define DLL_EXPORT __declspec(dllexport)
extern "C" DLL_EXPORT int Two(int c, int d);
此时,解析头文件a.h,如何能获得One(int a, int b)和Two(int c, int d)两个函数申明?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.