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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:40:37+00:00 2026-06-12T13:40:37+00:00

Is it possible to pass structure by parameter ? Is it compatible with the

  • 0

Is it possible to pass structure by parameter ?

Is it compatible with the C abi ?

[edit]

Basically, I would like to have a C++ POD which would contain two members (the structure would be a fat pointer, with a pointer and an integer), and be able to pass this structure as function parameter in call instructions (even when calling C code).

I’m not using fat pointer now (the pointer and the integer are each in a different function parameter), and I would like to know if it’s possible before starting a pretty big refactoring !

  • 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-12T13:40:39+00:00Added an answer on June 12, 2026 at 1:40 pm

    You can do this.

    You can figure out what the LLVM code is for sample C by copying and pasting the C code into LLVM’s online demo at http://llvm.org/demo/index.cgi.

    If you copy and paste the code at codepad.org in, you’ll see that LLVM generates the following for myFunction:

    define void @_Z10myFunction10MyStruct_t(i8* %myStructAsParam.coerce0, i32     %myStructAsParam.coerce1) nounwind uwtable {
      %1 = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([23 x i8]* @.str, i64 0, i64 0), i8* %myStructAsParam.coerce0, i32 %myStructAsParam.coerce1)
      ret void
    }
    

    Of course, if you look at the call you’ll notice that no copy is being made. It’s up to the calling function to do that. If we write a small C function:

    void myCallingFunction(MyStruct_t *foobar)
    {
      myFunction(*foobar);
    }
    

    We can see that the LLVM bitcode generated for myCallingFunction is:

    define void @_Z17myCallingFunctionP10MyStruct_t(%struct.MyStruct_t* nocapture %foobar)   nounwind uwtable {
      %foobar.0 = getelementptr inbounds %struct.MyStruct_t* %foobar, i64 0, i32 0
      %tmp = load i8** %foobar.0, align 8
      %foobar.1 = getelementptr inbounds %struct.MyStruct_t* %foobar, i64 0, i32 1
      %tmp1 = load i32* %foobar.1, align 8
      %1 = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([23 x i8]* @.str, i64 0, i64 0), i8* %tmp, i32 %tmp1) nounwind
      ret void
    }
    

    The calling function makes a copy of the struct, and then passes in the address of the copy.

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

Sidebar

Related Questions

Is it possible to pass pointer to structure using JNA? Suppose I have a
Possible Duplicate: pass parameter in g:remoteLink as result of javascript function I am trying
Possible Duplicate: pass data from Action To Another Action I have a view in
Is it possible to pass TargetActivity.class to another activity and do something like: //
Is it possible to pass *args to string.format? I have the following function: @classmethod
Is it possible to pass more than one parameter to beginthreadex? I know I
Is it possible to pass a large Structure through JNI from C to Java?
Possible Duplicate: Pass a PHP string to a Javascript variable (including escaping newlines) Hy,
Possible Duplicate: pass by reference not working I was going through some of the
Is it possible to pass a request from java servlet and read that request

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.