I recently purchased a Teensy 4.1 and am porting an application that heavily leverages constructor attributes. When running the following application under LInux, this snippet:
Compiles and produces the following (expected output)
That is, the funciton "init_foo" is called before main.
However, running a similar snippet of code under teensyduino (or using Makefiles):
Produces the incorrect output:
Any thoughts on what I need to do to get the constructors to be called?
Mark
Code:
#include <stdio.h>
int foo;
int main(int argc, char *argv[])
{
printf("foo is %d\n", foo);
}
void __attribute__((constructor (200))) init_foo(void)
{
foo = 5;
}
Compiles and produces the following (expected output)
Code:
[markster@portamarko ~]$ gcc -o footest footest.c
[markster@portamarko ~]$ ./footest
foo is 5
[markster@portamarko ~]$
That is, the funciton "init_foo" is called before main.
However, running a similar snippet of code under teensyduino (or using Makefiles):
Code:
int foo;
void setup() {
while (!Serial);
Serial.print("foo has the value ");
Serial.println(foo);
}
// the loop routine runs over and over again forever:
void loop() {
}
void __attribute__((constructor (200))) init_foo(void)
{
foo = 5;
}
Produces the incorrect output:
Code:
foo has the value 0
Any thoughts on what I need to do to get the constructors to be called?
Mark