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

Hoisting breaks array initialization #56

Open
MathieuSoysal opened this issue Aug 9, 2023 · 7 comments · Fixed by #57
Open

Hoisting breaks array initialization #56

MathieuSoysal opened this issue Aug 9, 2023 · 7 comments · Fixed by #57

Comments

@MathieuSoysal
Copy link

MathieuSoysal commented Aug 9, 2023

Introduction

Currently, I'm trying to initialize an array that has a fixed length like that:

image

This code is ok for Norminette and is compilable:
image

Problem

The formatter, formats the code like that:

image

And this version of the code is not compilable:
image

@cacharle
Copy link
Collaborator

cacharle commented Aug 9, 2023

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

@cacharle cacharle changed the title Doesn't work with array initialization Hoisting breaks array initialization Aug 9, 2023
cacharle added a commit that referenced this issue Aug 9, 2023
@cacharle cacharle linked a pull request Aug 9, 2023 that will close this issue
cacharle added a commit that referenced this issue Aug 9, 2023
@MathieuSoysal
Copy link
Author

MathieuSoysal commented Aug 10, 2023

Thank for your help ! 🥳 @cacharle

Unfortunately, we have a new problem now:

When we do this code:

image

the formatter formats the code like that:

image

But this version of formated code is not OK for Norminette.

cacharle added a commit that referenced this issue Aug 10, 2023
@cacharle
Copy link
Collaborator

cacharle commented Aug 10, 2023

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

@cacharle cacharle reopened this Aug 10, 2023
@MathieuSoysal
Copy link
Author

Unfortunately I have tested but I think is an issue with Norminette now

@cacharle
Copy link
Collaborator

Even if the norminette fails, do you have the behavior you desire when you try it out?

@MathieuSoysal
Copy link
Author

MathieuSoysal commented Aug 11, 2023

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?

@cacharle
Copy link
Collaborator

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

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

Successfully merging a pull request may close this issue.

2 participants