delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/10/22/21:31:08

Date: Sat, 23 Oct 1999 02:18:10 +0100 (MET)
From: Gisle Vanem <giva AT bryggen DOT bgnett DOT no>
To: djgpp AT delorie DOT com
Subject: Re: a K-R program doesn't work only with DJGPP
Message-ID: <Pine.UW2.3.95.991023021637.20562A-100000@bryggen.bgnett.no>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com

ryot AT bigfoot DOT com (George Ryot) said:

> The way to find out is to simplify the program to the smallest that
> will still exhibit the problem:
>
> /*** bug.c ***/
>
> int main(void)
> {
>     return 0;
> }
>
> void qsort(int *v)
> {
>     v[30000] = 0;
> }
> ...
>
> The DJGPP startup code calls the globbing function which in turn calls
> qsort which has been redefined to do something bad.
>
> Whether this is a program or compiler bug hinges on whether or not it
> is legal to have user defined functions which overide those in libc.
>
> I am fairly sure that it is, and so this is indeed a DJGPP bug.

No, it not. The linker cannot possibly know that the prototype for
your qsort() is bad. This problem hadn't occured if you've used 
'gcc -Wall' and paid attention to the warnings. In which case including
<stdlib.h> would resulted in a compile error.

And it's fully legal to replace libc functions with your own (with correct
args of course).

Gisle V.

- Raw text -


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