11-03-2022, 09:16 PM
Print Using?
|
11-04-2022, 12:57 AM
11-04-2022, 03:47 PM
(This post was last modified: 11-04-2022, 10:09 PM by mnrvovrfc.
Edit Reason: Put my theory to test
)
Wait, how do I write a string function that resides in a "dot-H" file? Memory has to be allocated for it, right, not just the "char-star"? Use "alloca()" or "malloc()" in C, or "cheat" using the "string" class in C++? Does the string buffer, only for allocation of a function's return value, have to be allocated by BASIC code (use "SPACE$()") or by C/C++ code? The "DECLARE CUSTOMTYPE LIBRARY" works really well with writing functions returning the simple types, but many people, including myself, would be interested in doing the same thing for string.
This is the main reason why I prefer coding it as sub with the last parameter being a string that is the return value. There's no need to use "_OFFSET" or some other solution I don't like. With returning "_INTEGER64" or "SINGLE" or something else then the "DECLARE CUSTOMTYPE LIBRARY" way is fine. EDIT: I was able to figure it out with a strictly C method. Previously said "calloc()" above instead of "alloca()"; the former is like "malloc()" but is for setting up like an array, and the latter takes memory from the "stack" (function space) instead of the "heap" (global space). I hope it's all right using "alloca()" for allocating function return value because I've had an ugly experience with Psycle Lua scripting device; it was very easy to get it to run out of stack space so that music program crashed hard. Doing things in C/C++ means not having access to "qbs" system deep-rooted into QB64. My small knowledge and patience of C language paid off. Previously I tried to do it with C++ "string" class but it didn't work. I used "c_str()" method to copy the object away from "string" class variable and into an allocated "char-star" buffer but it didn't work. Had to make many adjustments to get it to compile successfully but didn't produce the expected output. EDIT #2: It is all right! From "man alloca" (man pages for "alloca()" C runtime library): Quote:DESCRIPTION |
« Next Oldest | Next Newest »
|
Users browsing this thread: 6 Guest(s)