Debugging by old fashioned trace log printfs / writefln

H. S. Teoh hsteoh at qfbox.info
Fri Jun 30 16:04:42 UTC 2023


On Fri, Jun 30, 2023 at 03:43:14PM +0000, Cecil Ward via Digitalmars-d-learn wrote:
[...]
> Since I can pass my main function some compile-time-defined input, the
> whole program should be capable of being executed with CTFE, no? So in
> that case pragma( msg ) should suffice for a test situation? Would
> pragma(message) have the advantage over writefln that I don’t have to
> pervert the function attributes like nogc nothrow pure ?

Just use the `debug` statement:

	auto pureFunc(Args args) pure {
		...
		debug writefln("debug info: %s", ...);
		...
	}

Compile with `-debug` to enable the writefln during development. When
not compiling with `-debug`, the writefln will not be compiled and the
function will actually be pure.

The problem with pragma(msg) is that it happens very early in the
compilation process; some things may not be available to it, such as the
value of variables in CTFE. This may limit its usefulness in some
situations.  For more details on this, see:

	https://wiki.dlang.org/Compile-time_vs._compile-time


T

-- 
He who sacrifices functionality for ease of use, loses both and deserves neither. -- Slashdotter


More information about the Digitalmars-d-learn mailing list