Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8844055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:23:26+00:00 2026-06-14T11:23:26+00:00

Currently I’m using Cgo to call C functions from Go. I’m trying to recreate

  • 0

Currently I’m using Cgo to call C functions from Go. I’m trying to recreate the ‘Read a Photo’ example in Go.

One on the C functions, however, expects a int* len argument (bonus question; is that the same as int *len?). As I read this, this is a pointer to an integer. The function in question is ccv_write of the libccv library. It’s full signature is:

int ccv_write(ccv_dense_matrix_t* mat, char* out, int* len, int type, void* conf)

The relevant code snippet is as follows:

type Image struct {
    image *C.ccv_dense_matrix_t
}

func main() {
    image := new(Image)

    /* ... snip ... */

    dst := C.CString("black_and_white_painting.jpg")
    defer C.free(unsafe.Pointer(dst))
    x := 0 // <- perhaps var x int ?
    C.ccv_write(image.image, dst, (*C.int)(&x), C.CCV_IO_PNG_FILE, 0)
}

The above example generates the following compile time error: cannot convert &x (type *int) to type *_Ctype_int

Any thoughts on how to pass the correct argument?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T11:23:27+00:00Added an answer on June 14, 2026 at 11:23 am

    The issue here is you have two different types. You have an int which is defined by your Go compiler and C.int which is defined by your C compiler. Depending on the compilers and architecture these may be the same size. However, it is very possible that int will be 64 bits in size and C.int would be 32 bits.

    In order for the compiler to enforce the type safety, it requires you to do an explicit conversion or define the type at initialization.

    In your example, you do: x := 0. This is the same as x := int(0). The int is implied. Instead, you can do x := C.int(0).

    However, I think the “cleaner” method would be to do what jnml recommended: var x C.int. This does exactly the same thing but just looks nicer.


    Later, you will most likely want to convert that C.int back to an int. This is easy to do with a conversion.

    y := int(x)
    

    This will convert x to an int and then copy that value into the newly initialized variable y.


    Bonus Anwser: int* len is indeed the same as int *len

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently playing about with KnockoutJS. Just trying to update an observable array from a
Currently i'm having trouble using two functions in my -(void)viewDidLoad , both of these
Currently I am using HTML files for parts of my user interface. I display
currently, I`m implementing a map App with Mono4Droid and there I`m using a WebView
Currently I'm starting a new Activity and calling finish on a current one. Is
Currently I am trying to use a bunch of custom perl modules, test.pm as
currently i am saving user uploaded image files as follows: public_html/img/user/$category/$username/$imagename however, is this
Currently I am using Amazon Cloudfront to service static objects on my ASP.Net MVC3
Currently, I have a log file of messages in one table in a MySQL
Currently I'm using the Jackson JSON Processor to write preference data and whatnot to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.