Static library structs and includesWhat is the difference between #include <filename> and #include “filename”?What does “static” mean in C?typedef struct vs struct definitionsDifference between static and shared libraries?Telling gcc directly to link a library staticallyDifference between shared objects (.so), static libraries (.a), and DLL's (.so)?Static Library Include Issue in CC: initialising global constants with external linkageIs it possible to hide a portion of a standard header (in C)?Including header file from static library

Why do Russians call their women expensive ("дорогая")?

Yandex Programming Contest: Alarms

What does the term “mohel” mean in Hilchot Melicha (salting)?

shutdown at specific date

Were pen cap holes designed to prevent death by suffocation if swallowed?

Is there any use case for the bottom type as a function parameter type?

Could I be denied entry into Ireland due to medical and police situations during a previous UK visit?

Split polygon using another polygon in QGIS

Is floating in space similar to falling under gravity?

Is a post-climate apocolypse city in which many or most insects have disappeared realistic?

What are these (utility?) boxes at the side of the house?

Can a Beholder use rays in melee range?

Infinitely many hats

Declining an unreasonable request from a superior

Is this story about US tax office reasonable?

Can a wire having a 610-670 THz (frequency of blue light) AC frequency supply, generate blue light?

File globbing pattern, !(*example), behaves differently in bash script than it does in bash shell

Which noble houses were destroyed during the Game of Thrones?

What does uniform continuity mean exactly?

Restoring order in a deck of playing cards

What problems does SciDraw still solve?

Ticket sales for Queen at the Live Aid

Can the Help action be used to give advantage to a specific ally's attack (rather than just the next ally who attacks the target)?

What's the connection between "kicking a pigeon" and "how a bill becomes a law"?



Static library structs and includes


What is the difference between #include <filename> and #include “filename”?What does “static” mean in C?typedef struct vs struct definitionsDifference between static and shared libraries?Telling gcc directly to link a library staticallyDifference between shared objects (.so), static libraries (.a), and DLL's (.so)?Static Library Include Issue in CC: initialising global constants with external linkageIs it possible to hide a portion of a standard header (in C)?Including header file from static library






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








2















I'm building up a static embedded C-library, which has an API header file, that lists all available functions. I am not sure about a few thing, that I would like to clarify first before I start implementing it.



First of all, since this is a C-Library for embedded systems, which has hardware FPU, I'm not sure what I should include to calculate the math functions like sinf() etc. Normally I use the hardware specific includes, but that is not avialable in this static C-library, since it can run on some STM32 or even some AVR etc. How can I solve this problem?



Further Lets say I have the files foo.c and foo.h, which provide some hidden functions in the library and then there is the api.h, which can be seen by a user and api.c, which is also hidden. In foo.h are now some structs defined, that I would like to return in a callback to a user. Since this structs are hidden, I'm not sure how I should handle this callbacks. Should I implement a handler in api.c, which maps the structs from the callback from foo.c and pass them to the users callback, where the structs are redefined (with different name) in api.h or are there solutions with less overhead?



When I would define the necessary structs for foo.h in api.h, I would need to include api.h in foo.h, but also foo.h in api.h, that is not a good idea I think.










share|improve this question
























  • When you say "static embedded C-library" you mean a library which has nothing to do with the standard C library (the one which provides stdlib.h among others)?

    – Simon Doppler
    Mar 24 at 9:16











  • With static embedded C-library I mean a lib.a file, a project compiled as a library.

    – HansPeterLoft
    Mar 24 at 9:30


















2















I'm building up a static embedded C-library, which has an API header file, that lists all available functions. I am not sure about a few thing, that I would like to clarify first before I start implementing it.



First of all, since this is a C-Library for embedded systems, which has hardware FPU, I'm not sure what I should include to calculate the math functions like sinf() etc. Normally I use the hardware specific includes, but that is not avialable in this static C-library, since it can run on some STM32 or even some AVR etc. How can I solve this problem?



Further Lets say I have the files foo.c and foo.h, which provide some hidden functions in the library and then there is the api.h, which can be seen by a user and api.c, which is also hidden. In foo.h are now some structs defined, that I would like to return in a callback to a user. Since this structs are hidden, I'm not sure how I should handle this callbacks. Should I implement a handler in api.c, which maps the structs from the callback from foo.c and pass them to the users callback, where the structs are redefined (with different name) in api.h or are there solutions with less overhead?



When I would define the necessary structs for foo.h in api.h, I would need to include api.h in foo.h, but also foo.h in api.h, that is not a good idea I think.










share|improve this question
























  • When you say "static embedded C-library" you mean a library which has nothing to do with the standard C library (the one which provides stdlib.h among others)?

    – Simon Doppler
    Mar 24 at 9:16











  • With static embedded C-library I mean a lib.a file, a project compiled as a library.

    – HansPeterLoft
    Mar 24 at 9:30














2












2








2








I'm building up a static embedded C-library, which has an API header file, that lists all available functions. I am not sure about a few thing, that I would like to clarify first before I start implementing it.



First of all, since this is a C-Library for embedded systems, which has hardware FPU, I'm not sure what I should include to calculate the math functions like sinf() etc. Normally I use the hardware specific includes, but that is not avialable in this static C-library, since it can run on some STM32 or even some AVR etc. How can I solve this problem?



Further Lets say I have the files foo.c and foo.h, which provide some hidden functions in the library and then there is the api.h, which can be seen by a user and api.c, which is also hidden. In foo.h are now some structs defined, that I would like to return in a callback to a user. Since this structs are hidden, I'm not sure how I should handle this callbacks. Should I implement a handler in api.c, which maps the structs from the callback from foo.c and pass them to the users callback, where the structs are redefined (with different name) in api.h or are there solutions with less overhead?



When I would define the necessary structs for foo.h in api.h, I would need to include api.h in foo.h, but also foo.h in api.h, that is not a good idea I think.










share|improve this question
















I'm building up a static embedded C-library, which has an API header file, that lists all available functions. I am not sure about a few thing, that I would like to clarify first before I start implementing it.



First of all, since this is a C-Library for embedded systems, which has hardware FPU, I'm not sure what I should include to calculate the math functions like sinf() etc. Normally I use the hardware specific includes, but that is not avialable in this static C-library, since it can run on some STM32 or even some AVR etc. How can I solve this problem?



Further Lets say I have the files foo.c and foo.h, which provide some hidden functions in the library and then there is the api.h, which can be seen by a user and api.c, which is also hidden. In foo.h are now some structs defined, that I would like to return in a callback to a user. Since this structs are hidden, I'm not sure how I should handle this callbacks. Should I implement a handler in api.c, which maps the structs from the callback from foo.c and pass them to the users callback, where the structs are redefined (with different name) in api.h or are there solutions with less overhead?



When I would define the necessary structs for foo.h in api.h, I would need to include api.h in foo.h, but also foo.h in api.h, that is not a good idea I think.







c static-libraries






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 24 at 9:09







HansPeterLoft

















asked Mar 24 at 9:01









HansPeterLoftHansPeterLoft

1251113




1251113












  • When you say "static embedded C-library" you mean a library which has nothing to do with the standard C library (the one which provides stdlib.h among others)?

    – Simon Doppler
    Mar 24 at 9:16











  • With static embedded C-library I mean a lib.a file, a project compiled as a library.

    – HansPeterLoft
    Mar 24 at 9:30


















  • When you say "static embedded C-library" you mean a library which has nothing to do with the standard C library (the one which provides stdlib.h among others)?

    – Simon Doppler
    Mar 24 at 9:16











  • With static embedded C-library I mean a lib.a file, a project compiled as a library.

    – HansPeterLoft
    Mar 24 at 9:30

















When you say "static embedded C-library" you mean a library which has nothing to do with the standard C library (the one which provides stdlib.h among others)?

– Simon Doppler
Mar 24 at 9:16





When you say "static embedded C-library" you mean a library which has nothing to do with the standard C library (the one which provides stdlib.h among others)?

– Simon Doppler
Mar 24 at 9:16













With static embedded C-library I mean a lib.a file, a project compiled as a library.

– HansPeterLoft
Mar 24 at 9:30






With static embedded C-library I mean a lib.a file, a project compiled as a library.

– HansPeterLoft
Mar 24 at 9:30













1 Answer
1






active

oldest

votes


















2














For the first part of the question, the mathematical operations like sinf should be handled by the C standard library (you should check you specific version for support on your architecture). You can then use the math.h header and its functions, the compiler should then use the FPU to make the floating point computations.




For the second part, the usual way to show the user a hidden structure is with a foward declaration but the user will have to interact with the structure through pointers and access functions.



With you example, say we have four files:




  • api.h: public header


  • api.c: source code for functions from the public header


  • foo.h: library internal header (will not be shipped to the end-user)


  • foo.c: source code for the internal functions

The api.h is the only interesting file of those (have no changes).



// file: api.h
#ifndef API_H
#define API_H

struct foo; // forward declaration of the foo structure

typedef void (*callback_t)(struct foo*); // typedef for a callback taking a
// struct foo argument

void set_callback(callback_t fn);
#endif


Now we have a type for the callback and the type of the structure given to the callback, but the user cannot interact with the structure itself, since the compiler only knows it exists but does not know its content (nor storage size).



When the user writes a callback like in the below code, the user will need to have some access functions.



#include "api.h"

void user_callback(struct foo* arg)
// user code here



The access functions are usually defined like this:



// in the file api.h or another header that the user has access to

int foo_get_value1(struct foo* arg);
void foo_set_value1(struct foo* arg, int new_value);


and those functions would be implemented in foo.c



struct foo 
int value1;
int value2;
;

int foo_get_value1(struct foo* arg)
return arg->value1;


void foo_set_value1(struct foo* arg, int new_value)
arg->value1 = new_value;



This approach has the added advantage that your foo_set functions can do validity checks to make sure you have appropriate values in your structure.



Please note: I did not add any checks to my access functions to avoid cluttering the code, but when passing a pointer to a function, you should always check it for NULL






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55322161%2fstatic-library-structs-and-includes%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    For the first part of the question, the mathematical operations like sinf should be handled by the C standard library (you should check you specific version for support on your architecture). You can then use the math.h header and its functions, the compiler should then use the FPU to make the floating point computations.




    For the second part, the usual way to show the user a hidden structure is with a foward declaration but the user will have to interact with the structure through pointers and access functions.



    With you example, say we have four files:




    • api.h: public header


    • api.c: source code for functions from the public header


    • foo.h: library internal header (will not be shipped to the end-user)


    • foo.c: source code for the internal functions

    The api.h is the only interesting file of those (have no changes).



    // file: api.h
    #ifndef API_H
    #define API_H

    struct foo; // forward declaration of the foo structure

    typedef void (*callback_t)(struct foo*); // typedef for a callback taking a
    // struct foo argument

    void set_callback(callback_t fn);
    #endif


    Now we have a type for the callback and the type of the structure given to the callback, but the user cannot interact with the structure itself, since the compiler only knows it exists but does not know its content (nor storage size).



    When the user writes a callback like in the below code, the user will need to have some access functions.



    #include "api.h"

    void user_callback(struct foo* arg)
    // user code here



    The access functions are usually defined like this:



    // in the file api.h or another header that the user has access to

    int foo_get_value1(struct foo* arg);
    void foo_set_value1(struct foo* arg, int new_value);


    and those functions would be implemented in foo.c



    struct foo 
    int value1;
    int value2;
    ;

    int foo_get_value1(struct foo* arg)
    return arg->value1;


    void foo_set_value1(struct foo* arg, int new_value)
    arg->value1 = new_value;



    This approach has the added advantage that your foo_set functions can do validity checks to make sure you have appropriate values in your structure.



    Please note: I did not add any checks to my access functions to avoid cluttering the code, but when passing a pointer to a function, you should always check it for NULL






    share|improve this answer



























      2














      For the first part of the question, the mathematical operations like sinf should be handled by the C standard library (you should check you specific version for support on your architecture). You can then use the math.h header and its functions, the compiler should then use the FPU to make the floating point computations.




      For the second part, the usual way to show the user a hidden structure is with a foward declaration but the user will have to interact with the structure through pointers and access functions.



      With you example, say we have four files:




      • api.h: public header


      • api.c: source code for functions from the public header


      • foo.h: library internal header (will not be shipped to the end-user)


      • foo.c: source code for the internal functions

      The api.h is the only interesting file of those (have no changes).



      // file: api.h
      #ifndef API_H
      #define API_H

      struct foo; // forward declaration of the foo structure

      typedef void (*callback_t)(struct foo*); // typedef for a callback taking a
      // struct foo argument

      void set_callback(callback_t fn);
      #endif


      Now we have a type for the callback and the type of the structure given to the callback, but the user cannot interact with the structure itself, since the compiler only knows it exists but does not know its content (nor storage size).



      When the user writes a callback like in the below code, the user will need to have some access functions.



      #include "api.h"

      void user_callback(struct foo* arg)
      // user code here



      The access functions are usually defined like this:



      // in the file api.h or another header that the user has access to

      int foo_get_value1(struct foo* arg);
      void foo_set_value1(struct foo* arg, int new_value);


      and those functions would be implemented in foo.c



      struct foo 
      int value1;
      int value2;
      ;

      int foo_get_value1(struct foo* arg)
      return arg->value1;


      void foo_set_value1(struct foo* arg, int new_value)
      arg->value1 = new_value;



      This approach has the added advantage that your foo_set functions can do validity checks to make sure you have appropriate values in your structure.



      Please note: I did not add any checks to my access functions to avoid cluttering the code, but when passing a pointer to a function, you should always check it for NULL






      share|improve this answer

























        2












        2








        2







        For the first part of the question, the mathematical operations like sinf should be handled by the C standard library (you should check you specific version for support on your architecture). You can then use the math.h header and its functions, the compiler should then use the FPU to make the floating point computations.




        For the second part, the usual way to show the user a hidden structure is with a foward declaration but the user will have to interact with the structure through pointers and access functions.



        With you example, say we have four files:




        • api.h: public header


        • api.c: source code for functions from the public header


        • foo.h: library internal header (will not be shipped to the end-user)


        • foo.c: source code for the internal functions

        The api.h is the only interesting file of those (have no changes).



        // file: api.h
        #ifndef API_H
        #define API_H

        struct foo; // forward declaration of the foo structure

        typedef void (*callback_t)(struct foo*); // typedef for a callback taking a
        // struct foo argument

        void set_callback(callback_t fn);
        #endif


        Now we have a type for the callback and the type of the structure given to the callback, but the user cannot interact with the structure itself, since the compiler only knows it exists but does not know its content (nor storage size).



        When the user writes a callback like in the below code, the user will need to have some access functions.



        #include "api.h"

        void user_callback(struct foo* arg)
        // user code here



        The access functions are usually defined like this:



        // in the file api.h or another header that the user has access to

        int foo_get_value1(struct foo* arg);
        void foo_set_value1(struct foo* arg, int new_value);


        and those functions would be implemented in foo.c



        struct foo 
        int value1;
        int value2;
        ;

        int foo_get_value1(struct foo* arg)
        return arg->value1;


        void foo_set_value1(struct foo* arg, int new_value)
        arg->value1 = new_value;



        This approach has the added advantage that your foo_set functions can do validity checks to make sure you have appropriate values in your structure.



        Please note: I did not add any checks to my access functions to avoid cluttering the code, but when passing a pointer to a function, you should always check it for NULL






        share|improve this answer













        For the first part of the question, the mathematical operations like sinf should be handled by the C standard library (you should check you specific version for support on your architecture). You can then use the math.h header and its functions, the compiler should then use the FPU to make the floating point computations.




        For the second part, the usual way to show the user a hidden structure is with a foward declaration but the user will have to interact with the structure through pointers and access functions.



        With you example, say we have four files:




        • api.h: public header


        • api.c: source code for functions from the public header


        • foo.h: library internal header (will not be shipped to the end-user)


        • foo.c: source code for the internal functions

        The api.h is the only interesting file of those (have no changes).



        // file: api.h
        #ifndef API_H
        #define API_H

        struct foo; // forward declaration of the foo structure

        typedef void (*callback_t)(struct foo*); // typedef for a callback taking a
        // struct foo argument

        void set_callback(callback_t fn);
        #endif


        Now we have a type for the callback and the type of the structure given to the callback, but the user cannot interact with the structure itself, since the compiler only knows it exists but does not know its content (nor storage size).



        When the user writes a callback like in the below code, the user will need to have some access functions.



        #include "api.h"

        void user_callback(struct foo* arg)
        // user code here



        The access functions are usually defined like this:



        // in the file api.h or another header that the user has access to

        int foo_get_value1(struct foo* arg);
        void foo_set_value1(struct foo* arg, int new_value);


        and those functions would be implemented in foo.c



        struct foo 
        int value1;
        int value2;
        ;

        int foo_get_value1(struct foo* arg)
        return arg->value1;


        void foo_set_value1(struct foo* arg, int new_value)
        arg->value1 = new_value;



        This approach has the added advantage that your foo_set functions can do validity checks to make sure you have appropriate values in your structure.



        Please note: I did not add any checks to my access functions to avoid cluttering the code, but when passing a pointer to a function, you should always check it for NULL







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 24 at 9:51









        Simon DopplerSimon Doppler

        734217




        734217





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55322161%2fstatic-library-structs-and-includes%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현