![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
c语言
文章平均质量分 52
wellnw
Linux/openwrt/MTK/QCA/Realtek
展开
-
error: ‘__builtin_strncpy‘ specified bound depends on the length of the source argument
error: '__builtin_strncpy' specified bound depends on the length of the source argument原创 2023-02-24 10:10:54 · 1789 阅读 · 0 评论 -
[C语言]error: function declaration isn‘t a prototype [-Werror=strict-prototypes]
编译出现error: function declaration isn't a prototype [-Werror=strict-prototypes] void test_info()问题分析这是由于编译器检查严格,函数参数为空的时候需要增加void问题修改将void test_info()修改为void test_info(void)...原创 2022-05-01 09:25:28 · 1346 阅读 · 0 评论 -
【c语言】字符串转mac及mac转字符串实现
001122334455 转为00:11:22:33:44:55实现输入src 001122334455输出dest 00:11:22:33:44:44void string_to_mac_address(char* src,char* dest){ size_t len=strlen(src); const char *s = src; int num=0; if (len<12) return; if (len) {原创 2022-04-25 08:45:06 · 2233 阅读 · 0 评论 -
c语言代码调试工具valgrind Ubuntu下安装、使用及举例说明
源码下载地址Valgrind: Current Releaseshttps://valgrind.org/downloads/我下载的最新版本valgrind-3.18.1.tar.bz2,点击如下即可下载安装valgrind软件包拷贝到虚拟机解压tar -xvfvalgrind-3.18.1.tar.bz2解压后文件夹valgrind-3.18.1编译及安装cdvalgrind-3.18.1/./configure --prefix=/home/w21041...原创 2021-11-26 10:35:03 · 1970 阅读 · 0 评论 -
Linux下C语言如何使用 netlink sockets与内核模块通信?
内核模块#include <linux/module.h>#include <net/sock.h> #include <linux/netlink.h>#include <linux/skbuff.h> #define NETLINK_USER 31struct sock *nl_sk = NULL;static void hello_nl_recv_msg(struct sk_buff *skb){ struct nlms原创 2021-11-12 10:57:10 · 1838 阅读 · 0 评论 -
Linux C编译出现error: function declaration isn‘t a prototype [-Werror=strict-prototypes]
问题报错logerror: function declaration isn't a prototype [-Werror=strict-prototypes]| int (*test_config)();解决方案这是由于函数定义在没有参数的时候没有指定为void将int (*test_config)();修改为int (*test_config)(void);即可...原创 2021-10-27 19:13:38 · 473 阅读 · 0 评论 -
Makefile增加CFLAGS += -O2导致多线程间数据同步异常(volatile修饰)
问题描述 程序多线程间共享变量出现取值不同步的问题,同一个变量取出来的数据不一致问题分析 查看最近修改记录发现,修改了Makefile,增加了编译优化项-O2,由此分析是由于编译器优化导致解决方案 将线程共享的变量增加volatile修饰即可例子验证#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <pthre...原创 2021-08-13 09:51:42 · 1277 阅读 · 0 评论 -
Linux下kernel panic Oops调试及实例分析(gdb objdump指令)
异常内核模块模块名称test-module.c#include <linux/init.h>#include <linux/module.h>#include <linux/version.h>static int test_module_init(void){ int *p = 1;printk("%d\n", *p); return 0;}static void test_module_exit(void){原创 2020-11-18 15:59:00 · 3200 阅读 · 0 评论 -
C语言使用gdb addr2line strace指令定位segmentation fault或者core dumped实例分析及总结
Core dump例子程序如下#include <stdio.h> int func(int a, int b){ return a / b;} int main(){ int x = 10; int y = 0; printf("%d / %d = %d\n", x, y, func(x, y)); return 0;}测试程序名称test.cUbuntu16.04下编译gcc -o test -g test.c测试编译出的原创 2020-11-16 18:44:29 · 614 阅读 · 0 评论 -
Static(C语言)关键字用法总结
变量1.局部变量普通局部变量存储于进程栈空间,使用完毕会立即释放。static修饰的局部变量在声明时未赋初值,编译器会初始化为0 ;static修饰局部变量存储于进程的全局数据区,函数返回,它的值也会保持不变。2.全局变量普通全局变量对整个工程可见,其他文件可以使用extern外部声明后直接使用;static修饰的全局变量仅对当前文件可见,其他文件不可访问,其他文件可以定义与其同名的变量,两者互不影响。函数普通函数可以在另一个文件中直接引用static修饰的函数只能在声明原创 2020-07-22 11:17:38 · 155 阅读 · 0 评论 -
C语言面试常见笔试题
1.以下是32 位系统上C 程序,请计算sizeof 的值。程序一:char str[] = “Hello” ; char *p = str ; i nt n = 10; 请计算(1)sizeof (str ) = 6 ...原创 2020-05-15 11:34:05 · 1739 阅读 · 2 评论