diff options
| author | David Faulkner <[email protected]> | 2026-08-07 23:40:47 -0500 |
|---|---|---|
| committer | David Faulkner <[email protected]> | 2026-08-07 23:40:47 -0500 |
| commit | b3e9e62599532050fc776c5e8f076915b56c2235 (patch) | |
| tree | af252346106a61b18cc6fc6fdbd32e962d096f1c /macro_trace.c | |
Import official C23 code examples for Modern C (Jens Gustedt, 2024)HEADupstream-importmain
- Add official C source files, Makefile, c23-fallback.h, and LICENSE
- Update README.md with study mirror notice
Diffstat (limited to 'macro_trace.c')
| -rw-r--r-- | macro_trace.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/macro_trace.c b/macro_trace.c new file mode 100644 index 0000000..1ecda7a --- /dev/null +++ b/macro_trace.c @@ -0,0 +1,40 @@ +#include "macro_trace.h" +#include <tgmath.h> +#include <stdlib.h> + +char const* trace_skip(char const expr[static 1]); + +void trace_values(FILE* s, + char const func[static 1], + char const line[static 1], + char const expr[static 1], + char const head[static 1], + size_t len, long double const arr[len]); + + +int main(int argc, char* argv[]) { + double sum = argc > 1 ? strtod(argv[1], 0) : 0x1P-1; + TRACE_PRINT0("my favorite variable: %g\n", sum); + TRACE_PRINT1("my favorite variable: %g", sum); + TRACE_PRINT2("my favorite variable: %g", sum); + TRACE_VALUE0("my favorite value:", sum); + TRACE_PTR0("my favorite pointer:", argv); + TRACE_PTR1("my favorite pointer:", argv); + TRACE_PRINT3("my favorite variable: %g", sum); + TRACE_PRINT4("my favorite variable: %g", sum); + TRACE_PRINT5("my favorite variable: %g", sum); + TRACE_PRINT5("a good expression: %g", sum*argc); + TRACE_PRINT6("a collection: %g, %i", sum, argc); + TRACE_PRINT7("a string"); + TRACE_PRINT8("a collection: %g, %i", sum, argc); + TRACE_PRINT8("another string"); + TRACE_PRINT9("a collection: %g, %i", sum*acos(0), argc); + TRACE_VALUES("an untyped collection:", sum, argc, acos(0)*2); + TRACE_VALUES("an untyped \"collection\":", sum, argc, acos(0)*2); + TRACE_VALUES("just one element:", acos(0)*2); + TRACE_VALUES("empty"); + TRACE_VALUES("\"empty\""); + TRACE_VALUE1("my favorite value:", sum); + TRACE_VALUE1("another value:", 0x1111111111111); + TRACE_VALUE1("my favorite pointer:", argv); +} |
