Thread overview
[experts] address operator
Feb 19, 2004
Manfred Nowak
Feb 19, 2004
Sean Kelly
Feb 20, 2004
Manfred Nowak
February 19, 2004
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.


February 19, 2004
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

February 20, 2004
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?
Because D is able to go down to the bare metal, it would be of interest to all of those who are going that deep.

So long.