Copying structs via function (not bitwise)

Matthias Walter walter at mail.math.uni-magdeburg.de
Thu Feb 14 01:11:40 PST 2008


Is there any other way of copying structs with '=' operator, other than the default way of a bitwise copy? I quote the FAQ:

"Structs, being value objects, do get copied about. A copy is defined in D to be a bit copy. I've never been comfortable with any object in C++ that does something other than a bit copy when copied. Most of this other behavior stems from that old problem of trying to manage memory. Absent that, there doesn't seem to be a compelling rationale for having anything other than a bit copy."

The reason, I'm asking for this, is that I'm working on a GMP port. Because numbers _must_ be value types, I must use structs. But as different instances of the same number must reference another memory region of the GMP internals, I must call special copy functions, if I do "a = b;" on two gmp-structs, a refers to the same gmp-internal memory as b.

Is there any way to do this?

best regards
Matthias Walter


More information about the Digitalmars-d-learn mailing list