Skip to content

How to print enum's value #403

Description

@LukyGuyLucky

Always the most recent build---

enum Status{
	Idle,
	Running,
	Finishing,
	Error(int)
}

test "enum_codegen_auto_call"{
	let s=Status::Idle;
	"s={s}";
	printf("%d\n",s);//ok
}

error

E:\Learning\zenpack\ex>zc run enum_print01.zc
   Compiling enum_print01.zc...
warning: Format argument 2: expected 'integer', got 'Status'
  --> enum_print01.zc:12:8
   |
12 |    printf("%d\n",s);//ok
   |        ^ here
   |
   = note: Mismatched format specifier may cause undefined behavior
enum_print01.zc: In function '_z_test_0':
enum_print01.c:84:28: error: '_Generic' selector of type 'struct Status' is not compatible with any association
   84 | #define _z_str(x) _Generic((x), _Bool: "%s", char: "%c", signed char: "%c", unsigned char: "%u", short: "%d",
unsigned short: "%u", int: "%d", unsigned int: "%u", long: "%ld", unsigned long: "%lu", long long: "%lld", unsigned lo
ng long: "%llu", float: "%f", double: "%f", char*: "%s", const char*: "%s", void*: "%p" _z_128_map _z_objc_map)
      |                            ^
enum_print01.zc:11:60: note: in expansion of macro '_z_str'
   11 |         "s={s}";
      |                                                            ^
error: C compilation failed

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions