www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/02/13/11:12:26

From: Steve McConnel <steve AT acadcomp DOT sil DOT org>
Subject: bug in gcc (either cc1 or as or ld)
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Date: Wed, 8 Feb 1995 16:38:09 -0600 (CST)

TWIMC,

While trying to compile MAWK 1.1.4 with DJGPP 1.12m4 (gcc 2.6.3), I
encountered a rather strange bug during the link step.  I don't know
whether to blame as or ld for this one (or could it be cc1?).  A
function that came at the beginning of the file preceding a struct
definition was not recognized by ld if the -g option was used with gcc
to compile the file.  This bug is demonstrated by the four tiny files
attached below (makefile, bugged.c, fixed.c, and x.c).  For what it's
worth, the program compiles fine on SunOS 4.1.3_U1 with gcc 2.6.2.
That's the only other implementation of gcc that I have available for
testing.
--
Stephen McConnel                        steve AT acadcomp DOT sil DOT org
Academic Computing Department                or
Summer Institute of Linguistics         steve DOT mcconnel AT sil DOT org
7500 W. Camp Wisdom Road                phone: (214)709-3361
Dallas, TX 75236  U.S.A.                fax:   (214)709-3387

=================================> makefile <==================================
CFLAGS = -g
x.exe: x.o bugged.o
	gcc -o x x.o bugged.o
	coff2exe x
xx.exe: x.o fixed.o
	gcc -o xx x.o fixed.o
	coff2exe xx
xxx.exe: x.o bugged1.o
	gcc -o xxx x.o bugged1.o
	coff2exe xxx
x.o: x.c
bugged.o: bugged.c
fixed.o: fixed.c
bugged1.o: bugged.c
	gcc -c bugged.c -o bugged1.o
all: x.exe xx.exe xxx.exe
clean:
	del *.o
	del x*.
=================================> bugged.c <==================================
unsigned hash(s)
char *s ;
{
unsigned h = 0 ;
while ( *s )  h += h + *s++ ;
return  h  ;
}

struct hash {
struct hash *link ;
char *string;
};
==================================> fixed.c <==================================
struct hash {
struct hash *link ;
char *string;
};

unsigned hash(s)
char *s ;
{
unsigned h = 0 ;
while ( *s )  h += h + *s++ ;
return  h  ;
}
====================================> x.c <====================================
#include <stdio.h>

extern unsigned hash();

void main(argc, argv)
int argc;
char **argv;
{
printf("hash(\"A\") = %u\n", hash("A"));
printf("hash(\"AB\") = %u\n", hash("AB"));
}

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019