Skip to content

how to compare dynamic array/slice by data pointer and length #2786

Answered by leidegre
gco-bmx asked this question in Q&A
Discussion options

You must be logged in to vote

If you wanna know if they point to the same memory I think you want to compare the underlying pointers with raw_data?

package exp

import "core:fmt"
import "core:testing"

@(test)
test_raw_data :: proc(t: ^testing.T) {
	tmp: [64]u8

	x := tmp[:]
	y := tmp[:]
	z := tmp[32:]

	fmt.println(x, y, z)

	a := raw_data(x)
	b := raw_data(y)
	c := raw_data(z)

	fmt.println(a, b, c)
}
> odin test .\exp\raw_data.odin -file
[Package: exp]
[Test: test_raw_data]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@gco-bmx
Comment options

Answer selected by gco-bmx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants