www.digitalmars.com         C & C++   DMDScript  

D - [Language design] trapped into an error due to opCall

reply Manfred Nowak <svv1999 hotmail.com> writes:
I am playing with the implementation of a hashing function `f'.

The hashing function is implemented in a class using `opCall'. One
definition looks like `void opCall( void* ptr)'. This definition was
tested and worked.

Further testing and extending the class showed, that I had to use a
function `foo' that was used like
`someVariable= foo(someVariable);'.

Instead of making `someVariable' public, I decided to include one further
definition of `opCall':
  void opCall( int delegate(int) bar){
    someVariable= bar(someVariable);
  }
and used it like `f(&foo)'.

I got wrong results. Reactivating the printouts of the `opCall' first
mentioned showed that it got wrong data: `224 0 0 0' instead of `0 0 0 0'.

If you already see, what error I made, then you need not unrot13 the
following nor even look at it:

`sbb' jnf abg n shapgvba, nyfb vg ybbxrq nyvxr. Vg jnf n pynff gung hfrq
`bcPnyy' vgfrys. Fb gur pbeerpg pnyy unq gb or `s(&sbb.bcPnyy)' vafgrnq bs
`s(&sbb)'.

Should the language take precautions to prevent such errors?

So long.



 

    
Feb 23 2004
parent reply Juan C <Juan_member pathlink.com> writes:
<snip>
In article <c1e4fq$hn4$1 digitaldaemon.com>, Manfred Nowak says...
Should the language take precautions to prevent such errors?
</snip> As long as what's written is valid the language shouldn't prevent the user (or is that misuser?) from making errors. We're all free to make whatever errors we like.
Feb 23 2004
parent Manfred Nowak <svv1999 hotmail.com> writes:
Juan C wrote:

 As long as what's written is valid
[...] Did you change your mind since <br5a3o$jea$1 digitaldaemon.com>? So long.
Feb 23 2004