Skip to content

Fixing C warnings #934

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

Merged
merged 16 commits into from
Nov 29, 2021
Merged

Fixing C warnings #934

merged 16 commits into from
Nov 29, 2021

Conversation

Amaras
Copy link
Member

@Amaras Amaras commented Nov 11, 2021

Currently, no warnings are activated during compilation for C.
Because of this, the code might be inconsistent in certain places.
I aim to fix or remove some errors in the C code, depending on if we consistently violate warnings or not.

Currently, only the following algorithms build without warnings:

  • approximate_counting
  • computus
  • forward_euler_method
  • graham_scan
  • jarvis_march
  • monte_carlo_integration
  • thomas_algorithm
  • tree_traversal
  • verlet_integration

The main errors I see in the rest of them are sign-compare, unused-parameter and unused-variable, along with a implicit-function-declaration and two return-type.
I did not implement any changes to the code yet, but I'll do that in the following days (hence why it's a draft PR).

@Amaras Amaras added Problem This is a problem in the archive or an implementation. Implementation Edit This provides an edit to an algorithm implementation. (Code and maybe md files are edited.) lang: c C programming language labels Nov 11, 2021
@Amaras Amaras self-assigned this Nov 11, 2021
@Amaras
Copy link
Member Author

Amaras commented Nov 11, 2021

It seems that, actually, I have done immediately exactly what I have said I would not do.

Anyway, I did 1 commit per algorithm fix, so that reverting is easier.

I can tell there is probably something wrong on the Gaussian elimination algorithm because I could completely eliminate the rows parameter in one function... This kind of fix was to brutally remove unused variables and parameters and adjust callers.

The rest of the fixes are simply fiddling around between size_t and int until the compiler stops throwing signed-compare errors.

@Amaras Amaras marked this pull request as ready for review November 11, 2021 23:17
@ntindle
Copy link
Member

ntindle commented Nov 11, 2021

Does this mean that Gaussian is wrong as a whole?

@Amaras
Copy link
Member Author

Amaras commented Nov 11, 2021

Does this mean that Gaussian is wrong as a whole?

I have not checked the correctness of the code yet, so I can't answer properly. It's just that, intuitively, there's something wrong if you're able to not pass one of the dimensions of the matrix.

EDIT: Also, I did not run the executables. Seeing how it's coded, the Gaussian elimination is probably going to segfault if we step outside the assumptions that were made.

Removed useless cast to (size_t *) in stable_marriage
@Amaras
Copy link
Member Author

Amaras commented Nov 13, 2021

Okay, I think I know the basic assumption of the Gauss-Jordan algorithm's implementation. We assume that we have an n*n matrix, and we augment it with the vector, which means that we have an n*(n+1) matrix. As such, we technically don't need the rows parameter, since it's just cols - 1

@stormofice stormofice self-requested a review November 29, 2021 21:16
Copy link
Contributor

@stormofice stormofice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for the fixes!

Overall the changes look good to me, however there is a small typo in the gaussian elimination code.

Apart from that, it is ready to be merged.

@@ -50,7 +50,7 @@ void gaussian_elimination(double *a, const size_t rows, const size_t cols) {
void back_substitution(const double *a, double *x, const size_t rows,
const size_t cols) {

for (int i = rows - 1; i >= 0; --i) {
for (size_t i = rows - 1; i == 0; --i) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be i >= 0, otherwise the loop body will never be executed

@Amaras Amaras merged commit 71e27ba into algorithm-archivists:master Nov 29, 2021
@Amaras Amaras deleted the fix_c_warnings branch December 5, 2021 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Implementation Edit This provides an edit to an algorithm implementation. (Code and maybe md files are edited.) lang: c C programming language Problem This is a problem in the archive or an implementation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants