Thread overview
A bug in the Comparison of dynamic structure arrays
Oct 19, 2003
Matthew B.
Oct 21, 2003
Marcel Strik
Jan 26, 2004
Walter
October 19, 2003
Unless I'm missing some nuance of the syntax, it seems that the linker fails
when one tries to compare arrays of structures.
Here is the code fragment that will generate the linker error



struct sowhat {
 uint failure ;
}

int main(char[][] args) {
 sowhat[] s1, s2 ;

int k ;
s1.length = 3 ;
s2.length = 3 ;
for (k = 0 ; k < s1.length ; k++) {
 s1[k].failure = 1 ;
 s2[k].failure = 1 ;
}

// If we loop through each element of the array and check we are OK
for (k = 0 ; k < s1.length ; k++) assert(s1[k] == s2[k]) ;
// A direct comparison like below doesn't work
   assert(s1 == s2) ;

return(0) ;

}


October 21, 2003
I might be wrong, but I think this is the right behaviour. I think assert(s1 == s2); will compare the addresses of s1 and s2 which will be different. assert(s1[] == s2[]); might work, but I'm not sure.


"Matthew B." <mattcbro@earthlink.net> wrote in news:bmv3lg$2r0q$1@digitaldaemon.com:

> Unless I'm missing some nuance of the syntax, it seems that the linker
> fails when one tries to compare arrays of structures.
> Here is the code fragment that will generate the linker error
> 
> 
> 
> struct sowhat {
>  uint failure ;
> }
> 
> int main(char[][] args) {
>  sowhat[] s1, s2 ;
> 
> int k ;
> s1.length = 3 ;
> s2.length = 3 ;
> for (k = 0 ; k < s1.length ; k++) {
>  s1[k].failure = 1 ;
>  s2[k].failure = 1 ;
> }
> 
> // If we loop through each element of the array and check we are OK
> for (k = 0 ; k < s1.length ; k++) assert(s1[k] == s2[k]) ;
> // A direct comparison like below doesn't work
>    assert(s1 == s2) ;
> 
> return(0) ;
> 
> }
> 
> 

January 26, 2004
"Matthew B." <mattcbro@earthlink.net> wrote in message news:bmv3lg$2r0q$1@digitaldaemon.com...
> Unless I'm missing some nuance of the syntax, it seems that the linker
fails
> when one tries to compare arrays of structures.
> Here is the code fragment that will generate the linker error
>
>
>
> struct sowhat {
>  uint failure ;
> }

To make it work, there needs to be a Typeinfo created for sowhat. Right now, it would need to be done manually.