Skip to content

coddra/c-plu

Repository files navigation

C-PLU

Funky little extra features to C to make it even more fun.

c-plu is based on the cproc compiler by Michael Forney. See cproc-README.md for more details.

Currently added features:

If any features break backwards compatibility, please let me know by opening an issue.

Auto dereferencing

Given a pointer to a struct/union, using the . operator with an identifier will automatically dereference the pointer.

struct location {
    int x;
    int y;
};

int main(void) {
    struct location *loc = malloc(sizeof(struct location));

    // works just fine
    loc.x = 0;
    loc.y = 0;

    return 0;
}

DotCall

Dot syntax function call with auto lifting (DotCall for short) allows to locate the first parameter of a function call before the function. Auto lifting refers to automatically taking the addres of that argument, if possible.

int add(int x, int y) {
    return x + y;
}

int* inc(int *x) {
    ++*x;
    return x;
}

int main(void) {
    int x = 0;

    // works just fine
    x = x.add(34).add(35);

    // works just fine because of auto lifting
    x.inc().inc();

    // would not work, as cannot take address of literal
    //(0).inc();

    // auto dereferencing makes this possible
    int *y = malloc(sizeof(int));
    *y = y.add(10);

    return 0;
}

About

Funky little extra features for C

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 9