Switch to C instead of C++, added example, program now reads file

This commit is contained in:
2026-01-22 18:08:23 +00:00
parent 4ac780e3e9
commit 4ec6dd8259
5 changed files with 63 additions and 33 deletions

View File

@@ -3,5 +3,4 @@
((nil . ((compile-command . "make MODE=debug -B -k") ((nil . ((compile-command . "make MODE=debug -B -k")
(+license/license-choice . "MIT License"))) (+license/license-choice . "MIT License")))
(c-mode . ((mode . clang-format))) (c-mode . ((mode . clang-format))))
(c++-mode . ((mode . clang-format))))

View File

@@ -1,10 +1,10 @@
CXX=c++ CC=cc
DIST=build DIST=build
OUT=$(DIST)/main.out OUT=$(DIST)/main.out
LDFLAGS= LDFLAGS=
GFLAGS=-Wall -Wextra -Wpedantic -std=c++23 GFLAGS=-Wall -Wextra -Wpedantic -std=c23
DFLAGS=-ggdb -fsanitize=address -fsanitize=undefined DFLAGS=-ggdb -fsanitize=address -fsanitize=undefined
RFLAGS=-O3 RFLAGS=-O3
@@ -16,10 +16,10 @@ CFLAGS=$(GFLAGS) $(DFLAGS)
endif endif
$(OUT): $(DIST)/main.o | $(DIST) $(OUT): $(DIST)/main.o | $(DIST)
$(CXX) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
$(DIST)/main.o: main.cpp | $(DIST) $(DIST)/main.o: main.c | $(DIST)
$(CXX) $(CFLAGS) -c -o $@ $^ $(CC) $(CFLAGS) -c -o $@ $^
$(DIST): $(DIST):
mkdir -p $(DIST) mkdir -p $(DIST)

1
examples/hello-world.arl Normal file
View File

@@ -0,0 +1 @@
"Hello, world! println

56
main.c Normal file
View File

@@ -0,0 +1,56 @@
/* main.cpp:
* Created: 2026-01-22
* Author: Aryadev Chavali
* License: See end of file
* Commentary:
*/
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#define FAIL(...) \
do \
{ \
fprintf(stderr, "FAIL: "); \
fprintf(stderr, __VA_ARGS__); \
abort(); \
} while (0)
char *read_file(const char *filename)
{
FILE *fp = fopen(filename, "rb");
if (!fp)
FAIL("File `%s` does not exist\n", filename);
fseek(fp, 0, SEEK_END);
long size = ftell(fp);
fseek(fp, 0, SEEK_SET);
char *buffer = calloc(1, size + 1);
fread(buffer, size, 1, fp);
fclose(fp);
buffer[size] = '\0';
return buffer;
}
int main(void)
{
const char *filename = "./examples/hello-world.arl";
char *buffer = read_file(filename);
printf("%s => %s\n", filename, buffer);
free(buffer);
return 0;
}
/* Copyright (C) 2026 Aryadev Chavali
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the MIT License for details.
* You may distribute and modify this code under the terms of the MIT License,
* which you should have received a copy of along with this program. If not,
* please go to <https://opensource.org/license/MIT>.
*/

View File

@@ -1,26 +0,0 @@
/* main.cpp:
* Created: 2026-01-22
* Author: Aryadev Chavali
* License: See end of file
* Commentary:
*/
#include <cstdio>
int main(void)
{
puts("Hello, world!");
return 0;
}
/* Copyright (C) 2026 Aryadev Chavali
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the MIT License for details.
* You may distribute and modify this code under the terms of the MIT License,
* which you should have received a copy of along with this program. If not,
* please go to <https://opensource.org/license/MIT>.
*/