In doing this, I've encountered a situation where I need to define a stru=
ct in forth (using the forth-2012 begin-structure & end-structure words) th= >at I will then pass to a C function. My question is, how do I know how muc= >h memory & padding each field should have?
Is there some resource that exp=
lains how C handles struct creation?
Troy Jacobs <tmj...@gmail.com> writes:Thanks, I appreciate the help! :)
In doing this, I've encountered a situation where I need to define a stru=The best way is to ask the C compiler, with the offsetof macro, and
ct in forth (using the forth-2012 begin-structure & end-structure words) th= >at I will then pass to a C function. My question is, how do I know how muc= >h memory & padding each field should have?
use the resulting numbers in Forth with +FIELD.
Gerald Wodni has extended SWIG to automate much of this work (but he
is in the process of revising his SWIG approach, so don't invest more
than necessary in the current approach). You can find more about this
in <https://gforth.org/manual/Automated-interface-generation-using-SWIG.html>.
Following this, I find <https://github.com/GeraldWodni/forth-c-interfaces/tree/master/glfw3>
("LFW is an Open Source, multi-platform library for OpenGL, OpenGL ES
and Vulkan development on the desktop. It provides a simple API for
creating windows, contexts and surfaces, receiving input and
events."), which may be of interest to you (or you can use it as an
example for how to use SWIG for the C interface).
Is there some resource that exp=Maybe the ABI documentation, but the best bet is to ask the C
lains how C handles struct creation?
compiler, as discussed above.
- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: http://www.forth200x.org/forth200x.html
EuroForth 2021: https://euro.theforth.net/2021
On Wednesday, April 20, 2022 at 5:31:50 PM UTC-4, Anton Ertl wrote:Apologies for the confusion, I have multiple Google accounts, and sometimes I accidentally use the wrong one. That last comment was my other account.
Troy Jacobs <tmj...@gmail.com> writes:
In doing this, I've encountered a situation where I need to define a stru=The best way is to ask the C compiler, with the offsetof macro, and
ct in forth (using the forth-2012 begin-structure & end-structure words) th=
at I will then pass to a C function. My question is, how do I know how muc=
h memory & padding each field should have?
use the resulting numbers in Forth with +FIELD.
Gerald Wodni has extended SWIG to automate much of this work (but he
is in the process of revising his SWIG approach, so don't invest more
than necessary in the current approach). You can find more about this
in <https://gforth.org/manual/Automated-interface-generation-using-SWIG.html>.
Following this, I find <https://github.com/GeraldWodni/forth-c-interfaces/tree/master/glfw3>
("LFW is an Open Source, multi-platform library for OpenGL, OpenGL ES
and Vulkan development on the desktop. It provides a simple API for creating windows, contexts and surfaces, receiving input and
events."), which may be of interest to you (or you can use it as an
example for how to use SWIG for the C interface).
Is there some resource that exp=Maybe the ABI documentation, but the best bet is to ask the C
lains how C handles struct creation?
compiler, as discussed above.
- antonThanks, I appreciate the help! :)
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html New standard: http://www.forth200x.org/forth200x.html
EuroForth 2021: https://euro.theforth.net/2021
Troy Jacobs <tmj9001@gmail.com> writes:
In doing this, I've encountered a situation where I need to define a stru= >>ct in forth (using the forth-2012 begin-structure & end-structure words) th= >>at I will then pass to a C function. My question is, how do I know how muc= >>h memory & padding each field should have?
The best way is to ask the C compiler, with the offsetof macro, and
use the resulting numbers in Forth with +FIELD.
Gerald Wodni has extended SWIG to automate much of this work (but he
is in the process of revising his SWIG approach, so don't invest more
than necessary in the current approach). You can find more about this
in ><https://gforth.org/manual/Automated-interface-generation-using-SWIG.html>.
Following this, I find ><https://github.com/GeraldWodni/forth-c-interfaces/tree/master/glfw3>
("LFW is an Open Source, multi-platform library for OpenGL, OpenGL ES
and Vulkan development on the desktop. It provides a simple API for
creating windows, contexts and surfaces, receiving input and
events."), which may be of interest to you (or you can use it as an
example for how to use SWIG for the C interface).
Is there some resource that exp=
lains how C handles struct creation?
Maybe the ABI documentation, but the best bet is to ask the C
compiler, as discussed above.
- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html >comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: http://www.forth200x.org/forth200x.html
EuroForth 2021: https://euro.theforth.net/2021
In article <2022Apr2...@mips.complang.tuwien.ac.at>,This is also super helpful, thank you! :D
Anton Ertl <an...@mips.complang.tuwien.ac.at> wrote:
Troy Jacobs <tmj...@gmail.com> writes:
In doing this, I've encountered a situation where I need to define a stru= >>ct in forth (using the forth-2012 begin-structure & end-structure words) th=
at I will then pass to a C function. My question is, how do I know how muc= >>h memory & padding each field should have?
The best way is to ask the C compiler, with the offsetof macro, and
use the resulting numbers in Forth with +FIELD.
Gerald Wodni has extended SWIG to automate much of this work (but he
is in the process of revising his SWIG approach, so don't invest more
than necessary in the current approach). You can find more about this
in ><https://gforth.org/manual/Automated-interface-generation-using-SWIG.html>.
Following this, I find ><https://github.com/GeraldWodni/forth-c-interfaces/tree/master/glfw3>
("LFW is an Open Source, multi-platform library for OpenGL, OpenGL ES
and Vulkan development on the desktop. It provides a simple API for >creating windows, contexts and surfaces, receiving input and
events."), which may be of interest to you (or you can use it as an
example for how to use SWIG for the C interface).
Is there some resource that exp=
lains how C handles struct creation?
Maybe the ABI documentation, but the best bet is to ask the CIn addition to this you, want the actual value of symbolic constants
compiler, as discussed above.
that are generally not documented in man pages.
You may find the macro's in the following program useful.
For Forth you may replace EQU with CONSTANT and 0x with $.
----------------------------8<-----------------------------------
/* This c-source is intended to be print a number of EQUATES */
/* that can be included in assembler files. */
#include <stdio.h>
#include <stdlib.h>
#include <sys/times.h>
... etc ...
/* Steal the information what value B has, leave it in A */
#define STEAL(A,B) printf("%s\tEQU\t0x%x\n", A, B );
/* Have a A that has the same value than in C. */
#define STEALNAME(A) STEAL( #A, A)
/* Have a A that has the number of system call B */
#define STEALSYS(A) STEAL( #A, __NR_##A)
int main()
{
printf("include(stealconstant.m4) \n");
STEALNAME(SEEK_CUR)
STEALNAME(SEEK_SET)
.... etc ....
STEAL("SIZE_TERMIO",sizeof(struct termios))
printf("_C{ https://github.com/torvalds/linux/tree/master/arch/x86/entry/syscalls}\n");
STEALSYS(exit)
STEALSYS(unlink)
.... etc ...
STEALNAME(__NR_times)
exit(0);
}
-------------------------- 8<--------------------
- anton--
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html >comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: http://www.forth200x.org/forth200x.html
EuroForth 2021: https://euro.theforth.net/2021
"in our communism country Viet Nam, people are forced to be
alive and in the western country like US, people are free to
die from Covid 19 lol" duc ha
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 300 |
Nodes: | 16 (2 / 14) |
Uptime: | 52:40:44 |
Calls: | 6,712 |
Files: | 12,243 |
Messages: | 5,355,180 |