I am new to Odin. I thought I would give it a try with an existing C programming project on which I am working. I would like to make an Odin proc() which can be called from C and the C layer passes a pointer to a struct to the Odin proc(). The problem that I am having is that one of my struct members is a variable named ‘c’. For example, in Odin, I would declare this line as:
BravaisLattice :: struct {
a, b, c, alpha, beta, gamma: f64
// many other structure members
}
However, because the struct is coming from C code, I tried this:
BravaisLattice :: struct {
a, b, c, alpha, beta, gamma: c.double
}
The Odin compiler isn’t happy with this, and here is error and some presumably related errors:
The names of these variables (the crystallographic unit cell parameters) are well established in my field, and I would prefer to not have to rename them as, e.g. ax, by, cz, if at all possible. Thanks for any guidance.
My take on what I can see is…
That first error " cyclic of ‘c’ " I’m pretty sure is name collision on ‘c’. The second error is saying there is another variable somewhere with the name ‘c’ that is already defined as f64. The third is saying ‘c’ is not a type, but a previously define variable. I interpret the last 2 as the same as the second error.
Taking everything that I can get from your original post, the following compiles for me. So I think there may be something else going on that I cannot see from your post. Sorry if I’m not very helpful.
OK, that worked. I think in my text substitution, I mistyped something embarassingly dumb. I typed in:
import “core:c”
import core_c “core:fmt” // doh!
When I aliased it properly,
import core_c “core:c”
import “core:fmt”
Most of the compilation errors cleaned up. I was also getting a “context not defined in this scope” error. I added, as the compiler message suggested, “context = runtime.default_context()” into my Odin procedure, and the code compiled cleanly.