随笔分类 -  C/CPP

摘要:const与* *符号左侧为所指对象的语义,*符号右侧为指针自身语义 const与iterator const iterator(是T* const) != const_iterator 详细原因应参考c++编译和c++设计与演化 const避免将==写成= 运算符的重载函数返回const对象可以避 阅读全文
posted @ 2022-08-20 12:08 ijpq 阅读(39) 评论(0) 推荐(0)
摘要:pre 针对Effective C++ (55条)中的每一个条款写一个blog。 0x02 尽量以const, enum, inline 替换 #define 为什么需要这样做?因为使用define会使得变量被define的符号替换,在遇到错误时提示的是替换后的符号而非原始定义的符号,引起误解,因此 阅读全文
posted @ 2022-08-17 23:34 ijpq 阅读(80) 评论(0) 推荐(0)
摘要:为什么? 即使给函数宏加上了小括号,如下 #define F(a,b) f((a)>(b)?(a):(b)) 但仍会在使用++运算符时产生问题 F(++a,b) // 替换为 f((++a)>(b)?(++a):(b)) 怎么做 永远使用inline template替换函数宏 template < 阅读全文
posted @ 2022-08-17 23:26 ijpq 阅读(55) 评论(0) 推荐(0)
摘要:前置知识: virtual table in C++ 对于每个opr,dispatcher构建了一个vtable(c多态性相关概念)。dispatcher的工作就是根据输入的tensor和其他一些meta信息,计算dispatch key,然后根据vtable跳转到相应的函数 c virtual t 阅读全文
posted @ 2022-05-20 16:18 ijpq 阅读(290) 评论(0) 推荐(0)
摘要:class Container { public: virtual double& operator[](int) = 0; virtual int size() const = 0; virtual ̃Container() {} // pure virtual function // const 阅读全文
posted @ 2022-05-20 11:44 ijpq 阅读(52) 评论(0) 推荐(0)
摘要:we could dynamic symbol printf with libc.so instead of include<stdio.h> in source file. a.c int main(){ printf("hi! .so success!\n"); return 0;} gcc a 阅读全文
posted @ 2022-02-20 22:28 ijpq 阅读(47) 评论(0) 推荐(0)
摘要:Guide to Faster, Less Frustrating Debugging Guide to Faster, Less Frustrating Debugging Norman Matloff University of California at Davis (530) 752-195 阅读全文
posted @ 2022-02-20 22:25 ijpq 阅读(60) 评论(0) 推荐(0)
摘要:bit operations /2, *2 odd or even 实现mod 当计算\(a \mod b\) 且 b是\(2^n\)时,可以直接使用\(a \& (b-1)\)来计算\(a \mod b\)​。 原理为:$a \mod b \(是\)a/b$​的余数。 因为\(b=2^n\),\( 阅读全文
posted @ 2021-12-20 19:36 ijpq 阅读(86) 评论(0) 推荐(0)
摘要:问题 类似,可以看到下面的这个问题 回答 总的来说,浮点数无法表示0.1。 这是因为,根据IEEE浮点数标准,float的尾数是23位,权分别为$2^{-1},2^{-2},...$。0.1 = 1/10 = 1/2 * 1/5 = 1 * %2^{-1}% * 1/5,而1/5无法直接找到对应的权 阅读全文
posted @ 2021-12-19 18:02 ijpq 阅读(426) 评论(0) 推荐(0)
摘要:pre 使用了opencv_contrib中的plot 模块,contrib的安装过程存在问题,如果不能解决,可以把plot.cpp/plot.h相关文件先编译一遍,之后再编译的时候带着obj。 需要一些基础的opencv配置知识,知道涉及到的模块该如何build,如何include step1 g 阅读全文
posted @ 2021-12-16 20:15 ijpq 阅读(625) 评论(0) 推荐(0)
摘要:https://docs.microsoft.com/en-us/cpp/preprocessor/hash-include-directive-c-cpp?redirectedfrom=MSDN&view=msvc-170 阅读全文
posted @ 2021-12-16 20:06 ijpq 阅读(31) 评论(0) 推荐(0)
摘要:起因 邓俊辉的中序遍历二叉树采用了和前序遍历不同的循环检查方式,在前序遍历时使用stack非空检查,而在中序遍历时采用了while1检查。不便于迁移学习。 分析 视频地址: https://www.bilibili.com/video/BV1jt4y117KR?p=173 中序遍历时,根据规律每次进 阅读全文
posted @ 2021-10-25 09:20 ijpq 阅读(219) 评论(0) 推荐(0)
摘要:IN C gcc 5.4.1 c99 gdb 7.11.1 0X01 array bound are fully determined at compile time. #include <stdio.h> #define R 3 #define C 4 void func(int arr[R][C 阅读全文
posted @ 2021-10-20 12:01 ijpq 阅读(26) 评论(0) 推荐(0)
摘要:Assume that a piece of memory space is requested by malloc type *ptr = (type *) malloc(num * sizeof(element)); the ptr is the first address of the pie 阅读全文
posted @ 2021-10-20 12:01 ijpq 阅读(29) 评论(0) 推荐(0)
摘要:assume $num is the number what you assign through scanf or fscanf or sscanf and so on. while (fscanf(fileptr, formatstring, &var1, &var2,...)!=$num) { 阅读全文
posted @ 2021-10-20 12:01 ijpq 阅读(44) 评论(0) 推荐(0)
摘要:find the variable name translate the operator adjacent to the var name with prioirty translate anthor symbol adjacent to the var in the opposite direc 阅读全文
posted @ 2021-10-20 11:55 ijpq 阅读(32) 评论(0) 推荐(0)
摘要:source code #include <stdio.h> #include <unordered_map> #include <string> #include <iostream> using namespace std; int main() { // printf("Hello World 阅读全文
posted @ 2021-10-20 11:53 ijpq 阅读(40) 评论(0) 推荐(0)
摘要:const容易混乱的地方在于底层const和顶层const概念。以及const与新标准中constexpr的区分。 顶层const和底层const int *const p1 = &i; // 顶层 cosnt int ci = 42; // 顶层 const int *p2 = &ci; //底层 阅读全文
posted @ 2021-10-20 11:52 ijpq 阅读(40) 评论(0) 推荐(0)
摘要:% x%y语义上:如果x和y都是正整数,结果是x除以y的余数 这个运算结果的取值范围是[0, x-1]  但值得注意的是 // Program to illustrate the // working of the modulo operator #include <stdio.h> int m 阅读全文
posted @ 2021-10-14 08:53 ijpq 阅读(42) 评论(0) 推荐(0)
摘要:今天看pytorch源码,看到一些之前和DALI源码相似的操作,我发现这些代码都使用C来实现范型,而不使用C++.真的很神奇!难道嫌模板编译不够快???? 假如我们写了一个整数add的函数如下 struct NumVector { num *data; int n; } // C = A + B v 阅读全文
posted @ 2021-10-14 08:49 ijpq 阅读(115) 评论(0) 推荐(0)