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

Feature: C23 improved tag compatibility missing implementation #187

Open
ib00 opened this issue Apr 8, 2024 · 3 comments
Open

Feature: C23 improved tag compatibility missing implementation #187

ib00 opened this issue Apr 8, 2024 · 3 comments

Comments

@ib00
Copy link

ib00 commented Apr 8, 2024

Not many compilers (currently only gcc trunk) support C23 improved tag compatibility:
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3037.pdf

Some data structures would be easier with this feature supported.

@thradams
Copy link
Owner

thradams commented Apr 8, 2024

The idea for this feature is just remove the struct members from struct type.
For instance

struct X { int i; };
void f(struct X { int i; } x){ }

generated code

struct X { int i; };
void f(struct X x) {}

What is missing is the comparison with the previous tag X.

@ib00
Copy link
Author

ib00 commented Apr 8, 2024

Here's an example that I have been plating with:

#define Array(TYPE) struct TYPE##Array {TYPE* elements; int count;}

void foo(Array(int) myArr) {
    // do something
}

int main() {
    Array(int) myInts;
    myInts.elements = (int*) (int[3]) {3, 2, 1};
    myInts.count = 3;
    foo(myInts);
    return 0;
}

This should compile with C23. At the moment only gcc trunk supports this.

@thradams
Copy link
Owner

thradams commented Apr 9, 2024

There are some details.
structs declared inside arguments does not have global scope.
Then cake would have to introduce one declaration.
or, if the user puts the like here

#define Array(TYPE) struct TYPE##Array {TYPE* elements; int count;}
#pragma expand Array

Array(int);

void foo(Array(int) myArr) {
    // do something
}

int main() {
    Array(int) myInts;
    myInts.elements = (int*) (int[3]) {3, 2, 1};
    myInts.count = 3;
    foo(myInts);
    return 0;
}

then the generated code would be

```c
#define Array(TYPE) struct TYPE##Array {TYPE* elements; int count;}
#pragma expand Array


struct intArray {int* elements; int count;};

void foo(struct intArray myArr) {

}

int main() {
    struct intArray myInts;
    myInts.elements = (int*) (int[3]) {3, 2, 1};
    myInts.count = 3;
    foo(myInts);
    return 0;
}

@thradams thradams changed the title Feature: Tag compatibility Feature: C23 tag compatibility Aug 31, 2024
@thradams thradams changed the title Feature: C23 tag compatibility Feature: C23 improved tag compatibility missing implementation Aug 31, 2024
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