standalone: Add output_bool in demo library #331

Merged
sb10q merged 1 commits from enhance/add-output-bool-to-demo-lib into master 2024-08-17 17:37:20 +08:00
1 changed files with 10 additions and 9 deletions

View File

@ -12,30 +12,31 @@
#error "Unsupported platform - Platform is not 32-bit or 64-bit" #error "Unsupported platform - Platform is not 32-bit or 64-bit"
#endif #endif
void output_bool(const bool x) { void output_bool(bool x) {
Outdated
Review

const?

const?

It's just to enforce an immutable-by-default design, similar to how objects in Rust are immutable unless mut is specified.

It's just to enforce an immutable-by-default design, similar to how objects in Rust are immutable unless `mut` is specified.
Outdated
Review

Sounds like very idiosyncratic and probably ineffective C programming style.

Sounds like very idiosyncratic and probably ineffective C programming style.

Should I remove it then? It's just stylistic and doesn't change the ABI.

Should I remove it then? It's just stylistic and doesn't change the ABI.
Outdated
Review

Yes, everywhere.

Yes, everywhere.
puts(x ? "True" : "False"); puts(x ? "True" : "False");
} }
void output_int32(const int32_t x) { void output_int32(int32_t x) {
printf("%d\n", x); printf("%d\n", x);
} }
void output_int64(const int64_t x) { void output_int64(int64_t x) {
printf("%ld\n", x); printf("%ld\n", x);
} }
void output_uint32(const uint32_t x) { void output_uint32(uint32_t x) {
printf("%d\n", x); printf("%d\n", x);
} }
void output_uint64(const uint64_t x) { void output_uint64(uint64_t x) {
printf("%ld\n", x); printf("%ld\n", x);
} }
void output_float64(const double x) { void output_float64(double x) {
printf("%f\n", x); printf("%f\n", x);
} }
void output_asciiart(const int32_t x) {
void output_asciiart(int32_t x) {
static const char *chars = " .,-:;i+hHM$*#@ "; static const char *chars = " .,-:;i+hHM$*#@ ";
if (x < 0) { if (x < 0) {
putchar('\n'); putchar('\n');
@ -45,12 +46,12 @@ void output_asciiart(const int32_t x) {
} }
struct cslice { struct cslice {
const void *data; void *data;
usize len; usize len;
}; };
void output_int32_list(struct cslice *slice) { void output_int32_list(struct cslice *slice) {
const int32_t *data = (const int32_t *) slice->data; const int32_t *data = (int32_t *) slice->data;
putchar('['); putchar('[');
for (usize i = 0; i < slice->len; ++i) { for (usize i = 0; i < slice->len; ++i) {