www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/05/16/16:01:58

From: "Dave Bird---ARS HakeMonger ,,,,><_'>.,,,<_\",,,," <dave AT xemu DOT demon DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: ? array[n] or array[n+1] ?
Date: Sat, 15 May 1999 23:35:27 +0100
Organization: very little
Message-ID: <aY8UjGCvafP3Ewvj@xemu.demon.co.uk>
References: <37367f71 DOT 6271443 AT news DOT wanadoo DOT fr>
<3736A098 DOT 55E268BE AT softhome DOT net> <373c0195 DOT 3902906 AT news DOT wanadoo DOT fr>
<3737f542 DOT 0 AT nnrp1 DOT news DOT uk DOT psi DOT net>
NNTP-Posting-Host: xemu.demon.co.uk
X-NNTP-Posting-Host: xemu.demon.co.uk:158.152.196.209
X-Trace: news.demon.co.uk 926809223 nnrp-09:20629 NO-IDENT xemu.demon.co.uk:158.152.196.209
X-Complaints-To: abuse AT demon DOT net
MIME-Version: 1.0
X-Newsreader: Turnpike (32) Version 4.01 <dQumtnY$x4rJ2u5tL5fS$n2vuP>
Lines: 89
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

In article <7h946u$qhe$1 AT nnrp1 DOT deja DOT com>, Maxximo  writes:
>Then, this is true for several Unix machine.
[that an auto array is on the stack &a static array in the data segment,
hence the type of problem you get by over-running each].
> I don't know if this is
>true for a PC with Win* or DOS.

  To the best of my knowledge, it is exactly the same in Win* or DOS.

In article <3737f542 DOT 0 AT nnrp1 DOT news DOT uk DOT psi DOT net>, Ya'qub <rick AT nct-
active.com> writes
>Greetings,
>    With all due respect, this explanation does not seem very convincing.
>Surely, the compiler *should* complain when you do such a thing as
>overrunning an array.

 Oh should it?  C language, and C with classes,  does *NOT* guarantee to
 detect even where it can that you are about to throw  a run-time error:
 it will execute anything you grammatically tell it to.

 Any move into heavy pre-checking is a major ENHANCEMENT, and a move 
 away into a different kind of language:  VC++ is a changed language,
 somewhat Pascal-influenced.  IMO such checking can be a good thing..
 provided you have the freedom to turn it off when necessary.

In article <37383391 DOT 0 AT nnrp1 DOT news DOT uk DOT psi DOT net>, Ya'qub <rick AT nct-
active.com> writes
>Greetings,
>    Thanks for the information. On second thoughts, I realise that it was
>probably silly of me to expect the compiler to detect that kind of bug
>because it's probably only at run time that accessing an element beyond the
>array length will actually be detected, right?

 No, sometimes you can see it.... the question is, do you bloat the
 compiler with endless checks or just tell the programmer to "write
 accurate code or fix the consequences yourself"?  There is no 100%
 correct answer to this question.                                   
                                                                    
 Bloating a freeware GNU/dj-GPP compiler is a bad idea, because you
 haven't the paid staff time to throw at it & charge into the price

In<3738912D DOT F5 AT ns DOT sympatico DOT ca>, Klaas <klaas AT ns DOT sympatico DOT ca> writes
>Bounds checking is possible... but it sacrifices speed.

 I meant spotting  for(int i=0; i<=N; ++i){ ...a[i]....  }; ?N>bound(a)
 is possible at compile time, at the cost of a bigger compiler.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In article <37390d5c DOT 2690408 AT noticias DOT iies DOT es>, Guillermo Rodriguez
Garcia <XXguille AT XXiies DOT XXes> writes
>El día Tue, 11 May 1999 10:19:16 +0100, "Ya'qub" <rick AT nct-active DOT com>
>escribió:
>
>>Greetings,
>>    With all due respect, this explanation does not seem very convincing.
>>Surely, the compiler *should* complain when you do such a thing as
>
>A C compiler usually doesn't know if you will overrun an array
>(sometimes it is just impossible to know this at compile time), but
>even if the compiler knew, it would assume that you really *want* to
>do that. And indeed, sometimes it is done! I think I've seen some
>zero-length arrays in structures, where the size of the array isn't
>actually known until run time, and for some reason an equivalent
>pointer to <type> is not appropiate.
>
>Now you could have runtime checks for array bounds, uninitialized
>memory, etc., but the C language was designed to trust the programmer
>so that you can freely do almost whatever you want. It is up to you if
>your code crashes and your computer burns. If you want those checks,
>just go for Pascal or Java.

 There are some advantages in a big bloated VC++ which adds the
 convenience if such (optional) tests to the power of C++.
>
>>overrunning an array. I hoped that the compiler would help such a poor
>>programmer as myself in catching such bugs which I suppose could cause quite
>>a lot of headache to locate. Can anybody else confirm that gcc makes such
>>assumptions that we know what we are doing and let us carry on regardless.
>
>Not just gcc; almost every C compiler will.
  

-- 
   ^-^-^-@@-^-;-^   http://www.xemu.demon.co.uk/
        (..)__u     news:alt.smoking.mooses



- Raw text -


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