1. Phix: c-struct
- Posted by andreasWagner 2 weeks ago
- 250 views
Hallo
I've been experimenting with phix again. I wanted to take a look at this c-struct.
So I copied the example from the documentation, but unfortunately didn't get very far.
struct rect """ typedef struct _RECT { LONG left; LONG top; LONG right; LONG bottom; } RECT, *PRECT; """ end struct rect q = new({10,10,350,200}), r = new() r.left = 10 --\ equivalent to using the r.top = 10 -- } {10,10,350,200} above r.right = 350 -- } and/or m = allocate(16) r.bottom = 200 --/ & poke4(m+0/4/8/12,..). -- then eg c_proc(xFillRect,{hDC,struct_mem(r|q)|m,hBrush})
ended like this
D:\testpool\ray_test\struct_test.ex:10
type check failure, q is {"struct","rect",2,10910404.0}
Global & Local Variables
--> see D:\testpool\ray_test\ex.err
Press Enter...
Am I doing something wrong, or have I simply misunderstood?(Phix 1.05 32/64bit)
Thank you.
2. Re: Phix: c-struct
- Posted by petelomax 2 weeks ago
- 213 views
Oh dear. That works fine in 0.8.2 but is broken in 1.0.1 and everything after...
Obviously no-one, including myself, has used c-structs in the last five years, so I'm inclined to just drop 'em.
Anyway, a c-struct was only ever meant to be a thin wrapper to the following, which still works fine.
include cffi.e constant idRECT = define_struct(""" typedef struct _RECT { LONG left; LONG top; LONG right; LONG bottom; } RECT, *PRECT;""") -- replaces 'q', could be named that: atom pRECT = allocate_struct(idRECT) -- The above is still equivalent to allocate, but with size auto-calculated, -- and the following are still equivalent to poke(), with offset&size "". set_struct_field(idRECT,pRECT,"left",10) set_struct_field(idRECT,pRECT,"top",10) set_struct_field(idRECT,pRECT,"right",350) set_struct_field(idRECT,pRECT,"bottom",200)
So unless anyone has any serious objections, I'm just going to delete all references to c-struct in the docs,
and clean up builtins/structs.e and pmain.e a bit, and leave it at that. You good with that?
3. Re: Phix: c-struct
- Posted by andreasWagner 2 weeks ago
- 197 views
Oh dear. That works fine in 0.8.2 but is broken in 1.0.1 and everything after...
Obviously no-one, including myself, has used c-structs in the last five years, so I'm inclined to just drop 'em.
Anyway, a c-struct was only ever meant to be a thin wrapper to the following, which still works fine.
include cffi.e constant idRECT = define_struct(""" typedef struct _RECT { LONG left; LONG top; LONG right; LONG bottom; } RECT, *PRECT;""") -- replaces 'q', could be named that: atom pRECT = allocate_struct(idRECT) -- The above is still equivalent to allocate, but with size auto-calculated, -- and the following are still equivalent to poke(), with offset&size "". set_struct_field(idRECT,pRECT,"left",10) set_struct_field(idRECT,pRECT,"top",10) set_struct_field(idRECT,pRECT,"right",350) set_struct_field(idRECT,pRECT,"bottom",200)
So unless anyone has any serious objections, I'm just going to delete all references to c-struct in the docs,
and clean up builtins/structs.e and pmain.e a bit, and leave it at that. You good with that?
Thanks for the prompt reply. It's good to see that Phix is still being actively developed.
Of course, I can only speak for myself. Naturally, I would prefer dot notation. But since I haven't really used c-struct, I won't miss it. These things are for code that you write once and then it disappears into an include file that you hopefully never have to look at again.
By the way, I've only been using Phix since version 1.02 or 1.03 for more than just testing.
So it's okay for me.
4. Re: Phix: c-struct
- Posted by petelomax 1 week ago
- 177 views
It's good to see that Phix is still being actively developed.
Sometimes I wonder why I bother, then I have a week like I've just had and I realise it's because I enjoy it!
I've been struggling with a new GUI, and finally bit the bullet at the end of November, threw 0.1 in the bin
and started a brand new 0.2: two months of hard slog with not much to show, then it suddenly burst into life.
Several days nailing down a few things and a tough time ironing out all the bugs in the new layout manager,
then this week everything I touch is just turning to gold
Naturally, I would prefer dot notation.
Me too, but a) I can't justify it, and b) what the language really deserves, and even I would use, is summat like:
#ilSTRUCT("""
typedef struct RECT {
LONG left;
LONG top;
LONG right;
LONG bottom;
}""") // (so the inline assembler now understands what a RECT is, at compile-time [only])
#ilASM {
mov ecx, RECT.length
call :%pGetPool // aka eax := allocate(sizeof(RECT))
pragma struct RECT eax // an assembly directive, aka "eax is a *RECT"
mov [eax.left], 10
mov [eax.top], 10
mov [eax.right], 350
mov [eax.bottom], 200
pragma struct none eax // switch off the special eax dot handling
}
Which emits the perfect super-fast machine code to do these things. One day, maybe, but probably not soon.To clarify: hll code using dot notation calling generic code in builtins/structs.e is daft compared to asm.
The #ilASM would just treat mov [eax.top], 10 as if it said mov dword[eax+4], 10 ie automate size/offset.
5. Re: Phix: c-struct
- Posted by andreasWagner 1 week ago
- 154 views
Hello,
Somehow I couldn't resist responding.
Which emits the perfect super-fast machine code to do these things. One day, maybe, but probably not soon.
To clarify: hll code using dot notation calling generic code in builtins/structs.e is daft compared to asm.
The #ilASM would just treat mov [eax.top], 10 as if it said mov dword[eax+4], 10 ie automate size/offset.
Please do not take the following text as criticism. It is simply my opinion and also the reason why I program in HLL.
Even though I am sure that such function calls in assembler are extremely fast and flexible and can cover all special cases in function calls.
I am also certain that the effort involved in writing all calls in assembler, especially if the code is to support multiple architectures (e.g., 32/64-bit), is disproportionate to the result for a simple hobby programmer like me.
So in the future, I will probably always use Phix system_exec() instead of trying to use CreateProcessEx from the WinApi in an assembler routine in the hope that something would run faster or be more optimized.
Maybe not a good example, but hopefully it explains my point of view.
6. Re: Phix: c-struct
- Posted by petelomax 1 week ago
- 166 views
You got nothing to worry about there, I'm not inclined to trash anything anyone actually uses.
As you mentioned and I was only rambling on about some obscure write once forget about areas where extra effort is justifiable.

