answersLogoWhite

0

For gcc there's a non-standard solution. Declare the function with __attribute__((constructor)) (note the double parentheses).

Like this:

void init(void) __attribute__ ((constructor));

void init(void) {

// your code goes here

}

Starting with gcc 4.3 there's even a possibility to assign a priority to the "constructor". See http://gcc.gnu.org/onlinedocs/gcc-4.3.0/gcc/Function-Attributes.html for details.

User Avatar

Wiki User

17y ago

What else can I help you with?

Related Questions

What is a main function in c plus plus?

It is the first function that gets called when the program is executed.


What is the only function all C plus plus programs must contain?

Every C plus plus program that is a main program must have the function 'main'.


Is C plus plus interpreted as the program is executed?

No. Neither C nor C++ are interpreted. Both need to be compiled and linked to produce highly-optimised machine code, which is then executed.


What is a primary function in C plus plus?

There is no such thing. You probably meant the main function. The main function is the only function that is required as it serves as the entry point of the program.


Where is the global declaration section of a c plus plus program?

Anything declared outside of a function is global.


What is the importance of functions in a c plus plus program?

Functions are very important in C++, as you can't write the simplest program to print hello without using a function. Overall you can say that function are building blocks of a C++ program. Functions can also be defined by the programmer to reduce program size.


How do you write a programm in c plus plus without using function main?

I don't think its possible. Every C++ program must at least have the main function.


What is meant by abstraction in c plus plus?

Abstraction is a process by which higher concepts are derived from the usage and classification of literal ("real" or "concrete") concepts, first principles and/or other abstractions.


How do you write a C plus plus program that will display the first 10 positive prime numbers?

By learning how to program on C+.


Why wont your c plus plus program stay open?

If you are talking about the program executing, but the output screen being displayed for a flash and then disappearing, I suggest adding getch() or getchar() function at the end of your main function. This will make sure that the output screen waits for you to press a character before the program terminates.


Can a function be called from more than one place in a program in c plus plus?

In C and C++, as well as in many (all?) languages, a function can be called from more than one place in a program. That's the purpose of functions - to encapsulate pieces of code that are needed in more than one place in the program.


What are the general format of C plus plus program?

The format of a basic C++ program is as follows: First, you have your include statements. Next, you have your function prototypes, and class declarations. Then, you have your main function. This can be organized into small parts using whitespace characters. Finally, you have the definition of all the functions you call in the main function. Really, it's up to the individual programmer how most of the code is organized, but the above is a good structure if you're not absolutely sure what you're doing.