Hi Hongwei,
On Sat, Aug 27, 2016 at 12:05 PM, gmhwxi <[email protected]> wrote:>
> It is not clear to me what you mean by 'miss cast'.
My 'miss cast' is meaning... If we have following code:
```
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)
absvtype struct_bar_ptr(l:addr) = ptr(l)
typedef struct_bar = $extype_struct"struct bar" of {
a = int,
p = [l:addr] ptr(l) // struct foo *p
}
castfn takeout_struct_bar_ptr: {l1:agz} (ptr(l1)) -> struct_bar_ptr(l1)
```
then we can write following code with some mistake that cast pointer
to foo as bar:
```
var foo: struct_foo
// ...
val bar_ptr = takeout_struct_bar_ptr (addr@foo)
val () = print_bar bar_ptr
val () = addback_struct_bar_ptr bar_ptr
```
> Maybe you should use cptr (instead of ptr):
>
> typedef struct_foo = $extype_struct"struct foo" of {
> b = int,
> p = cPtr0(struct_bool)
> pi = cPtr0(cPtr0(int))
> }
Umm......... I think we can't get this style.
Because we can't directly specify struct implemetation in the struct,
while using mutual struct.
> Honestly, I think 'struct_foo' should be abstract. Functions
> like struct_foo_get_b can and probably should be implemented in C directly.
Ah, it's also another simple solution.
I have not yet my feeling to decide using either ATS or C language in
such situation...
Thanks a lot,
--
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/CAEvX6dn_oSF%3DXtM_e_UOtUTLDtNOeoytJj4U19dCTPp9sBraNQ%40mail.gmail.com.