我有一个指针int* p,并在循环中执行一些操作.我不修改内存,只是阅读.如果我添加const到指针(两种情况,const int* p和int* const p),它可以帮助编译器优化代码吗?
我知道其他优点const,比如安全或自我记录,我会问这个特例.重新提出问题:可以const给编译器任何有用的(用于优化)信息吗?
我想为我的学习实现一个小的路由表?我知道它是在路由器中使用radix/patricia树实现的吗?
有人可以给我一个如何实现相同的想法吗?
我觉得的主要问题是存储IP ADDRESS.例如:10.1.1.0网络下一跳20.1.1.1 10.1.0.0网络下一跳40.1.1.1
有人能给我一个结构的声明,我可以从中得到一个想法吗?
我正在研究安全编码.
在下一页的第二个代码示例中,建议使用(char*)表示"skip"变量. https://www.securecoding.cert.org/confluence/display/seccode/EXP08-C.+Ensure+pointer+arithmetic+is+used+correctly
我不太清楚这个例子中的地址计算.所以我做了以下代码.
#include <stddef.h>
#include <iostream>
using namespace std;
// https://www.securecoding.cert.org/confluence/display/seccode/EXP08-C.+Ensure+pointer+arithmetic+is+used+correctly
struct big {
unsigned long long ul1_1; // 8
unsigned long long ul1_2; // 8
unsigned long long ul1_3; // 8
int si_4; // 4
int si_5; // 4
};
void getAdrs(void *p) {
cout << p << endl;
}
int main() {
size_t skip = offsetof(struct big, ul1_2);
struct big *s = (struct big *)malloc(sizeof(struct big));
cout << skip << endl; // 8
getAdrs(s ); // …Run Code Online (Sandbox Code Playgroud) 有谁知道需要多少主机位来保证子网可以拥有9个可用的主机?
我在想4左右,但我不确定.有人可以对此有所了解吗?
c ×2
c++ ×2
const ×1
ip-address ×1
ipv4 ×1
networking ×1
optimization ×1
pointers ×1
subnet ×1