GCC警告:函数'puts'的隐式声明在C99中无效 [英] GCC Warning: implicit declaration of function 'puts' is invalid in C99

查看:663
本文介绍了GCC警告:函数'puts'的隐式声明在C99中无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始了Zed Shaw的学习C的艰难之路。我已经下载了XCode和命令行工具。但是,当我编译第一个程序:

  int main(int argc,char * argv []){
puts(Hello world。);
返回0;
}

我得到这个警告:


ex1.c:2:1:警告:函数'puts'的隐式声明无效
in C99
[-Wimplicit-function-declaration] p>

程序会正确编译并执行。 我使用OSX 10.8 0.3。输入'gcc -v'给出:


使用内置规格。目标:i686-apple-darwin11配置:
/private/var/tmp/llvmgcc42/llvmgcc42-2336.11~182/src/configure
--disable-checking --enable-werror --prefix = /Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2 --mandir = / share / man --enable-languages = c,objc,c ++,obj-c ++ --program-prefix = llvm- - -program-transform-name = / ^ [cg] [^ .-] * $ / s / $ / - 4.2 / --with-slibdir = / usr / lib --build = i686-apple-darwin11 --enable- llvm = / private / var / tmp / llvmgcc42 / llvmgcc42-2336.11〜182 / dst-llvmCore / Developer / usr / local
--program-prefix = i686-apple-darwin11- --host = x86_64-apple- darwin11 --target = i686-apple-darwin11 --with-gxx-include-dir = / usr / include / c ++ / 4.2.1线程模型:posix gcc版本4.2.1(基于Apple Inc. build 5658)(LLVM建立2336.11.00)

请帮助解决方案 / div>

您需要包含stdio.h,即

  #include< stdio.h> 

开始导入函数定义。


I am beginning Zed Shaw's Learn C The Hard Way. I have downloaded XCode and the Command Line Tools. But when I compile the very first program:

int main(int argc, char *argv[]) {
     puts("Hello world."); 
     return 0;
 }

I get this warning:

ex1.c:2:1: warning: implicit declaration of function 'puts' is invalid in C99 [-Wimplicit-function-declaration]

The program does compile and execute correctly.

I'm using OSX 10.8.3. Entering 'gcc -v' gives:

Using built-in specs. Target: i686-apple-darwin11 Configured with: /private/var/tmp/llvmgcc42/llvmgcc42-2336.11~182/src/configure --disable-checking --enable-werror --prefix=/Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2 --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-prefix=llvm- --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin11 --enable-llvm=/private/var/tmp/llvmgcc42/llvmgcc42-2336.11~182/dst-llvmCore/Developer/usr/local --program-prefix=i686-apple-darwin11- --host=x86_64-apple-darwin11 --target=i686-apple-darwin11 --with-gxx-include-dir=/usr/include/c++/4.2.1 Thread model: posix gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)

Please help.

解决方案

You need to include stdio.h, i.e.

#include <stdio.h> 

at the start to import the function definition.

这篇关于GCC警告:函数'puts'的隐式声明在C99中无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆