www.digitalmars.com         C & C++   DMDScript  

D - [experts] address operator

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

`f' should be able to operate with many memory areas. But there seems to
be no type safe way of getting the start of a memory area together with
its length. Why does the adress operator `&' not yield a struct for
example:
  struct MemoryArea{
    void* start;
    uint length;
  }
Because the type of the variable is known at compile time ;-) the length
field should be easily beeing filled by `&'.

Then:
  void f( MemoryArea a){ ... inspect a ... }
  ...
  int x; real r;
  ...
  f(&x); f(&r);

would be much less errorprone than
  void f( void* ptr, uint length){ ... inspect ptr up to ptr+length-1 ...}
  ...
  int x; real r;
  ...
  f( &x, x.sizeof); f( &r, r.sizeof);

So long.

  
Feb 19 2004
parent reply Sean Kelly <sean ffwd.cx> writes:
Kind of a neat idea, but it would complicate C support.  And I really 
don't think you should be using raw memory pointers much in D anyway. 
How useful would this really be?


Sean
Feb 19 2004
parent Manfred Nowak <svv1999 hotmail.com> writes:
Sean Kelly wrote:

[...]
 but it would complicate C support.

I do not believe that. Because also the receiver of the result of the address operator is known at compile time the compiler can decide whether to let the oprator yield a naked address or a struct. [...]
 How useful would this really be?

all of those who are going that deep. So long.
Feb 19 2004