【问题标题】:Warning] data definition has no type or storage class [enabled by default]警告] 数据定义没有类型或存储类 [默认启用]
【发布时间】:2014-11-04 17:25:13
【问题描述】:

对于大学,我需要使用提供的模板创建一个基本的桌面计算器。我已经设法完成了大部分工作,但第 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 */
iExit();
} /* End of main */

【问题讨论】:

  • 您没有在函数声明中指定返回类型。默认情况下,它将采用int。例如。 iScreenSetup(); 应该是 <datatype> iScreenSetup(); 例如 int iScreenSetup();
  • 这与implicit int有关,在C89中如果你不指定类型则默认为int,尽管在C99之后这已经消失了many compiler still support it
  • 当你的函数名从i开始时,它应该返回int。例如。 int iScreenSetup();
  • 我遇到错误“未定义对 textcolor 的引用”有什么提示吗?
  • 一些 C 带有“conio.h”,这不是标准的,其中大多数包含 textcolor() 函数,但可能不是全部。如果这是一个问题,请发布一个新问题并显示实际使用 textcolor 的代码。

标签: c class storage definition


【解决方案1】:

您的原型缺少返回类型。如果什么都不返回,那就是void

/* Prototypes */
void iScreenSetup();

【讨论】:

  • 谢谢一百万!我正在破坏我的大脑试图弄清楚。
  • @Fiery-Skyline:请注意,这仍然不是原型声明(正如评论所暗示的那样),而是(过时的)旧式声明。例如,原型是void iScreenSetup(void)。对于旧式版本(以及其他问题),当您使用错误数量的参数(或错误类型的参数)调用它时,您的编译器可能不会告诉您。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-03-13
  • 1970-01-01
  • 2014-08-18
  • 1970-01-01
  • 1970-01-01
  • 2013-09-27
  • 2013-09-25
相关资源
最近更新 更多