1

I am attempting to debug a compiler error on an old HP 3000 MPE/iX Computer System. The error is:

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.

The code is as follows. Help is sincerely appreciated:

#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');
}
phuclv
  • 37,963
  • 15
  • 156
  • 475
Chris So
  • 21
  • 7
  • 4
    Try `int find_length() char *string; { ... }`. It sounds like that's a K&R pre-ANSI compiler. – dxiv Oct 19 '20 at 20:22
  • Re "*It sounds like that's a pre-ANSI K&R compiler.*", \*Jaw drops\* I know a lot of people want to forget this year, but this is silly! – ikegami Oct 19 '20 at 20:22
  • 1
    @ikegami That hardware started in the 70s. Could be a case of "*if it ain't broken* ..." taken to extremes ;-) – dxiv Oct 19 '20 at 20:29
  • 2
    @dxiv, I know, I know. I did some development for the computer controlling a local nuclear power plant. It's a Varian72, as in 1972. It has 32 KiW of RAM (64 KiB with an address for each 16-bit word). – ikegami Oct 19 '20 at 20:39
  • it looks like it thinks those function declarations are actually function prototypes? Try taking out the `void` argument to `main` and moving `main` to be the first function in this file. – loremdipso Oct 19 '20 at 21:09

1 Answers1

2

For pre-ANSI C, you need to declare the arguments to a function after the function header, before the opening { of the body. You only put the names of the arguments in the parentheses. So you would have:

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

For main, just get rid of the void keyword.

Chris Dodd
  • 119,907
  • 13
  • 134
  • 226