c_formatter_42
c_formatter_42 copied to clipboard
Hoisting breaks array initialization
Introduction
Currently, I'm trying to initialize an array that has a fixed length like that:
This code is ok for Norminette and is compilable:
Problem
The formatter, formats the code like that:
And this version of the code is not compilable:
Indeed, there should be an edge case in the hoist formatter for this or we could remove the hoist formatter completly and let the people do it themself
Thank for your help ! 🥳 @cacharle
Unfortunately, we have a new problem now:
When we do this code:
the formatter formats the code like that:
But this version of formated code is not OK for Norminette.
Could you try the version I just pushed on your local machine, to make sure the bug is fixed?
git clone --branch 56-hoisting-breaks-array-initialization https://github.com/dawnbeen/c_formatter_42
cd c_formatter_42
python3 -m venv venv
. venv/bin/activate
pip install -e .
c_formatter_42 < some_file.c
Unfortunately I have tested but I think is an issue with Norminette now
Even if the norminette fails, do you have the behavior you desire when you try it out?
Maybe we can implement a solution to be Norminette friendly:
int main(int argc, char const *argv[])
{
int length;
int array[3] = {3, 5, 7};
length = sizeof(array) / sizeof(array[0]);
return (0);
}
Formmating to:
int main(int argc, char const *argv[])
{
int length;
int array[3];
array[0] = 3;
array[1] = 5;
array[2] = 7;
length = sizeof(array) / sizeof(array[0]);
return (0);
}
Maybe this solution is a little bit hard to implement, but if you want, I can give some help to you if you explain how to do it.
What do you think about this solution?
I don't like that, it will fill all the lines with a bigger array. This edge case is too specific to have a complex logic to handle it
I think that if the norminette doesn't allow array initialization, we shouldn't find a way to make it work, the user should be the one that doesn't use that feature.
Leaving array assignment alone is ok imo