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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:38:45+00:00 2026-05-18T20:38:45+00:00

I have an interface with which I want to be able to statically link

  • 0

I have an interface with which I want to be able to statically link modules. For example, I want to be able to call all functions (albeit in seperate files) called FOO or that match a certain prototype, ultimately make a call into a function in the file without a header in the other files. Dont say that it is impossible since I found a hack that can do it, but I want a non hacked method. (The hack is to use nm to get functions and their prototypes then I can dynamically call the function). Also, I know you can do this with dynamic linking, however, I want to statically link the files. Any ideas?

  • 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-18T20:38:45+00:00Added an answer on May 18, 2026 at 8:38 pm

    This is somewhat common in writing test code. e.g., you want to call all functions that start with test_. So you have a shell script that grep’s through all your .C files and pulls out the function names that match test_.*. Then that script generates a test.c file that contains a function that calls all the test functions.

    e.g., generated program would look like:

    int main() {
       initTestCode();
       testA();
       testB();
       testC();
    }
    

    Another way to do it would be to use some linker tricks. This is what the Linux kernel does for its initialization. Functions that are init code are marked with the qualifier __init. This is defined in linux/init.h as follows:

    #define __init          __section(.init.text) __cold notrace
    

    This causes the linker to put that function in the section .init.text. The kernel will reclaim memory from that section after the system boots.

    For calling the functions, each module will declare an initcall function with some other macros core_initcall(func), arch_initcall(func), et cetera (also defined in linux/init.h). These macros put a pointer to the function into a linker section called .initcall.

    At boot-time, the kernel will “walk” through the .initcall section calling all of the pointers there. The code that walks through looks like this:

    extern initcall_t __initcall_start[], __initcall_end[], __early_initcall_end[];
    
    static void __init do_initcalls(void)
    {
            initcall_t *fn;
    
            for (fn = __early_initcall_end; fn < __initcall_end; fn++)
                    do_one_initcall(*fn);
    
            /* Make sure there is no pending stuff from the initcall sequence */
            flush_scheduled_work();
    }
    

    The symbols __initcall_start, __initcall_end, etc. get defined in the linker script.

    In general, the Linux kernel does some of the cleverest tricks with the GCC pre-processor, compiler and linker that are possible. It’s always been a great reference for C tricks.

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

Sidebar

Related Questions

I have an interface with which I want to be able to statically link
I want to have a class which implements an interface, which specifies the specific
I have an interface: List<List<Integer>> separate(List<Integer> list); I want to be able to separate
I have an application in which users interact with each-other. I want to visualize
We have an interface which will be implemented by classes that take care of
I have the following interface which I'm trying to make COM-visible. When I try
In COM, if I have an interface IBase and an interface IX which inherits
I have an interface called Dictionary which has a method insert() . This interface
I have a generic interface IConstrained which is implemented by the generic Constrained class.
We have an interface IPoller for which we have various implementations. We have a

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.