7

Is there a way to instruct gcc to skip initialization for certain static,volatile variables? I have several circular buffers (declared volatile) that really don't need to be zeroed at startup and on my MCU, it's a waste of about ~2500 tcy.

Thanks in advance,

3
  • conditional compilation using #ifdef..... #endif ?? Commented Jul 20, 2013 at 9:33
  • hmm... I'm speaking about runtime here, not design time. Commented Jul 20, 2013 at 9:45
  • Also see stackoverflow.com/questions/11180892/… Commented Jul 20, 2013 at 10:51

1 Answer 1

7

If you use gcc, you can place the array object in the .noinit section:

uint8_t arr[1024] __attribute__ ((section (".noinit")));
Sign up to request clarification or add additional context in comments.

10 Comments

Doesn't this extension contradict the C standard?
@icepack - probably yes - that's why it's an extension.
Do you happen to know a similar one for MSVC?
@user93353 well, another possibility is that it's not a contradiction but an innovation that will be adopted sometime, like the changes in C++11 that follow boost in many ways
@SomeWittyUsername: No, this does not contradict the C standard. The C standard says that C implementations may have extensions, and that extensions that do not alter the behavior of strictly conforming programs (which do not use extensions) are conforming. GCC’s __attribute__ keyword is a reserved identifier (because it starts with __), so no strictly conforming programs use it (by definition, any program that uses it is not strictly conforming), so accepting it is a conforming extension.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.