1. How to deal with C_POINTR?
- Posted by Liu Junfeng <rufi at 163.com> Mar 31, 2003
- 430 views
when define and call c_func often there are parameters passed by pointers, then how to send and get data if it is a c struct? -- My favorite languages: C#, Euphoria,Python, Haskell, Curry
2. Re: How to deal with C_POINTR?
- Posted by stabmaster_ at hotmail.com Mar 31, 2003
- 430 views
>when define and call c_func often there are parameters passed by >pointers, then how to send and get data if it is a c struct? Let's say you have: typedef struct { int a,b; } foo; foo *bar(foo *grill) { return grill; } Then you could do something like: constant FOO_A=0, FOO_B=4, SIZEOF_FOO=8 constant grill = allocate(SIZEOF_FOO) constant bar = define_c_func(blah,"bar",{C_POINTER},C_POINTER) grill = c_func(bar,{grill}) ? peek4s(grill+FOO_B) -- print grill->b
3. Re: How to deal with C_POINTR?
- Posted by Derek Parnell <ddparnell at bigpond.com> Mar 31, 2003
- 427 views
----- Original Message ----- From: <stabmaster_ at hotmail.com> To: "EUforum" <EUforum at topica.com> Subject: Re: How to deal with C_POINTR? > > >when define and call c_func often there are parameters passed by > >pointers, then how to send and get data if it is a c struct? > > Let's say you have: > > typedef struct > { > int a,b; > } foo; > > foo *bar(foo *grill) > { > return grill; > } The problem though is when you have something like ... foo bar(foo grill) { return grill; } In other words, the struct is passed by value, not as a pointer to struct. In this case, it is difficult. Sometimes, if the stuct ONLY has 32-bit values in it, you can fake passing it as a set of C_UINT values, but returning a struct is impossible, I suspect. ---------------- cheers, Derek Parnell
4. Re: How to deal with C_POINTR?
- Posted by stabmaster_ at hotmail.com Mar 31, 2003
- 445 views
I guess you could receive a structure using some assembly code, though i don't know how structs are returned by value. Can't exactly put in a register, so the stack would be probable.. Anyway, I can't see in what situation anyone would like to pass/return structs by value. If it's a dll written by someone else and you have the source code, then by all means fix it to do it the proper way (i.e. using pointers). > > >when define and call c_func often there are parameters passed by > > >pointers, then how to send and get data if it is a c struct? > > > > Let's say you have: > > > > typedef struct > > { > > int a,b; > > } foo; > > > > foo *bar(foo *grill) > > { > > return grill; > > } > >The problem though is when you have something like ... > > foo bar(foo grill) >{ > return grill; >} > >In other words, the struct is passed by value, not as a pointer to struct. > >In this case, it is difficult. Sometimes, if the stuct ONLY has 32-bit >values in it, you can fake passing it as a set of C_UINT values, but >returning a struct is impossible, I suspect. >
5. Re: How to deal with C_POINTR?
- Posted by "C. K. Lester" <cklester at yahoo.com> Mar 31, 2003
- 433 views
> If it's a dll written by someone else and you have the source code, > then by all means fix it to do it the proper way (i.e. using pointers). It's like I always say, "Work with the system, people!"