Sign in to follow this  

Conditional Compilation

This topic is 3334 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everybody. For starters, I need some help with preprocessors statements and conditional compilation in C. I don't use C very much, and its been awhile since I did use it (in class). We didn't really learn about preprocessor statements. However, to give some background, I'm an intermediate programmer - I program in C++ and java all the time and tend to stay away from preprocessors except for include gaurds in header files. Anyhow.... I am working on a simple system in which there can be no overhead in terms of how the data needs to be processed. I. E. The program needs to make a decision before the program executes because we can't really spare the time and code to make that decision when the program runs. This is robot code for a ping sensor (in robotics club). (I am working with a PIC with limited space, and my code needs to have as little overhead as possible to give space and speed to other systems. The president of the club wants me to use preprocessors as that would make it so the decision of program execution was made before the program actually ran. So... in the main code we will have something like this #define PING_PORT A - which means we want the sensor to be on port A of the PIC. My code needs to detect the port using conditional compilation and set other variables (#defines) so.. #if PING_PORT == A #undef PING_PORT #define PING_PORT PORTA #elif .... #elif..... #elif.... #elif.... #endif The trouble I am having is if I implement one #if and one #elif, the code works. After those two, the code doesn't work. Its almost as if the other code is left out and undefined behavior is happening. Now I brought this into visual studio and it happened just like that. After two conditionals it grayed out the rest and didnt execute properly. So, what's going on? Any help will be appreciated. This is probably a simple issue that somebody has a solution to. However, I don't work with C very much. PS. if this is in the wrong forum, please move it. Thanks - Lo$t

Share this post


Link to post
Share on other sites
You can define prepocessor definitions also in project settings->c/c++->preprocessor definitions, so when you link the program you will have definitions before linking.

You can create several projects sets with different definitions.

Share this post


Link to post
Share on other sites

This topic is 3334 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this