Re: range checking



Christian Christmann wrote:
Hi,

in GDB you can set the option "check range". However,
this option just works with some languages that
have to be defined in GDB by "set language ...".

When choosing C, C++ or Java as langauge, the
range-checking option is not available, but it works
with e.g. Pascal. What exactly is meant by the
term "range checking"? Does Pascal allow to check if
for example arrays are accessed out of their range, like

int[2] = {1, 2};
int{2] = 5; // int[2] out of range

Yes.
Generally this feature isn't normally available in C even as a compiler
switch. It was once available as a patch to GCC, but irritatingly was
never installed. The TCC does it though.

In C it is difficult to do in general, because the language supports
arbitrary operations on pointers. It can only be done by making
assumptions about pointers that come from other libraries.

In C implementations other than TCC you can still do something though,
you can range check check heap allocated arrays. To do this you need a
memory debugger library such as "Electric Fence".

.



Relevant Pages

  • Re: Operator overloading in C
    ... All development of C as an independent language has ... making any changes or improvements to the standard ... The lack of a counted string data structure, ... Pointers can't be used for arg1 or arg2. ...
    (comp.std.c)
  • Re: pointers?
    ... There's absolutely nothing abstract in pointers. ... Take the C array: if you write ... To the assembly language programmers who were the first generation adopters of C, this mental mapping was very tight. ... Forth gained the most traction on machines like the IBM 1130 and the Data General Nova. ...
    (comp.lang.forth)
  • Re: another day, another patch ...
    ... windows weenies started to graduate from being teenage videogame players into application programmers and system managers. ... Would you blame the language? ... But you are then making that code REALLy ugly and dangerous (an non portable because assumption of 32 bit pointers). ...
    (comp.os.vms)
  • Re: which should i learn c or c++ ?
    ... >I have a book to learn the C language, but also I have some ebooks to ... >So I have a real problem. ... They'll jump right into using STL, and from your knowledge of C you'll ... productive code before even delving into pointers (by using STL ...
    (alt.comp.lang.learn.c-cpp)
  • Re: VB6, VB2005, or Something Else?
    ... They documented that this could corrupt binary data. ... Language behavior changes IMHO cannot be prevented over the lifetime of a ... Pointers don't belong in the ... But if it's framework code (lists, ...
    (microsoft.public.vb.general.discussion)