What is the practical use of this directive?

    3 answers 3

    Imagine the situation that you wrote cleverly optimized code for selecting hashes. And he believes that the byte is strictly 8 bits. Everyone is happy, everyone is happy and they want to run your code on "big machines" (like Cray), and there may be 36 bits in a byte on them. And it works there, but somehow it is not. Head off, debazhat ... but everything would be simpler if they immediately inserted a check into the code and output with the help of #error the message "and your platform is strange, contact the developer".

    • It is also an option. - gecube

    But such. Suppose you are using conditional compilation directives. And among them there are incompatible. Then, if they are selected, use the #error directive and the program will not build (but still it will not work correctly). There are plenty of other uses for this directive.

      Another example is when it is necessary that either one symbol or another be defined (for example, either debug or release), but not both at once or none.