This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: gcc/ld init section and libraries


"John Donoghue" <john.donoghue@ieee.org> writes:

> Im not sure if this question belong in this list but ...
>
> I have a cross compiling suite for m68k-elf I am using for a small
> 68332 board and want to add some code that will be run (initialize
> some stuff for me) when the program runs.

You could try to use the "constructor" attribute:

#include <stdio.h>

void __attribute__((constructor)) f() {
    puts("foo");
}

int main() {
    puts("bar");
    return 0;
}


-- 
	Falk


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]