Hi Hongwei, On Mon, Aug 22, 2016 at 2:28 PM, Hongwei Xi <[email protected]> wrote: > Basically, I think that every struct in C should be first mapped to an > abstract type. > > Let us take the inode as an example. > > absvtype inode_ptr(l:addr) = ptr(l)
I have a question about avoiding errors in ATS language. Now you advice following code: https://github.com/jats-ug/practice-ats/blob/cd3693440273ae8b7bc429a898b7ac7c52e0f233/template_struct/gen.sats#L25 ``` absvtype struct_foo_ptr(l:addr) = ptr(l) typedef struct_foo = $extype_struct"struct foo" of { b = int, p = [l:addr] ptr(l), // struct bar *p pi = [l:addr] ptr(l) // int **pi } castfn takeout_struct_foo_ptr: {l:agz} (ptr(l)) -> struct_foo_ptr(l) castfn addback_struct_foo_ptr: {l:agz} (struct_foo_ptr(l)) -> void ``` The ATS code can avoid errors caused by NULL pointer. However, it can't catch miss cast for `ptr` type. I think the type equals `void *` in C. On C language side, we have following code: ``` struct bar; struct foo { int b; struct bar *p; int **pi; }; struct bar { int a; struct foo *p; }; ``` The C code can avoid miss cast for `void *` type. However, it can't catch errors caused by NULL pointer. Truly, we have no method to avoid both miss cast and NULL pointer??? Or we can avoid them, if drop mutual struct/record and use singly-pointer-linked struct/record? Best regards, -- Kiwamu Okabe at METASEPI DESIGN -- You received this message because you are subscribed to the Google Groups "ats-lang-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/ats-lang-users. To view this discussion on the web visit https://groups.google.com/d/msgid/ats-lang-users/CAEvX6dkS%2BknEQOemFR-9umJF9PFEX_fN3b%3DyctmAiVc9YF0W9g%40mail.gmail.com.
