Newsgroups: comp.lang.apl
Path: watmath!watserv2.uwaterloo.ca!torn!cs.utexas.edu!uunet!newshost!root
From: trirex!taff@uunet.uu.net (Tom Affinito)
Subject: Potential (Minor) Problems with J6.0
Message-ID: <1992Nov10.160147.6619@Trirex.COM>
Keywords: J, apl, ISI
Sender: root@Trirex.COM (Operator)
Reply-To: trirex!taff@uunet.uu.net
Organization: Trirex Systems Inc.
Distribution: na
Date: Tue, 10 Nov 1992 16:01:47 GMT
Lines: 55

I had two minor problems compiling the source for j6.0, and thought I'd
share these with the net.

I'm using a NeXT, system 3.0, which uses the gcc compiler version 1.93.
This version of gcc had a fatal error in the file vh.c, and since fatal
errors do not generate line numbers I had to play with commenting out
sections of the source until I narrowed the problem down to the following
code fragment in function hiat (note, this line might not be exactly
original, as I was mucking around adding parens and such, but it's close)

d=(t&BOOL? (*(B*)yv) : (t&INT)? (*(I*)yv) : (*(D*)yv)); d*=hct;

The d*=hct end is fine, but the first part was the troublemaker for this
version of gcc; it appears that gcc has problems with the conditional
operators when it gets nested a couple of levels.  I did not fully examine
this bug, but the problem went away when I replaced that first part of the  
line with

   if (t&BOOL)
      d = (*(B*)yv);
   else if (t&INT)
      d = (*(I*)yv);
   else
      d = (*(D*)yv);

This is not a problem with ISI code, but I wanted to report the problem
anyway.


The next part IS an ISI bug, and it's in the sample main.c that gets used  
when compiling LinkJ.

The main routines loops, waiting for a Ctrl-D, and contains this line:
if('\004'==*v)exit(0); else if('\n'==*v)*v=0;

This is faulty because the string v is fetched through gets, which 1) does
not place '\n' in the string buffer anyway, but replaces it with '\0'
(unlike fgets), and 2) does not specify what gets read when the EOF
is generated.

The behavior on the NeXT is that pressing Ctrl-D causes the program to
loop forever, reevaluating the last input over and over and over again.
A solution is to replace the while with the following
 while(1){
  printf("   "); if (NULL == gets(s)) exit(0);
  v=s+strlen(s)-1; 
  t=jx(s);
  if(jerr)printf("jerr: %d\n",jerr); else if(!asgn)jpr(t);
  }

This uses the fact that gets must fail and return NULL after the EOF
marker is read.

Tom Affinito
taff@trirex.com
