Chinaunix首页 | 论坛 | 博客
  • 博客访问: 225993
  • 博文数量: 65
  • 博客积分: 25
  • 博客等级: 民兵
  • 技术积分: 417
  • 用 户 组: 普通用户
  • 注册时间: 2012-08-05 15:12
个人简介

路漫漫其修远兮,吾将上下而求索

文章分类

全部博文(65)

文章存档

2016年(1)

2015年(12)

2014年(34)

2013年(16)

2012年(2)

我的朋友

分类: LINUX

2014-02-20 15:18:33

最近写程序要用到strcasestr, 正好有现成的函数,也没必要自已实现一个!
可是最终到编译阶段,老是报编译警告!warning: assignment makes pointer from integer without a cast
我一般很少不去理会警告,能去掉,能解决的,肯定要解决,因为警告存在,说明你的程序还是有一些容易出错的地方!
看了man手册,如果用strcasestr,要定义这个宏 #define _GNU_SOURCE
于是我在头这块写成这样,本以为只对string.h定义宏就可以了

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <iconv.h>

#define _GNU_SOURCE
#include <string.h>
.....
#undef _GNU_SOURCE

警告依然存在,这是因为函数的声明在调用之后。未经声明的函数默认返回int型。
 
       因此要在#include所有头文件之前加  

#define _GNU_SOURCE  ,以此解决此问题。 


#define _GNU_SOURCE
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <iconv.h>
#include <string.h>

......
#undef _GNU_SOURCE

阅读(1065) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~