|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Understanding the Source code
I'm a pretty proficient programmer (most of my experience is with C#), but I'm still finding myself stumped by some of the source code. I'm hoping that if I understand the source I can implement new classes as necessary and use proper conventions (especially where error handling is concerned).
First question: Macros. FRC apparently (and inexplicably) has made extensive use of macros. I'm not extremely familiar with them, but they seem to serve many purposes. The first one I came across: "START_ROBOT_CLASS(IterativeDemo);" at the bottom of the demo class. This references RobotBase.h, which has: Code:
#define START_ROBOT_CLASS(_ClassName_) \
RobotBase *FRC_userClassFactory(void) \
{ \
return new _ClassName_(); \
} \
extern "C" { \
int FRC_UserProgram_StartupLibraryInit(void) \
{ \
RobotBase::startRobotTask((FUNCPTR)FRC_userClassFactory); \
return 0; \
} \
}
Second question: Macros. Heh, sorry, I mean Macros that do error handling. The next major macro confusion is with the "wpi_assert"s and "wpi_fatal"s that are sprinkled across the code. One example in RobotDrive.cpp: Code:
void RobotDrive::SetInvertedMotor(MotorType motor, bool isInverted)
{
if (motor < 0 || motor > 3)
{
wpi_fatal(InvalidMotorIndex);
return;
}
m_invertedMotors[motor] = isInverted ? -1 : 1;
}
Code:
#ifdef WPI_STATUS_DEFINE_STRINGS #define S(label, offset, message) const int wpi_v_##label = offset; const char *wpi_s_##label = message ; #else #define S(label, offset, message) const int wpi_v_##label = offset; extern const char *wpi_s_##label; #endif Sorry if this was a lot of questions... Basically, I want to know: -What happened to main() and what is the START_ROBOT_CLASS macro doing -How the wpi_assert and _demands handle errors |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| need help understanding c code in robotdrive | mahmosh | C/C++ | 14 | 16-01-2009 08:56 |
| i downloaded the source code, now what do i do? | programmr | Programming | 2 | 12-12-2008 14:39 |
| Source code for the Easy C Pro library functions? | bobpskier | Programming | 3 | 05-02-2007 21:39 |
| [FVG]: Source Code | SilverStar | FIRST-related Organizations | 5 | 24-08-2004 14:28 |
| Patent source code? | Kyle Fenton | Chit-Chat | 3 | 20-10-2001 17:53 |