hi,
zig run main.c –library c works but how do i pass -std=c23 to it ?
zig run main.c –cflags -std=c23 doesnt work as adviced by the ai
hi,
zig run main.c –library c works but how do i pass -std=c23 to it ?
zig run main.c –cflags -std=c23 doesnt work as adviced by the ai
-cflags sets the flags for the next c file. Just put them before main.c
AI often makes mistakes especially with zig; try more reliable resources like zig run --help for this case, there are official and community resources maintained by people who keep up with changes so they are much more reliable
Shouldn’t that be zig run -cflags -std=c23 -- main.c ? I.e. with -- terminating the “cflags”.
No, zig run -- ... passes the following args to the code you just compiled.
I am aware of the interperetation of -- ending normal interpretation of commandline options, that was already part of the getopt code I used in the 80s. What I find kind of confusing is that the help output for zig run and zig translate is exactly the same for -cflags:
-cflags [flags] -- Set extra flags for the next positional C source files
and that the language reference states (for zig translate-c):
-cflags [flags] --: Pass arbitrary additional command line flags to clang. Note: the list of flags must end with --with the full example zig translate-c -cflags -fshort-enums -- varycflags.h.
Based on that (without checking whether the compiler does something different for -cflags for those subcommands), I did expect zig run -cflags -std=c23 -- main.c
And the lines following https://codeberg.org/ziglang/zig/src/commit/7eb79daffb16426d1ed78316d5fdf9ff0d015a83/test/src/Cases.zig#L612, seem to indicate the same -- behaviour for zig run as described for zig translate-c in the language reference (i.e. the artifact after --). But I have to admit I never used it, just tried to interpret what to do for the commandline completion.
You are right! (didn’t verify but trust the lang ref)
I ran into that when analysing the output of zig cc --help for command-line completion of zig and thought it was not a good idea to overload -- in this way. The command-line parser, that the command-line completion piggy-backs upon, terminates on --. I would have chosen something like -end-cflags instead of --.
However the bigger problem for completion is that based on the -cflags you do have to change to whole different set of options (and then back on --, neither of which zigclc currently does, it is on the ToDo list though)