-
Notifications
You must be signed in to change notification settings - Fork 5
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
cannot use external const for array declaration #9
Comments
You already gave the answer. :-) Since by design we do not parse and interpret C code we cannot know for sure what value MAX has. Only local Blech constants can be used in this declaration. |
Okay, thanks for the quick reply! :-) Does that mean that there is no way in sharing the size of an array between Blech and C?
|
But you could define the size in Blech using |
Unfortunately not – at least not as of my understanding. I tried the following:
This leads to
This compiles, but still does not solve the problem. The
This means I cannot access blc_01test01_SIZE_FOR_C from outside, e.g. another C module, and – even if I could – I cannot use a variable for declaring the size of an array in C in a struct (which does not make any sense by the way), e.g.
leads to
|
Oh yes, sorry, you are right. The C error makes sense in my opinion. SIZE is a global variable which can be changed after compile time and then the size of the str array would not match the value of SIZE anymore. It is then not clear what size the type "struct test" has. So sharing constants between Blech and C is an issue at the moment. I'll reopen. |
One possible way to fix this is to generate a const declaration into the .h file even though we substitute their occurrences in the generated code. |
Describe the bug
The following code
leads to this compile error:
Means the external C constant cannot be used for declaring the array size in Blech.
Expected behaviour
I would expect that above approach works since MAX actually is a compile-time constant.
Or is this a deliberate restriction since Blech cannot verify that MAX is actually constant at compile time?
Screenshots
If applicable, add screenshots to help explain your problem.
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: