Discussion: Bounds checking
Afficher un message
Vieux 05/02/2008, 17h27   #3
William Ahern
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Bounds checking

polas <nick@force.com> wrote:
> Afternoon everyone.


> I have a quick question about standard C. Generally speaking, in my
> experience, whenever one accesses an array there is never any bounds
> checking done (either statically during compilation or dynamically
> during runtime.) However, I was wondering if whether there is anything
> defined in the standard about this.


> The reason for this is I have some code conforming to ANSI C99 and
> wish to write to both arrays and a block of memory allocated by malloc
> and was wondering if I can say that there will never be any runtime
> checking done to ensure that the location I am writing to exists.


If a compiler supports this sort of checking, it's probably disabled by
default. I only know of one compiler*, actually, which supports this--TinyCC.
With TinyCC you have to enable it, using the -b switch.

Otherwise, the behavior is undefined as mentioned elsethread, and is usually
also unspecified by the compiler, so anything can happen (as opposed to
TinyCC w/ -b, where it specifies what it does).

* That is, in the form typically distributed, and without patching.

  Réponse avec citation
 
Page generated in 0,05708 seconds with 9 queries