#define functions

What would be the purpose of writing a method this way:
1
2
3
4
5
6
7
#define UNHANDLED_EXCEPTION() \
    do { \
        bell(3); \
        error("Record Error."); \
        sleep(4); \
        LOG(FATAL) << "An unhandled exception occurred"; \
    } while (false) 

vs.
1
2
3
4
5
6
7
void UNHANDLED_EXCEPTION()
{
    bell(3);
    error("Record Error. ");
    sleep(4);
    LOG(FATAL) << "An unhandled exception occured";  
}


did people used to use the first version a lot? Is this out dated now or still perfectly legit?
C didn't have inline functions, so inlined code was injected using macros.

The equivalent in C++ would be to use an inline function instead. If there's an error in it, you'll get proper error messages back, plus you get proper type checking. However, the function may not be inlined, the inline keyword is more a compiler hint than a command.
Topic archived. No new replies allowed.