Menu

Custom Compile Error Messages

Ultim
2007-07-14
2012-09-26
  • Ultim

    Ultim - 2007-07-14

    Here's a good question: Is there any way you can define your own errors? So that:


    int a;
    int b; //Not allowed to use this variable

    b = 5;

    Will cause an error at compile, highlighting b=5; in red (you can use #line for THAT) and saying something like "Sorry, you can't use b"

     
    • Nobody/Anonymous

      I wonder - do you want to remove variable b from your code and find all instances where it is used? You can remove the declaration of b and then the compiler errors will tell you where it is used.

       
    • Anonymous

      Anonymous - 2007-07-14

      Why would you want to do that? And no you can't. Mostly because compiler writers don't put gratuitously silly features into compilers - they are too busy making it work sensibly!

      There is the #error preprocessor directive however, but it does not help do what you just asked.

      You will have to write your own pre-processor error checker. If you wnat to actually check for sensible errors or bad coding practices, there are tools that do just that such as lint and PRQA.

      Clifford

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.