Re: CFO: Why C?
From: VBDis (vbdis_at_aol.com)
Date: 09/10/03
- Next message: VBDis: "Re: CFO: Why ./configure?"
- Previous message: VBDis: "Re: CFO: Why C?"
- In reply to: Måns Rullgård: "Re: CFO: Why C?"
- Next in thread: Ulrich Eckhardt: "Re: CFO: Why C?"
- Reply: Ulrich Eckhardt: "Re: CFO: Why C?"
- Reply: Måns Rullgård: "Re: CFO: Why C?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 09 Sep 2003 23:37:31 GMT
Im Artikel <yw1xbrtvr69t.fsf@users.sourceforge.net>, mru@users.sourceforge.net
(=?iso-8859-1?q?M=E5ns_Rullg=E5rd?=) schreibt:
>It is often said that Java has no pointers. This is easily proven
>wrong. Just look up NullPointerException. Renaming pointers to
>references doesn't change anything fundamental.
The difference between pointers and references is more than only a rename. At
least in C++ references cannot be NULL, that's a significant difference from
unmanaged pointers. References also cannot be modified, by pointer arithmetic.
What remains is a check for possibly uninitialized variables.
>It's true that if pointers are not used, certain errors can't happen.
>However, it's not only errors that are banished by this. A lot of
>nice functionality is lost as well.
Can you give concrete examples?
>Doing things perfectly safely is impossible without runtime checks.
Agreed, when dynamic arrays come into play. Do you know of other situations?
>Runtime checks always take some extra time.
Sometimes appropriate runtime checks can even save time! Consider a loop over
an array, where in traditional code often a pointer as well as an index (loop
variable) is incremented or decremented and tested for every iteration. With
indexed access to the array the compiler will almost use the same procedure,
with an implicit pointer, but it can create faster code for the loop test
(LOOPNE or similar, for the assembly freaks ;-)
In another case, when counted instead of zero terminated strings are used, a
test for the trailing null byte is obsolete, since the length of the string is
known before entering the loop, and can immediatley be used as the loop count.
Similarly NULL pointers deserve no checking code at all, when references are
used.
>Even with the checks,
>there is nothing you can do but abort, when there is a violation.
Compile time checks reduce the amount of remaining runtime checks. I just can
imagine only two possible cases, but perhaps you find more:
- index bounds violation
- out of memory during allocation
In the first case it should be possible to find the place (loop...) of the
erroneous index calculation. The second case usually indicates an infinite
loop, which also should be locatable in the code.
>IMHO, it is better to use a debugging tool, such as valgrind, to check
>the program during development.
There exist fine tools, which can reduce the time to find the remaning bugs in
some code. In the best case they allow to verify that no errors can occur at
all, provided the code is written in a way that allows for such a verification.
DoDi
- Next message: VBDis: "Re: CFO: Why ./configure?"
- Previous message: VBDis: "Re: CFO: Why C?"
- In reply to: Måns Rullgård: "Re: CFO: Why C?"
- Next in thread: Ulrich Eckhardt: "Re: CFO: Why C?"
- Reply: Ulrich Eckhardt: "Re: CFO: Why C?"
- Reply: Måns Rullgård: "Re: CFO: Why C?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|