0

I'm absolutely not a coder, but I'm trying to get a very old program to compile from fortran to C, so that I can play a game i've not played in 20+ years (originally created on HP3000 in the late 70s!) on my linux box.

Someone has written a make.sh file, using f2c (fortran to C) so that it can compile using GCC under linux, but that was done many moons ago.

I'm getting the following error message:

stubs.c: In function ‘exexc_’:
stubs.c:76:13: warning: implicit declaration of function ‘mmsa_’; did 
you mean ‘memset’? [-Wimplicit-function-declaration]
case 'A': mmsa_(); break;

The relevant piece of code i.e. exexc function in stubs.c is:

#include <setjmp.h>
int setjmp(jmp_buf env);
void exexc_(name, i1, i2, i3, i4, i5, namelen)
char *name;
shortint *i1, *i2, *i3, *i4, *i5;
long namelen;
 {
   static jmp_buf env;
   static int first = 1;
   static char segment[6];

   ipx[0] = *i1;
   ipx[1] = *i2;
   ipx[2] = *i3;
   ipx[3] = *i4;
   ipx[4] = *i5;

   strncpy(segment, name, namelen);

   if( ! first ) longjmp(env, 1);

   if( first )
  {
            first = 0;
            setjmp(env);
            switch(segment[3]) {
            case 'A': mmsa_(); break;
            case 'B': mmsb_(); break;
            case 'C': mmsc_(); break;
            case 'D': mmsd_(); break;
            case 'E': mmse_(); break;
            case 'F': mmsf_(); break;
            case 'G': mmsg_(); break;
            case 'H': mmsh_(); break;
            case 'I': mmsi_(); break;
            case 'J': mmsj_(); break;
            case 'K': mmsk_(); break;
            case 'L': mmsl_(); break;
            default:
                  fprintf(stderr, "Whoa, attempted to call segment %s\n", segment);
                  fflush(stderr);
                   exit(1);
           }
          fprintf(stderr, "Oops, segment %s didn't call next segment\n", segment);
          fflush(stderr);
          exit(2);
   }
}

What do i need to change in the stubs.c file, so that 'case 'A': mmsa_()' function is declared? If it helps, then mmsa refers to another file i think mmsa.c in the same local directory.

Happy to give more info if you need it. I've not played this game in over 20+ years(!), so any help would be gratefully received.

Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
JamesT
  • 1

1 Answers1

2

this is "just" a warning, and the function call doesn't have any parameters, nor any return value is retrieved, so it should be safe to write:

void mmsa_(void);
void mmsb_(void);
...

and so on.

And if you have header files declaring those functions, it's even better as you can include them instead of declaring them directly.

of course you have to link with libraries or objects containing the code of mmsa_ and other functions, or you'll get a link error (the problem would be just moved to the link phase)

as an aside: consider refactoring your code to remove the K&R old-style parameter declaration which is very much outdated and error prone.

Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
  • These are invalid (non-prototype) function declarations. An empty parameter list is specified by `void`, not empty parentheses. – too honest for this site Jul 15 '18 at 22:22
  • I was considering it "too much". You're right. Else, one can pass parameters. – Jean-François Fabre Jul 15 '18 at 22:27
  • TBH, the question is pretty hopeless. If OP does not know C and the code is that ancient not to declare functions before usage, there are very likely other, more subtle quirks. I'd recommend to either use a fortran compiler (gcc does provide one) or use this as an oportunity to learn C from a good textbook. Alone the custom declaration of a standard library function is illegal. all the `static` local variables are, too. Automatically translated code is just _urgh_. (plus: we don't know what the functions are supposed to do, expecially with all the side-effects in the code shown). – too honest for this site Jul 15 '18 at 22:31
  • Finally: K&R parameter declarations are also invalid. – too honest for this site Jul 15 '18 at 22:35
  • In C89 adding these prototypes may introduce undefined behaviour, depending on how the function is defined – M.M Jul 15 '18 at 22:35
  • @M.M I'm just assuming that the call is correct, so there are no parameters so `void` is valid there. Since I didn't see the code for those functions, I only have to trust the caller. – Jean-François Fabre Jul 16 '18 at 07:09
  • @Olaf my experience with f2c is very good. The tool creates terrible C code but it's 100% faithful to the original behaviour-wise (that impressed me). That said, I _hate_ fortran and a rewrite (by a trainee if possible) is always a good option to take control over some old code. I often do that when the original code has bugs or isn't valuable enough/badly written and we need to maintain it afterwards. – Jean-François Fabre Jul 16 '18 at 07:11
  • @Jean-FrançoisFabre: TRhe problem is the code apparently is not compliant C (anymore) since a long time. Plus we have no idea for which platform the original code was designed. Both don't really strengthen confidence in the **logical** quality of the generated C code even if we ignore the quality of the structure. The latter makes the code more problematic to comprehend even for a semipro, though. I mean, if the code is from the 70ies, it's not even Fortran 90 compliant. – too honest for this site Jul 16 '18 at 09:07