0

I am doing a bcmp(&v6_addr1,&v6_addr2,sizeof(v6_addr1))

(gdb) p v6_addr2
$15 = {u = {b = "0\001", '\000' <repeats 12 times>, "\002\061", w = {304, 0,
      0, 0, 0, 0, 0, 12546}, l = {304, 0, 0, 822214656}}}

(gdb) p v6_addr1
$16 = {u = {b = "0\001", '\000' <repeats 12 times>, "\002\061", w = {304, 0,
      0, 0, 0, 0, 0, 12546}, l = {304, 0, 0, 822214656}}}

(gdb) p bcmp(&v6_addr1,&v6_addr2,sizeof(v6_addr1))
$18 = 1

The blocks seem to be same in gdb

but the bcmp return value is 1.. What could be the reason ??

Chris Maes
  • 35,025
  • 12
  • 111
  • 136
Aishu
  • 27
  • 2
  • 6

1 Answers1

0

If the struct contains padding, the values at those places could differ. This won't show up in a debugger if you inspect the values, because it only shows the values.

You can verify this by examining the actual memory contents.

Don't bcmp. From the manual:

The bcmp() function compares the two byte sequences s1 and s2 of length n each.

See this for a solution: How do you compare structs for equality in C?

Community
  • 1
  • 1
Karoly Horvath
  • 94,607
  • 11
  • 117
  • 176