StreamKid wrote:
> why is a segmentation fault caused in this simple thing???
> and what exactly is this kind of error???

A segmentation fault occurs when you access memory you are not allowed to
access. Typically this is caused by an invalid pointer. If you want to
know where, use a debugger (typically gdb).

> *#define DEBUG

FYI: this macro has no meaning to standard C++, the one used to turn off
assert() is NDEBUG.

> *#define assert( x ) \

Bad: you are not allowed to define any names used by the standardlibrary.

> *     if( ! ( x )) \
> *     { \
> *             printf( "\nERROR!! Assert %s failed", #x ); \
> *             printf( "\n on line %s", __LINE__ ); \
> *     }

Several things here:
- You could have used a single printf().
- The '\n' should come at the end of a line, not at the beginning.
- If you put this macro somewhere in the context of another if-else block,
it will mess up control flow. Similarly, it doesn't even require a
semicolon after it.
- If you compile this with warnings turned on, it will give you a warning
which is the cause of your segmentation fault.

Uli

-- 
http://gcc.gnu.org/faq.html
http://parashift.com/c++-faq-lite/

_______________________________________________
help-gplusplus mailing list
help-gplusplus@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gplusplus

Reply via email to