【问题标题】:"Function prototypes are an ANSI feature" error while compiling C program编译 C 程序时出现“函数原型是 ANSI 特性”错误
【发布时间】:2020-10-19 20:17:44
【问题描述】:

我正在尝试在旧的 HP 3000 MPE/iX 计算机系统上调试编译器错误。错误是:

cc: "func.c", line 8: error 1705: Function prototypes are an ANSI feature.
cc: "func.c", line 15: error 1705: Function prototypes are an ANSI feature.

代码如下。衷心感谢您的帮助:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>

#define MAX_LEN 80

int find_length( char *string )
{
   int i;
   for (i =0; string[i] != '\0'; i++);
   return i;
}

int main( void )
{
   char string[132];
   int result;
   int again = 1;
   char answer;
   printf( "This program finds the length of any word you ");
   printf( "enter.\n" );
   do
   {
      printf( "Enter the word: ");
      fflush(stdin);
      gets( string );
      result = find_length( string );
      printf( "This word contains %d characters. \n", result);
      printf("Again? ");
      scanf("%c", &answer);
   } while (answer == 'Y' || answer == 'y');
}

【问题讨论】:

  • 试试int find_length() char *string; { ... }。听起来那是一个 K&R pre-ANSI 编译器。
  • Re "听起来那是一个 pre-ANSI K&R 编译器。", *Jaw drops* 我知道今年很多人都想忘记,但这很愚蠢!
  • @ikegami 该硬件始于 70 年代。可能是“如果它没有损坏 ...”的极端情况;-)
  • @dxiv,我知道,我知道。我为控制当地核电站的计算机做了一些开发。它是 1972 年的 Varian72。它有 32 KiW 的 RAM(64 KiB,每个 16 位字都有一个地址)。
  • 看起来它认为那些函数声明实际上是函数原型?尝试将 void 参数取出到 main 并将 main 移动到此文件中的第一个函数。

标签: c compiler-errors kernighan-and-ritchie function-prototypes ansi-c


【解决方案1】:

对于 ANSI C 之前的版本,您需要在函数头之后、主体的开头 { 之前声明函数的参数。您只需将参数的名称放在括号中。所以你会:

int find_length(string)
char *string;
{
    ...

对于main,只需去掉void 关键字即可。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-05-21
    • 1970-01-01
    • 1970-01-01
    • 2022-01-04
    • 2015-05-24
    • 2012-05-29
    • 2012-10-19
    相关资源
    最近更新 更多