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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:54:07+00:00 2026-05-29T17:54:07+00:00

I have a .c file (a library of functions) with a function and a

  • 0

I have a .c file (a library of functions) with a function and a definition like this:

typedef long double big;
big foo(int x) { ... }

I want to create an interface of this library, an .h. So I do:

typedef long double big;
big foo(int);

and remove the typedef long double big; from the .c file. But by doing so I give away the type definition of big in my interface, so it’s not really a clean interface. Any ideas how to fix that?

I know I could do this in my .c file:

struct foo {
  long double;
};

and then in the .h file do:

typedef struct foo big;
big foo(int);

But it seems waste to create a struct for just one field, plus I should use the . operator whenever I want to read a big.

  • 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-05-29T17:54:10+00:00Added an answer on May 29, 2026 at 5:54 pm

    If the type is never going to get more complex than long double, then it probably isn’t worth having conniptions about hiding it more. If it might need to become more complex, then you can consider using an opaque type. In your public header, big.h, you use:

    #ifndef BIG_H_INCLUDED
    #define BIG_H_INCLUDED
    typedef struct big big_t;
    
    extern big_t *foo(int);
    
    ...
    
    #endif
    

    All the functions will take and return pointers to the big_t type. This is all you can do with incomplete types like that. Note that your customers cannot allocate any big_t values for themselves; they don’t know how big the type is. It means you’ll probably end up with functions such as:

    extern big_t *big_create(void);
    extern void   big_destroy(big_t *value);
    

    to create and destroy big_t values. Then they’ll be able to do arithmetic with:

    extern big_errno_t big_add(const big_t *lhs, const big_t *rhs, big_t *result);
    

    Etc. But because they only have an opaque, incomplete type, they cannot reliably go messing around inside a big_t structure. But note that you are constrained to using pointers in the interface. Passing or returning values requires complete types, and if the type is complete, users can investigate its inner workings.

    In the implementation header, bigimpl.h, you’ll have:

    #ifndef BIGIMPL_H_INCLUDED
    #define BIGIMPL_H_INCLUDED
    #include "big.h"
    
    struct big
    {
        ...whatever the details actually are...
    };
    
    #endif
    

    And your implementation code will only include bigimpl.h, but that includes big.h. The main issue here is making sure you know how the memory allocations are handled.

    Sometimes this technique is worthwhile. Often it is not really necessary. You’ll need to make the assessment for yourself.

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

Sidebar

Related Questions

I have a big project compiled into libProject.so-file (shared library), I made some modules
I have a static library (.lib file) on Windows platform, I want to know
I have a library I created, File mylib.c: #include <mylib.h> int testlib() { printf("Hello,
I have an ActionScript 2.0 file that contains a small library. This library parses
Basically I have code which looks like this inside a header file: class Bar;
I'd like to run unit test for a functions library file... that is, I
I have functions in a 'library' file to be called from my 'worker' script.
I have a binary file - Windows static library (*.lib). Is there a simple
I have existing Linux shared object file (shared library) which has been stripped. I
I have a .tag file that requires a JavaScript library (as in a .js

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.