Using define
(Created page with "{{DISPLAYTITLE: Using #define}} <yambe:breadcrumb self="Using #define>Programming_Tips_Tricks|Programming Tips Tricks</yambe:breadcrumb> <br /> Some of the uses for the #defi...") |
|||
| Line 1: | Line 1: | ||
| − | {{DISPLAYTITLE: Using #define}} | + | {{DISPLAYTITLE: Using #define}} |
| − | <yambe:breadcrumb self="Using #define>Programming_Tips_Tricks|Programming Tips Tricks</yambe:breadcrumb> | + | <yambe:breadcrumb self="Using #define>Programming_Tips_Tricks|Programming Tips Tricks</yambe:breadcrumb> |
<br /> | <br /> | ||
Revision as of 13:56, 15 May 2012
General Programming → Programming Tips Tricks → Using define
Some of the uses for the #define statement, not all necessarily good programming but it shows that it has other uses beyond just defining constants. More explanation here http://en.wikipedia.org/wiki/C_preprocessor
#pragma config(UART_Usage, UART1, VEX_2x16_LCD, baudRate19200, IOPins, None, None) #pragma config(Motor, port1, , tmotorNormal, openLoop) #pragma config(Motor, port2, , tmotorNormal, openLoop) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*// #define DEBUG #define ABS(x) ( (x)>=0?(x):-(x) ) #define DRIVE_MOTOR(x) do{\ motor[port1] = (x);\ motor[port2] = (x);\ }while(0) #define JOY_DRIVE vexJSLeftV #define DISPLAY_MOTORS do{\ displayLCDNumber(1, 0, motor[port1], 3);\ displayLCDNumber(1, 8, motor[port2], 3);\ }while(0) task main() { while(true) { DRIVE_MOTOR( vexRT[ JOY_DRIVE ] ); wait1Msec(20); #ifdef DEBUG DISPLAY_MOTORS; #endif } } |
This tip was posted by jpearman over at http://www.vexforum.com/showpost.php?p=224863&postcount=12.