struct String
{
char[] data;
}
void main ()
{
auto foo = String(foo);
auto bar = String(foo.dup);
assert(bar == foo);
}
Why isn't == used to compare the struct members in the code above? I
mean, if I compare the structs with == it could also use == to compare
Am Mon, 08 Feb 2010 12:19:12 +0100
schrieb Jacob Carlborg d...@me.com:
struct String
{
char[] data;
}
void main ()
{
auto foo = String(foo);
auto bar = String(foo.dup);
assert(bar == foo);
}
Why isn't == used to compare the struct members in the code
Why isn't == used to compare the struct members in the code above? I
mean, if I compare the structs with == it could also use == to compare
the members. If I use is to compare the structs it could use is to
compare them members.
Structs are compared *bitwise*!
When you dup your pointer is
On 02/08/2010 01:48 PM, Trass3r wrote:
Why isn't == used to compare the struct members in the code above? I
mean, if I compare the structs with == it could also use == to compare
the members. If I use is to compare the structs it could use is to
compare them members.
Structs are compared
I believe the question was *why* things are this way. I think it's weird.
It's common behavior. In the end structs are just a way to map a memory
range to some variable tuple.
If you really need == for all members you can always overload opEquals!!
Would be interesting.
Trass3r schrieb:
Would be interesting.
Yes, this would be very interesting indeed. A list of the rules which
dmd uses internally for inlining functions and methods similiar to this
(which is for .NET)
http://blogs.msdn.com/ericgu/archive/2004/01/29/64717.aspx
would be really nice. Sure you
On 2/8/10 14:58, Pelle Månsson wrote:
On 02/08/2010 01:48 PM, Trass3r wrote:
Why isn't == used to compare the struct members in the code above? I
mean, if I compare the structs with == it could also use == to compare
the members. If I use is to compare the structs it could use is to
compare
On 2/8/10 13:48, Trass3r wrote:
Why isn't == used to compare the struct members in the code above? I
mean, if I compare the structs with == it could also use == to compare
the members. If I use is to compare the structs it could use is to
compare them members.
Structs are compared *bitwise*!
Yes, I intentionally duped the string to make sure they're not using the
same memory. I was thinking of something like a transitive ==.
Overload opEquals.
bearophile schrieb:
Scorn:
The only things i figured out so far is that functions across modules do
not seem to get inlined (i don't know if this is the case in general)
which would be really bad. Another thing which i believe is that
functions / methods which contain ref parameters are never
bearophile bearophileh...@lycos.com wrote in message
news:hkpiai$2kt...@digitalmars.com...
Scorn:
The only things i figured out so far is that functions across modules do
not seem to get inlined (i don't know if this is the case in general)
which would be really bad. Another thing which i
Use LDC (D1), you will note a significant improvement over DMD.
Unless you're on windows.
Yep, second big problem.
Use LDC (D1), you will note a significant improvement over DMD.
Unless you're on windows.
Yep, second big problem.
And unless you're using CodeBlocks (like me at the moment) for
development ...
14 matches
Mail list logo