kaisenamin / c_std Goto Github PK
View Code? Open in Web Editor NEWImplementation of C++ standard libraries in C
License: ISC License
Implementation of C++ standard libraries in C
License: ISC License
Nice work! Added a standard compile chain to have a look but doesn't compile "as is". Feel free to borrow.
ARG base_tag=bullseye
ARG base_img=mcr.microsoft.com/vscode/devcontainers/base:dev-${base_tag}
FROM --platform=linux/amd64 ${base_img} AS builder-install
RUN apt-get update --fix-missing && apt-get -y upgrade
RUN apt-get install -y --no-install-recommends \
apt-utils \
curl \
cmake \
build-essential \
gcc \
gdb \
g++-multilib \
locales \
make \
ruby \
gcovr \
wget \
python3 \
&& rm -rf /var/lib/apt/lists/*
# project
project_name=c_std
builder-build :
docker build \
-f builder.Dockerfile
-t ${project_name}-builder:latest .
builder-run :
docker run \
--rm \
-it \
--platform linux/amd64 \
--workdir /builder/mnt \
-v ${PWD}:/builder/mnt \
${project_name}-builder:latest \
/bin/bash
#/bin/bash -c "python3 compile.py b"
make builder-build
make builder-run
(container) python3 compile.py b
...truncated...
file_io/file_writer.c: In function ‘file_writer_lock’:
file_io/file_writer.c:494:15: warning: implicit declaration of function ‘fileno’ [-Wimplicit-function-declaration]
494 | if (fcntl(fileno(writer->file_writer), F_SETLKW, &fl) == -1) {
| ^~~~~~
file_io/file_writer.c: In function ‘file_writer_truncate’:
file_io/file_writer.c:580:9: warning: implicit declaration of function ‘ftruncate’; did you mean ‘strncat’? [-Wimplicit-function-declaration]
580 | if (ftruncate(fd, size) == -1) {
| ^~~~~~~~~
| strncat
Compilation failed.
//json.c:621
if (state.current_token.type == JSON_TOKEN_OBJECT_START) {
root = parse_object(&state);
}
else if (state.current_token.type == JSON_TOKEN_ARRAY_START) {
root = parse_array(&state);
}
else {
fmt_fprintf(stderr, "Error: Root element must be an object or array at position %zu.\n", state.position);
free(state.input);
return NULL;
}
But a json can be valid as a single and unique value
"value"
53
etc...
I noticed there is no Trie (prefix tree) module yet. I am almost finished writing one then I'll initiate a PR. Apologize for any time lag in advance, I work on it when day job isn't occupying all my time.
I may add all issues about vector_push_back,vector_emplace_back
and related for reference to check
// json.c:789
case JSON_ARRAY:
for (size_t i = 0; i < vector_size(element->value.array_val); ++i) {
JsonElement *item = json_deep_copy(*(JsonElement **)vector_at(element->value.array_val, i));
if (!item) {
json_deallocate(copy);
return NULL;
}
vector_push_back(copy->value.array_val, &item);
}
break;
What is expected here for example if vector_push_back
fails ? Should not we free all the copied data and return NULL
?
Because user may have a error message but nothing is recoverable from here...
Hi, when I test your code I find a good way to solve it without use the FMT_END_ARGS
in fmt.c
locate in fmt_print
and fmt_println
.
when i use the api , i don't want to use it with the define FMT_END_ARGS
just like the following code.
int main() {
const char* str = "Hello, World!";
fmt_println(str);
return 0;
}
the output is
Compilation successful. Output: ./build/main
Running the program...
*************************
Hello, World! �L�� �L�� @!�I�U ��UH��AWAVAUATSH��8L�%�I
There is a high probability that garbled characters appear because you cannot use simple define va_arg() to show all parameter list in C code. It causes undefined behavior.
Do you mind considering using NULL pointer or -1 as return value for when there is an error instead of exit(-1) ? It isn't safe to use with exit(-1) because most of the time we don't want an application to crash because of a simple error even if it's memory related.
But also, is it possible to guard each call to fmt_fprintf with a "#ifdef LOGGING_ENABLE" or "#ifndef LOGGING_DISABLE" ? We don't want all the time printing to stderr libraries error in client applications
if (vec->size == vec->capacitySize) {
vector_reserve(vec, vec->capacitySize * 2); // Use the modified version
}
char *base = (char *)vec->items;
memmove(base + (pos + 1) * vec->itemSize,
base + pos * vec->itemSize,
(vec->size - pos) * vec->itemSize);
memcpy(base + pos * vec->itemSize, item, vec->itemSize);
vec->size++;
What is the vector supposed to do when reserve fails this is actually a really dangerous matter as we may overwrite data. There shall be a way to inform the user of problems (other than just printing out a message)
Simply returning a boolean maybe ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.