最近我一直在尝试阅读更多开源C代码.我在业余爱好项目中采用的一种常见模式如下: -
在我的C文件中,我有静态或导出的函数.只有导出的函数才会放在头文件中.仅在对象范围内使用的全局变量也用作静态全局变量.
我的问题涉及在头文件中使用"静态内联"函数的有用性和动机.从我在线阅读的内容来看,不使用static关键字会导致多重定义错误,这就是不仅仅将函数定义为"内联"的原因.
但是,这是否意味着导出此函数以供其他对象使用?如果是,那么为什么不在C文件中定义此函数并通过头文件导出它?如果不是,为什么将它放在头文件中而不是仅仅在C文件中?
这种编码风格背后有原因吗?我错过了什么?
一个这样的例子可以在git代码库里面找到static inline:
/*
* Converts a cryptographic hash (e.g. SHA-1) into an int-sized hash code
* for use in hash tables. Cryptographic hashes are supposed to have
* uniform distribution, so in contrast to `memhash()`, this just copies
* the first `sizeof(int)` bytes without shuffling any bits. Note that
* the results will be different on big-endian and little-endian
* platforms, so they should not be stored or transferred over the net. …Run Code Online (Sandbox Code Playgroud) 我正致力于使用GCC编译的ARM C/C++代码的性能优化.CPU是Tegra 3.我知道标志-mthumb意味着生成旧的16位Thumb指令.在不同的测试中,我使用-marm对-mthumb的性能提高了10-15%.
-mthumb仅用于兼容性和性能 - marm总是更好吗?我问,因为android-cmake在Release模式下使用了-mthumb而在Debug中使用了-marm,这对我来说非常困惑.
我有一个 C++ 程序,我需要当前路径来稍后创建一个文件夹。我的可执行文件的位置是,比方说/home/me/foo/bin。这是我运行的:
//Here I expect '/home/me/foo/bin/', but get ''
auto currentPath = boost::filesystem::current_path();
//Here I expect '/home/me/foo/', but get ''
auto parentPath = currentPath.parent_path();
//Here I expect '/home/me/foo/foo2/', but get 'foo2/'
string subFolder = "foo2";
string folderPath = parentPath.string() + "/" + subFolder + "/";
//Here I expect to create '/home/me/foo/foo2/', but get a core dump
boost::filesystem::path boostPath{ folderPath};
boost::filesystem::create_directories( boostPath);
Run Code Online (Sandbox Code Playgroud)
我在 Ubuntu 16.04 上运行,使用安装了包管理器 Conan 的 Boost 1.66。
我曾经在不使用柯南的情况下使用以前版本的 Boost(我相信是 1.45)成功运行它。Boost 只是正常安装在我的机器上。我现在在运行时得到一个核心转储create_directories( boostPath);。
两个问题: …
Anaconda 是一个强大且流行的工具包,通常与 Python 开发相关。选择它的蛇名可能是为了提醒 Python,但我使用它的感觉是,它所做的只是处理虚拟环境,预安装有用的 Python 库、工具和包,然后(可能也是最重要的)处理具有依赖项和安装。
我也可以设置 Anaconda 来为 Go 创建虚拟环境吗?
从Anaconda 可以安装 Go的事实来看,我开始认为这实际上是可能的,但后来我也感觉到 Anaconda 的所有依赖项解决能力可能只考虑 Python。
……可以吗?