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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:11:14+00:00 2026-05-28T00:11:14+00:00

While it’s very handy, I very rarely, if ever, come across functions that return

  • 0

While it’s very handy, I very rarely, if ever, come across functions that return structs (or unions) in C, whether they are dynamically linked functions or statically defined functions.
They instead return the data through a pointer parameter.

(An dynamic example in Windows is GetSystemInfo.)

What’s the reason behind this?
Is it because of a performance issue, an ABI compatibility issue, or something else?

  • 1 1 Answer
  • 1 View
  • 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-05-28T00:11:14+00:00Added an answer on May 28, 2026 at 12:11 am

    I would say “performance”, plus the fact that it’s even possible sometimes seems to surprise C programmers. It’s not … in the general “flavor” of C, to many, to throw around large things such as structs as if they were mere values. Which, according to the language, they really are.

    Along the same lines, many C programmers seem to automatically resort to memcpy() when the need to copy structs arises, rather than just using assignment, too.

    In C++ at least, there is something called “return value optimization” which is able to silently transform code like this:

    struct Point { int x, y; };
    
    struct Point point_new(int x, int y)
    {
      struct Point p;
      p.x = x;
      p.y = y;
      return p;
    }
    

    into:

    void point_new(struct Point *return_value, int x, int y)
    {
      struct Point p;
      p.x = x;
      p.y = y;
      *return_value = p;
    }
    

    which does away with the (potentially stack-hungry) “true” return of a struct value. I guess even better would be this, not sure if they’re that smart:

    void point_new(struct Point *return_value, int x, int y)
    {
      return_value->x = x;
      return_value->y = y;
    }
    

    I’m not sure if C compilers can do any of this, if they can’t then I guess that might be a real argument against struct returns, for very performance-critical programs.

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

Sidebar

Related Questions

While listening through Stanford's Programming Abstractions course, I come across some piece of code
While I understand the Math.round/ceil/floor functions in javascript, I have been unable to come
While using boost::threads I have come across this interruption problem. When I do a
While reading this class BitmapFactory I noticed that almost all methods inside are static.
While trying to install a program from source I found that it installed libraries
While looking at various options for making dropdowns more user-friendly I came across this
While working on an auditing project I came across different problems regarding software and
While debugging my NServiceBus enabled application, I have certain messages that are reported in
while working i messed HTML because i did not knew that <p> tag within
While editing and fixing up code I have thought that sometimes it would be

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.