Skip to content

Commit 66f958d

Browse files
authored
v.builder: switch to using -std=c99, instead of -std=gnu99 to avoid name colisions with C linux macros defined by gcc/clang (#25848)
1 parent de48e90 commit 66f958d

File tree

4 files changed

+7
-23
lines changed

4 files changed

+7
-23
lines changed

GNUmakefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ ifdef LEGACY
111111
rm -rf $(TMPLEGACY)
112112
$(eval override LDFLAGS+=-L$(realpath $(LEGACYLIBS))/lib -lMacportsLegacySupport)
113113
endif
114-
$(CC) $(CFLAGS) -std=gnu99 -w -o v1$(EXE_EXT) $(VC)/$(VCFILE) -lm -lpthread $(LDFLAGS) || cmd/tools/cc_compilation_failed_non_windows.sh
114+
$(CC) $(CFLAGS) -std=c99 -w -o v1$(EXE_EXT) $(VC)/$(VCFILE) -lm -lpthread $(LDFLAGS) || cmd/tools/cc_compilation_failed_non_windows.sh
115115
ifdef NETBSD
116116
paxctl +m v1$(EXE_EXT)
117117
endif
@@ -229,4 +229,3 @@ etags:
229229

230230
ctags:
231231
./v$(EXE_EXT) -print-v-files cmd/v | grep -v :parse_text| ctags -L -
232-

vlib/v/builder/cc.v

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ import v.vcache
1111
import term
1212

1313
const c_std = 'c99'
14-
const c_std_gnu = 'gnu99'
1514
const cpp_std = 'c++17'
16-
const cpp_std_gnu = 'gnu++17'
1715

1816
const c_verror_message_marker = 'VERROR_MESSAGE '
1917

@@ -465,12 +463,7 @@ fn (mut v Builder) setup_ccompiler_options(ccompiler string) {
465463
}
466464
}
467465
if !v.pref.no_std {
468-
if v.pref.os == .linux {
469-
ccoptions.source_args << '-std=${c_std_gnu}'
470-
} else {
471-
ccoptions.source_args << '-std=${c_std}'
472-
}
473-
ccoptions.source_args << '-D_DEFAULT_SOURCE'
466+
ccoptions.source_args << ['-std=${c_std}', '-D_DEFAULT_SOURCE']
474467
}
475468
$if trace_ccoptions ? {
476469
println('>>> setup_ccompiler_options ccompiler: ${ccompiler}')
@@ -545,18 +538,10 @@ fn (mut v Builder) thirdparty_object_args(ccoptions CcompilerOptions, middle []s
545538
mut all := []string{}
546539

547540
if !v.pref.no_std {
548-
if v.pref.os == .linux {
549-
if cpp_file {
550-
all << '-std=${cpp_std_gnu}'
551-
} else {
552-
all << '-std=${c_std_gnu}'
553-
}
541+
if cpp_file {
542+
all << '-std=${cpp_std}'
554543
} else {
555-
if cpp_file {
556-
all << '-std=${cpp_std}'
557-
} else {
558-
all << '-std=${c_std}'
559-
}
544+
all << '-std=${c_std}'
560545
}
561546
all << '-D_DEFAULT_SOURCE'
562547
}

vlib/v/help/build/build-c.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ see also `v help build`.
341341
compiler, on the command line, without writing an .rsp file first.
342342

343343
-no-std
344-
By default, V passes -std=gnu99(linux)/-std=c99 to the C backend, but some compilers do
344+
By default, V passes -std=c99 to the C backend, but some compilers do
345345
not support that, even though they may be able to compile the produced
346346
code, or have other options that can be tuned to allow it.
347347
Passing -no-std will remove that flag, and you can then use -cflags ''

vlib/v/pref/pref.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ pub mut:
227227
fatal_errors bool // unconditionally exit after the first error with exit(1)
228228
reuse_tmpc bool // do not use random names for .tmp.c and .tmp.c.rsp files, and do not remove them
229229
no_rsp bool // when true, pass C backend options directly on the CLI (do not use `.rsp` files for them, some older C compilers do not support them)
230-
no_std bool // when true, do not pass -std=gnu99(linux)/-std=c99 to the C backend
230+
no_std bool // when true, do not pass -std=c99 to the C backend
231231

232232
no_parallel bool // do not use threads when compiling; slower, but more portable and sometimes less buggy
233233
parallel_cc bool // whether to split the resulting .c file into many .c files + a common .h file, that are then compiled in parallel, then linked together.

0 commit comments

Comments
 (0)