Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create string type #22

Open
LytixDev opened this issue Feb 3, 2023 · 2 comments
Open

create string type #22

LytixDev opened this issue Feb 3, 2023 · 2 comments
Assignees

Comments

@LytixDev
Copy link
Member

LytixDev commented Feb 3, 2023

The default char * array in C works fine, but its prone to errors. Since it does not keep track of the length of the string, buffer overflows and other security vulnerabilities are common. Modern computers have enough memory to store the length of the char * with the string. This would make it easier, and more safe, to use. If we were to implement a string type we would make sure it can be compatible with all the builtin str functions. We could also just make some of our owns.

@LytixDev
Copy link
Member Author

LytixDev commented Feb 3, 2023

struct string_t {
    char *str;
    size_t len;
    size_t capacity;
};

@LytixDev
Copy link
Member Author

LytixDev commented Feb 3, 2023

One advantage is that the type could be mutable: it dynamically changes its size on demand. We could also make an immutable string. That has its uses as well.

@callumgran callumgran self-assigned this Apr 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants