我试图将一个uint8_t数组转换为uint32_t数组,但似乎没有工作.
谁可以帮我这个事.我需要将uint8_t值设为uint32_t.
我可以通过转移来做到这一点,但我认为有一个简单的方法.
uint32_t *v4full;
v4full=( uint32_t *)v4;
while (*v4full) {
if (*v4full & 1)
printf("1");
else
printf("0");
*v4full >>= 1;
}
printf("\n");
Run Code Online (Sandbox Code Playgroud) 我创建了一个指向指针和int数组的指针,但是当我尝试通过指向指针的指针访问数组时,它会跳过一些元素并一次移动两个元素(例如:从1到3).这是我的代码:
int main(void) {
int c=10;
int p[5]={2,3,5,6,8};
int *x;
int **y;
x=p;
y=&p;
printf("p value is %d and p points to %d",p,&p);
printf("\n x is %d \n",x[1]);
printf("\n y is %d \n",y[0]);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当我打印y[1]它将打印5而不是3并y[2]打印为8.我想不出原因.谁可以帮我这个事?指针x是沿着正确的元素,做工精细和移动x[0]=2,x[1]=3,x[5]=5.也可以解释为什么我得到p和&p的相同值
我正试图再投struct一个.但是我在编译时不断收到此错误:
请求转换为非标量类型
我收到此行的错误:
p是结构前缀,我需要将其强制转换为struct prefix_ipv4
get_info (type, (struct prefix_ipv4) p);
Run Code Online (Sandbox Code Playgroud)
码:
ospf_external_info_delete (u_char type, struct prefix_ipv4 p)
{
///////////////
}
struct prefix_ipv4
{
u_char family;
u_char prefixlen;
struct in_addr prefix __attribute__ ((aligned (8)));
}
struct prefix
{
u_char family;
u_char prefixlen;
union
{
u_char prefix;
struct in_addr prefix4;
struct in6_addr prefix6;
struct
{
struct in_addr id;
struct in_addr adv_router;
} lp;
u_char val[8];
} u __attribute__ ((aligned (8)));
};
Run Code Online (Sandbox Code Playgroud)
有谁能说为什么?
我是Linux开发的新手.我正在研究一个示例Linux网络驱动程序教程,并遇到了net_generic(const struct net*net,int id)函数.有人可以解释一下net_generic(const struct net*net,int id)的使用我谷歌为它但只找到了头文件.任何人都可以在我可以参考的资源(网站或书籍)上指向我.谢谢