I have this code here:
Void() aba ()
{
}
#define std_Dynamic_Array(T) struct{Int32() count; Int32() capacity; T* memory; }
Void() no_body_func (Int32() b);
Int32() test_func (Int32()*** a)
{
}
Int32() test_func2 (Int32() x)
{
}
Int32() b = 33;
#define v_macro(T) struct{Int32() count; Int32() capacity; T* memory; } v (std_Dynamic_Array(T)* m)
{
Int32() l = 44;
}
Void() _main ()
{
Int64() a = 5;
b = 22;
Int32() c = test_func2(6);
Int32() inner_func (Int32()* a)
{
Int32() g = 3;
}
Int32()* x = &b;
inner_func(x);
Int32() j = *x;
Float32() f = 33.000000;
std_Dynamic_Array(Int64()) da = {.count = 4};
v_macro(Int64());
std_Dynamic_Array(Int64()) k = v(&da);
}
int main(int argc, char ** argv)
{
return 0;
}
I’m playing around with writing my own compiler that can generate C code as one of the targets. My problem is that I’m getting this weird error:
tests/simple.c:34:36: error: invalid initializer
34 | std_Dynamic_Array(Int64()) k = v(&da);
| ^
Here’s code generated by gcc -E ...
void aba ()
{
}
void no_body_func (int b);
int test_func (int*** a)
{
}
int test_func2 (int x)
{
}
int b = 33;
void _main ()
{
long long a = 5;
b = 22;
int c = test_func2(6);
int inner_func (int* a)
{
int g = 3;
}
int* x = &b;
inner_func(x);
int j = *x;
float f = 33.000000;
struct{int count; int capacity; long long* memory; } da = {.count = 4};
struct{int count; int capacity; long long* memory; } v (struct{int count; int capacity; long long* memory; }* m) { int l = 44; };
struct{int count; int capacity; long long* memory; } k = v(&da);
}
int main(int argc, char ** argv)
{
return 0;
}
Why is this error happening? Both v
‘s return type and k
‘s type expand to struct{int count; int capacity; long long* memory; }
, so why does GCC treat them as different types?
What can I possibly do to fix this?
Also:
- I don’t care about code readability, this is generated code meant for GCC, not for humans to deal with.
- If the solution requires the most hacky GCC trickery known to man and language extensions, so be it. The C target outputs code that will work strictly with GCC, no need to worry about clang, MSVC, ICC, etc.
I know I could probably solve this by generating some typedefs, but I want to avoid that. For now at least.
Thanks!!