我的疑惑开始于这篇文章,它说 C 语言中的 inline 函数是 static linkage,而 C++ 中的 inline 函数则是 external linkage。我第一次知道,原来 C 和 C++ 中的 inline 有如此的不同。于是,我尝试了这篇文章中的一个小实验。
有下面两个源文件:
// A.c
#include <stdio.h>| import re | |
| import sys | |
| try: | |
| from parse import parse | |
| except ImportError: | |
| print("You should install parse first.\n $ pip install --user parse") | |
| sys.exit(1) | |
| # PyTorch module 到 Nexus Symbol 的映射 |
| # NexusNet 镜像(CUDA 11.4,要求 Nvidia 驱动版本 >=470.57.02) | |
| # 作者:郭帅 | |
| # ===================================================================================== | |
| # [1] nexus-base :编译 NexusNet 源码所需的环境,包括 CUDA/cuDNN/OpenCV/Protobuf 以及其他软件 | |
| FROM nvidia/cuda:11.4.1-cudnn8-devel-ubuntu20.04 AS nexus-base | |
| # 更改 APT 源为阿里镜像站 | |
| RUN echo "\ | |
| deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse\n\ |
| #include "NexusCpp.hpp" | |
| // 一些全局变量 | |
| constexpr int N = 16; // batch size | |
| constexpr int C = 1; // channels 通道数 | |
| constexpr int H = 224; // 图像的高 | |
| constexpr int W = 224; // 图像的宽 | |
| constexpr int NCLASS = 10; // 分类的总类别数 | |
| auto DATASHAPE = TShape({N, C, H, W}); // 输入图像的形状 |
| # 使用 XeLaTeX 作为默认编译器,同时打开 nonstopmode 选项 | |
| $pdflatex = "xelatex -shell-escape -interaction=nonstopmode %O %S"; | |
| # 只生成 PDF 文件,不生成 DVI 和 PostScript 文件 | |
| $pdf_mode = 1; | |
| $dvi_mode = 0; | |
| $postscript_mode = 0; |
我的疑惑开始于这篇文章,它说 C 语言中的 inline 函数是 static linkage,而 C++ 中的 inline 函数则是 external linkage。我第一次知道,原来 C 和 C++ 中的 inline 有如此的不同。于是,我尝试了这篇文章中的一个小实验。
有下面两个源文件:
// A.c
#include <stdio.h>| import time | |
| import h5py | |
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| def timer(func): | |
| """给函数计时的装饰器""" |
| #include <iostream> | |
| #include <string> | |
| #include <vector> | |
| std::vector<std::string> split_naive(const std::string& s, char delim) { | |
| std::vector<std::string> ret; | |
| std::string token; | |
| for (char ch : s) { | |
| if (ch == delim) { | |
| ret.push_back(token); |
| #include <stdio.h> | |
| #include <math.h> | |
| #define PI 3.14159265358979323846 | |
| // O(n^2) | |
| void dft(double *input, double *real, double *imag, int n) { | |
| for (int k = 0; k < n; k++) { | |
| real[k] = 0; | |
| imag[k] = 0; |
| // | |
| // Timer.h | |
| // NLE | |
| // | |
| // Created by Guo Shuai on 2023/7/27. | |
| // | |
| #ifndef Timer_h | |
| #define Timer_h |