CC=gcc
-CFLAGS=-Wall -Wextra -pedantic
+CFLAGS=-x c -Wall -Wextra -pedantic
OUTFILE=hello
SOURCE=hello.c
--- /dev/null
+CC=gcc
+CFLAGS=-x c -Wall -Wextra -pedantic
+
+all: control test1 test2 test3
+
+control: control.c
+ $(CC) $(CFLAGS) -o control.out control.c
+
+test1: test1.c
+ $(CC) $(CFLAGS) -o test1.out test1.c
+
+test2: test2.c
+ $(CC) $(CFLAGS) -o test2.out test2.c
+
+test3: test3.c
+ $(CC) $(CFLAGS) -o test3.out test3.c
+
+clean:
+ rm ./*.out
--- /dev/null
+#include <stdio.h>
+
+int main()
+{
+ printf("Hello, world.\n");
+}
--- /dev/null
+#include <stdio.h>
+
+int main()
+{
+ // printf("Hello, world.\n");
+}
--- /dev/null
+// #include <stdio.h>
+
+int main()
+{
+ printf("Hello, world.\n");
+}
--- /dev/null
+$ gcc -x c -Wall -Wextra -pedantic -o test2.out test2.c
+test2.c: In function ‘main’:
+test2.c:5:3: warning: implicit declaration of function ‘printf’ [-Wimplicit-function-declaration]
+ 5 | printf("Hello, world.\n");
+ | ^~~~~~
+test2.c:1:1: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
+ +++ |+#include <stdio.h>
+ 1 | // #include <stdio.h>
+test2.c:5:3: warning: incompatible implicit declaration of built-in function ‘printf’ [-Wbuiltin-declaration-mismatch]
+ 5 | printf("Hello, world.\n");
+ | ^~~~~~
+test2.c:5:3: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
--- /dev/null
+#include <stdio.h>
+
+// int main()
+{
+ printf("Hello, world.\n");
+}
--- /dev/null
+gcc -x c -Wall -Wextra -pedantic -o test3.out test3.c
+test3.c:4:1: error: expected identifier or ‘(’ before ‘{’ token
+ 4 | {
+ | ^
+make: *** [Makefile:16: test3] Error 1
--- /dev/null
+CC=gcc
+CFLAGS=-x c -Wall -Wextra -pedantic
+OUTFILE=hello
+SOURCE=hello.c
+
+all: $(SOURCE)
+ $(CC) $(CFLAGS) -o $(OUTFILE) $(SOURCE)
+
+clean:
+ rm -f $(OUTFILE)
--- /dev/null
+#include <stdio.h>
+int main()
+{
+ printf("hello\n");
+ printf("\v"); // Vertical tab
+ printf("world\?\n"); // Question mark
+ printf("foo\x0A"); // Newline (hexadecimal)
+ printf("ba\br\n"); // Backspace
+ printf("baz\b\n"); // Backspace moves cursor back but doesn't overwrite z
+ printf("baz\b \n"); // Backspace overwrites z with space
+}
CC=gcc
-CFLAGS=-Wall -Wextra -pedantic
+CFLAGS=-x c -Wall -Wextra -pedantic
OUTFILE=a.out
SOURCE=hello.c
--- /dev/null
+hello
+a.out
--- /dev/null
+CC=gcc
+CFLAGS=-x c -Wall -Wextra -pedantic
+OUTFILE=a.out
+SOURCE=hello.c
+
+all: $(SOURCE)
+ $(CC) $(CFLAGS) -o $(OUTFILE) $(SOURCE)
+
+clean:
+ rm -f $(OUTFILE)
--- /dev/null
+#include <stdio.h>
+
+main() {
+ printf("hello, ");
+ printf("world");
+ printf("\n");
+}