![]() |
Conditional #define Statements
I'm rewriting the navigate.c class for our team, and I've come to an annoying problem.
I have two sensors, left and right, for each side of the robot. Depending on a switch, only one should be read. That means I can save on code, I think. With PBASIC, a simple if statement and alias command would set "sensor" to "left_sensor" or "right_sensor" but I have no idea how to do this in C, without going into pointers (which I don't remember). Is there any way I can make a conditional #define (or similar) statement? |
Re: Conditional #define Statements
Why not just have a conditional declaration?
if(your condition is meet) { int your_var; } else { int something else; } I'm probably misunderstanding you but its still worth a shot. |
Re: Conditional #define Statements
Quote:
1) You know at compile time which one you want Code:
#if IWANTVAR1Code:
int myVar;I hope this is what you wanted... |
Re: Conditional #define Statements
Ah, thanks, I didn't think about doing something simple like just reassigning the variable to a temporary variable. Seeing as I only need to read, I think I can make do with that, but I'll have to fool around with it a bit.
On the other hand, it's always a good time to relearn pointers... |
| All times are GMT -5. The time now is 18:17. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi