Call c----type conversion in Go language

Source: Internet
Author: User

1. Basic type conversion is simple, directly with coercion type conversion can be, as follows:

Go convert to C:var i intci: = C.int (i) C convert to Go:var i c.intgoi: = Int (i)

2. String type conversion is also not very difficult, one thing to note is that you need to make a small change in converting the char array in C to go string, as follows:

Go convert to C:var str stringcstr: = c.cstring (str) C convert to go:/* #include <stdlib.h> #include <stdio.h>char foo[] = " Hellofoo "; char *bar =" HelloBar "; */import" C "import" FMT "Func Main () {FMT. Printf ("%s\n", C.gostring (&c.foo[0])) FMT. Printf ("%s\n", C.gostring (C.bar))}

3. Array type conversions

The following is an example of an int array, as follows:



This article is from the "Linux related" blog, so be sure to keep this source http://diadia.blog.51cto.com/5440926/1737451

Call c----type conversion in Go language

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.