--
You received this message because you are subscribed to the Google Groups "Crystal" group.
To unsubscribe from this group and stop receiving emails from it, send an email to crystal-lang+unsubscribe@googlegroups.com.
To post to this group, send email to crysta...@googlegroups.com.
Visit this group at https://groups.google.com/group/crystal-lang.
To view this discussion on the web visit https://groups.google.com/d/msgid/crystal-lang/94046b5c-1358-4133-ab32-76e9310661d4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Crystal" group.
To unsubscribe from this group and stop receiving emails from it, send an email to crystal-lang+unsubscribe@googlegroups.com.
To post to this group, send email to crysta...@googlegroups.com.
Visit this group at https://groups.google.com/group/crystal-lang.
To view this discussion on the web visit https://groups.google.com/d/msgid/crystal-lang/94046b5c-1358-4133-ab32-76e9310661d4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Indeed, `const char *const *argv` is an array of C strings.Tim Uckun reply would have been correct if just a single `*` appeared on the code, but there are two (so it's a pointer to a pointer).A C char in Crystal lib is LibC::Char, or just UInt8. Adding two pointers you get LibC::Char**, or UInt8**.If you have an `Array(String)`, then invoking `to_unsafe` on it (or just passing it to C, which will try to invoke `to_unsafe` for you) will give you something of type `Pointer(String)`, which is not `Pointer(UInt8*)` or `Pointer(Pointer(UInt8))`. This can be done with `map`:strings.map(&.to_unsafe)This will make it be `Array(Pointer(UInt8))`, and when invoking `to_unsafe` on that you'll get `Pointer(Pointer(UInt8))`. I don't know a better way of doing that.Here's some code that compiles:~~~lib LibFoofun foo(x : UInt8**)endstrings = ["foo", "bar", "baz"]LibFoo.foo(strings.map(&.to_unsafe))~~~
On Wed, Jan 4, 2017 at 2:21 AM, BobTheJanitor <0bobthe...@gmail.com> wrote:
I have a c function with the parameters
> int argc
> const char *const *argv
I'm not too fluent in C, but I believe this represents a pointer to an array of strings. But the Crystal Compiler won't let me pass an array, or a pointer of an array
> only primitive types, pointers, structs, unions, enums and tuples are allowed in lib declarations, not Pointer(Array(String)
Please explain what I'm doing wrong.
--
You received this message because you are subscribed to the Google Groups "Crystal" group.
To unsubscribe from this group and stop receiving emails from it, send an email to crystal-lang...@googlegroups.com.
To post to this group, send email to crysta...@googlegroups.com.
Visit this group at https://groups.google.com/group/crystal-lang.
To view this discussion on the web visit https://groups.google.com/d/msgid/crystal-lang/94046b5c-1358-4133-ab32-76e9310661d4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.