Preprocessor directives

Go To Last Post
10 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

1) Where can I find a list of all AVR GCC compiler preprocessor directives?

2) What preprocessor directive can verify that one file is already included?

3) What preprocessor directive can verify that one const label is already declared?

4) How can I force the preprocessor to stop immediatelly? (for example I want after #error directive force the preprocessor stop)

Learn as long as you live

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

kzdev wrote:
1) Where can I find a list of all AVR GCC compiler preprocessor directives?
http://gcc.gnu.org/onlinedocs/gcc-2.95.3/cpp_3.html
kzdev wrote:
2) What preprocessor directive can verify that one file is already included?
http://gcc.gnu.org/onlinedocs/gcc-2.95.3/cpp_1.html#SEC8
kzdev wrote:
3) What preprocessor directive can verify that one const label is already declared?
Const label? Do you mean macro?
kzdev wrote:
4) How can I force the preprocessor to stop immediatelly?
Pull the plug.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Const label, for example:

const unsigned char delay[16] = {2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3};

How its possible with preprocessor directive to check that is already declared?

Learn as long as you live

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You can't, directly. As the "pre-" in "preprocessor" suggests, it operates before the compiler; it only manipulates text, and doesn't know anything about the C code.

Why do you want to?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have one routine in my library that when I include it in my program, is necessary to be declared in the main program the 'delay' constant as the above.

So I just want the preprocessor to warning me If I forget to set it in the main program.

Learn as long as you live

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You can't do that in the preprocessor, or in the compilation of any single source file -- the compiler has no way of knowing that you haven't defined it in some other source file.

Assuming your library declares it 'extern' and doesn't initialize it, the linker will give you an error if it isn't defined in the main program.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Pull the plug.

:)

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

kpschoedel wrote:
kzdev wrote:
4) How can I force the preprocessor to stop immediatelly?
Pull the plug.
:roll: How about:
#error "STOP THIS IMMEDIATELY!"

kpschoedel wrote:
I have one routine in my library that when I include it in my program, is necessary to be declared in the main program the 'delay' constant as the above.

So I just want the preprocessor to warning me If I forget to set it in the main program.

Sheesh, people are so literal! Okay, how about:
---delay.h:---

#ifndef __DELAY__
#define __DELAY__

const unsigned char delay[16] = {2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3};

#endif /* __DELAY__ */

---main.c---

#ifndef __DELAY__
#error "Delay constant is not set!!"
#endif

Now, having said all this, I think you are going about this the wrong way. The better way is to define the variable in main.c and then declare it extern in the other routines that may need it. That way everyone wins.

Check out [TUT] [C] Modularizing C Code: Managing large projects

Stu

Edit 1: PS: Also the constant you are defining will take SRAM space at all times. Check out the following for a way to store this array so that it saves SRAM:

[TUT] [C] GCC and the PROGMEM Attribute

Engineering seems to boil down to: Cheap. Fast. Good. Choose two. Sometimes choose only one.

Newbie? Be sure to read the thread Newbie? Start here!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Actually there is a compiler switch that tells the compiler to stop after the preprocessing stage. Look in the GCC manual.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Eric wrote:
Actually there is a compiler switch that tells the compiler to stop after the preprocessing stage. Look in the GCC manual.
True, but the OP specifically asked:
kzdev wrote:
How can I force the preprocessor to stop immediatelly? (for example I want after #error directive force the preprocessor stop)
I believe the #error directive does tell the pre-processor to stop immediately.

This is, of course, just my opinion. I could be wrong. :D

Stu

Engineering seems to boil down to: Cheap. Fast. Good. Choose two. Sometimes choose only one.

Newbie? Be sure to read the thread Newbie? Start here!