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 7813555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:54:43+00:00 2026-06-02T04:54:43+00:00

I am trying to use a C macro from Vala. It seems to me

  • 0

I am trying to use a C macro from Vala. It seems to me that this should be possible with the CCode directive but I fail to find any meaningful documentation about how to use it.

There is a brief section about CCode arguments in “The Hacker’s Guide to Vala”
and a mailing list thread about calling a C macro from Vala with CCode.

But neither resource really helps me to understand what CCode really does. It obviously affects how Vala generates C code, from the Hackers’ Guide to Vala I can deduce that the CCode directive probably gives me direct influence into how the CCode tree is created when traversing Valas AST.

Could anybody explain a little more what CCode does?

  • 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-02T04:54:45+00:00Added an answer on June 2, 2026 at 4:54 am

    Unfortunately, there isn’t a great deal of documentation about CCode that makes sense alone. What you need to do is use it in conjunction with the VAPI files that comes with Vala. At its most basic, you will probably use your macro something like this:

    [CCode(cname = "FOO", cheader_filename = "blah.h")]
    public extern void foo();
    

    Here we are setting the cname (i.e., the name that will be emitted into the C code), and the cheader_filename (i.e., the header file that should be #included). Most of the other CCode attributes control how arrays are handled. array_length = false indicates that an array is of unknown length. This can be applied to a parameter or to the method, indicating that is applies to the return type. For instance:

    [CCode(array_length = false)] public int[] x();
    [CCode(array_null_terminated = true)] public FileStream[] y();
    public int[] z();
    

    In this example, x will have unknown array length and have an expected C prototype of int *x(void), while y is assumed to have a null-terminated array with the expected C prototype of FILE **y(void). Finally, z is assumed to have an array length out parameter (i.e., a prototype of int *z(int *length), where length is a pointer to where to store the length of the returned array.

    All of these can be applied to parameters too. It’s also useful to specify array_length_pos if there is an array length but it is not the argument immediately after the array. If a parameter is a delegate, target_pos specifies where the user data is passed (i.e., the void* that goes with the function pointer).

    There’s also a variety of CCode attributes for use with delegates, classes, and structs. instance_pos specifies where the class/struct instance or delegate user data goes. All of the position arguments are specified with a floating point number. This allows multiple positions to be encoded. For instance, suppose we had a C prototype:

    void foo(void* userdata, int length, double *dbl_array, void(*handler)(double,void*));
    

    then we might write this:

    [CCode(cname = "foo")]
    public void foo([CCode(array_length_pos = 0.2)] double[] array, [CCode(target_pos = 0.1)] Handler func);
    

    Given Handler is defined as a delegate elsewhere, you can see that the pos values put the arguments after argument 0 (i.e., the start) and then in a particular order.

    Classes and structs have functions to handle initialisation, destruction, and reference counting, but those are fairly straight forward. Handling generics is also a bit complicated. Again, the VAPIs are the best source of insight. However, that’s enough to get you started on your basic C functions and macros.

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

Sidebar

Related Questions

I am trying to use the _MSC_VER macro in a Visual Studio 2005.NET C++
I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
Trying to use this method (gist of which is use self.method_name in the FunnyHelper
Trying to use this code to connect the AD PrincipalContext context = new PrincipalContext(ContextType.Domain,
I was trying to use XTEA encryption on NETMF using the code from blog
I'm trying to use ActiveSheet.CustomProperties to temporarily store my macro's settings for each worksheet.
I am trying to use the Worksheet Change Event in Excel VBA, but it
I am trying to use ASIO (Audio Stream Input/Output). I downloaded SDK, but because
I've been trying to use the system call ptrace (using the PTRACE_SINGLESTEP macro) to
I have a macro that might look as follows (from boost log library) #define

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.