Skip to content

Commit 12f6ed7

Browse files
committed
tweaks
1 parent b454760 commit 12f6ed7

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

compile-and-run.zsh

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,23 @@
33
set -euo pipefail
44

55
DAY="$1"
6-
INPUT="$2"
6+
7+
if [[ -z ${2-} ]]; then
8+
INPUT="${1:0:-1}.input"
9+
else
10+
INPUT=$2
11+
fi
12+
13+
FLAGS="-Ofast \
14+
-Wunused-but-set-variable \
15+
-Wunused-parameter \
16+
-Wunused-macros"
17+
18+
if [[ -v D ]]; then
19+
FLAGS="-O0 \
20+
-Wno-unused-function \
21+
-Wno-unused-variable"
22+
fi
723

824
mkdir -p build
925

@@ -19,10 +35,7 @@ clang \
1935
-Wsign-compare \
2036
-Wswitch-enum \
2137
-Wno-gnu-binary-literal \
22-
-Wunused-variable \
23-
-Wunused-function \
24-
-Wunused-but-set-variable \
25-
-Wunused-parameter \
38+
${=FLAGS} \
2639
-std=c17 \
2740
--debug \
2841
-o "./build/$DAY" \

template.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
int main(void) {
66
char *line = NULL;
77
size_t ngetline = 0;
8+
89
int nchars = 0;
910

1011
while ((nchars = (int)getline(&line, &ngetline, stdin)) > 0) {
11-
if (line[nchars - 1] == '\n') line[--nchars] = '\0';
12+
if (line[nchars - 1] == '\n') line[--nchars] = 0;
1213

1314
printf("line: %s\n", line);
1415
}

0 commit comments

Comments
 (0)