Comparing D structs

Dan twinbee42 at skytopia.com
Sun May 17 14:00:23 PDT 2009


That sounds great, and seems like yet another reason for me to switch to D (other than the removal of header files which always seemed like a kludge).

Just for the record though, I think one can initialize/blank/calloc C structs too, but the problem is that some struct elements (of the same array) may have padding while others don't, or perhaps they have different size paddings.

Dan


Jarrett Billingsley Wrote:

> On Sun, May 17, 2009 at 3:55 PM, Dan <twinbee42 at skytopia.com> wrote:
> > Structs can't easily be compared in C because of potential 'padding' inside the struct which may (or may not) exist.
> >
> > I was jut wondering if D somehow gets round this, and allows something like memcmp to easily compare two structs.
> 
> As grauzone said, you just use == to compare them.  D solves the issue
> with C's uninitialized holes by always initializing structs.
> Therefore the padding holes are always filled with 0s.



More information about the Digitalmars-d-learn mailing list