Subject: Re: c compilers
To: Wojciech Puchar <wojtek@wojtek.3miasto.net>
From: None <collver@linuxfreemail.com>
List: port-i386
Date: 10/13/2001 06:20:35
On Sat, Oct 13, 2001 at 12:28:44PM +0200, Wojciech Puchar wrote:
> > >  It doesn't have any optimisation capabilities at all so I don't think it
> > >  should be taken seriously as an alternative to gcc.
> > Regardless of its performance, the fact remains that there _are_ C
> > compilers for NetBSD other than gcc.
> and the fact lcc doesn't work ....
> 
> compiled from pkgsrc, tried to compile my small program (for converting
> between different polish-letters encoding standards) and it compiled but
> doesn't work. with gcc works perfect (attached)

I don't think lcc is technically broken in this situation.  The C standard
does not specify how a compiler will pack a structure.  The problem here is
that (stdin, stdout, stderr) are indexed to an array of FILE structures,
and that GCC and LCC produce FILE structures of different sizes.  The array
is defined in GCC compiled code (/usr/lib/libc.so), but indexed by LCC
compiled code.  I don't know what the elegant fix is, but the following
makes your program work.  Substitute GCC's sizeof(FILE) for "88" on yours.

Ben

bash-2.05$ diff --unified=1 plconv.c.orig plconv.c
--- plconv.c.orig       Sat Oct 13 04:52:49 2001
+++ plconv.c    Sat Oct 13 06:11:07 2001
@@ -1,2 +1,5 @@
 #include <stdio.h>
+#define libc_sizeof_FILE 88
+#define stdout (FILE *)((int)__sF + libc_sizeof_FILE)
+#define stderr (FILE *)((int)__sF + (2 * libc_sizeof_FILE))
 const char *pldefs[]={

  __
 (oO)  Why vote for the lesser of two evils?  Cthulhu for president.
 /||\