使用时gcc,代码:
register a = 3;
static b = 3;
Run Code Online (Sandbox Code Playgroud)
-std=c89 -pedantic-errors虽然有警告,但在使用旗帜时允许使用它.
但是它会收到-std=c99 -pedantic-errors标志错误.
我想知道C89标准的哪一部分允许"隐含整数"规则?
我正在使用orwell dev c ++ IDE.我知道在旧的C89标准和预标准中,当函数定义中没有明确指定函数的返回类型时,C++支持缺省为int规则.但它已在C++中被禁止.但最近我写了以下简单的C程序,它工作正常.
#include <stdio.h>
void fun();
int main(void)
{
int a=9;
printf("%d",a);
printf("%d",a);
fun();
return 0;
}
a=1;
void fun()
{
printf("%d",a);
}
Run Code Online (Sandbox Code Playgroud)
默认的int规则是否也适用于变量?我的编译器向我显示以下警告.
[Warning] data definition has no type or storage class [enabled by default]
[Warning] type defaults to 'int' in declaration of 'a' [enabled by default]
Run Code Online (Sandbox Code Playgroud)
为什么C99标准仍允许默认为int?它在C++中编译失败.如果我错了,请纠正我?此C程序也适用于ideone.com等在线编译器
对于大学,我需要使用提供的模板创建一个基本的桌面计算器.我已经设法完成大部分工作,但第9行有这个错误消息(iScreenSetup();:
"[警告]数据定义没有类型或存储类[默认启用]"
有小费吗?
#include "stdio.h"
#include "conio.h"
#include "stdlib.h"
#include "string.h"
/* Prototypes */
iScreenSetup();
iDataCapture();
iProcessData();
iReport();
iExit();
/* Declare and initialise global variables */
float fNum1 = 0.0;
float fNum2 = 0.0;
float fAns = 0.0;
int iOption = 0;
int main(void)
{
/* Set up the screen */
iScreenSetup();
/* Prompt the user and capture the data */
iDataCapture();
/* Process the data */
iProcessData();
/* Generate the report */
iReport();
/* Exit routine */ …Run Code Online (Sandbox Code Playgroud) 我很惊讶地发现这是C中的有效函数声明:
f() {
return 10;
}
Run Code Online (Sandbox Code Playgroud)
未指定函数的返回类型.它不仅编译,而且实际上返回10.
void main() {
int i = f();
printf("i = %d\n", i);
}
Run Code Online (Sandbox Code Playgroud)
此代码导致以下输出:
i = 10
Run Code Online (Sandbox Code Playgroud)
这是用gcc 4.8.4编译的.为什么没有明确指定的返回类型的函数声明编译而没有错误/警告?
编辑:作为解释这里的返回类型不是函数签名的一部分,你不能超载根据不同的返回类型的功能,但问题是,需要返回类型函数声明不回答.
c ×4
c89 ×1
class ×1
definition ×1
function ×1
implicit-int ×1
standards ×1
storage ×1
variables ×1