Skip to content

mccode linter

Peter Willendrup edited this page Jan 14, 2026 · 4 revisions

We recommend to use the cppcheck c-linter to help you spot potential problems with your component / instrument code. Examples of potential issues checked for are

  • un-initialised variables
  • indications of ‘undefined behaviour’
  • missing error-handling in case of failed malloc() or fopen() calls
  • potential memory leaks
    ... and more. All in all the tool provides a valuable shortcut to help you from “prototype physicist-code” to “validated user code” which is what we strive to ensure McStas/McXtrace is!

The McStas/McXtrace tools are preconfigured to run cppcheck, but it is not added as a dependency - so you will have to manually install it on your system. (We recommend using a conda-based enviroment where both McStas/McXtrace and cppcheck is installed.)

  • mcrun/mxrun provides the -C / --c-lint switch that will generate code for a given instrument and run the linter
  • mctest/mxtest provides the --lint switch that will run the linter in a mctest run

Please do not think that you know a given warning from cpplint is “not relevant”! Your code will not be merged to the McStas/McXtrace repo until all warnings and remarks are resolved!

Clone this wiki locally