| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • Stop wasting time looking for files and revisions. Connect your Gmail, DriveDropbox, and Slack accounts and in less than 2 minutes, Dokkio will automatically organize all your file attachments. Learn more and claim your free account.

View
 

error

Page history last edited by Kenneth Finnegan 12 years, 5 months ago

This preprocessor directive can be used to make a file not compile with your own error message saying what's wrong, or just cause a warning to be displayed.

 

Code:

#error "Custom error message saying what is wrong"

 

#warning "Custom warning message"

 

Usage:

int foo(int i) {

     #error "Function foo not yet implemented"

}

 

int bar(int j) {

     #warning "Function bar may not behave as expected all the time"

}

 


Extensions:

This could be used with #if to check properties of the environment

#if sizeof(int) < 4

     #error sizeof Int is too small, must be at least 4 bytes

#endif


Sources:

https://www.securecoding.cert.org/confluence/display/seccode/DCL03-A.+Use+a+static+assertion+to+test+the+value+of+a+constant+expression

http://en.wikipedia.org/wiki/C_preprocessor#User-defined_compilation_errors_and_warnings

Comments (0)

You don't have permission to comment on this page.