Stuck with Splint warnings

What happens

Hi, I’m using C for the first time to solve a challenge and after some days I’m still stuck with some Splint warnings. I think I’ve managed to solve most of them but I don’t know what can I do in this case.

I’m trying to use modifications (i.e. /*@modifies x@/) to indicate which parameter will be modified by each function, as Splint asks for. In order to use those modifications, I added the parameter names in the functions declaration. However, this produces another error: Declaration parameter has name.

What do you understand or find about that problem

I understand that I’m missing something about how to use Splint modifications.

You make any workaround? What did you do?

I’ve been reading the Splint documentation and searching for similar problems, but I still cannot get a way to solve the problem.


[link to pipeline]

I need help with

I don’t know how to specify which parameter is going to be modified without using the parameter names at the function declaration. How should I use the @modifies annotation in this case?

And if you have any other advice in order to pass the Splint warnings, I will appreciate it.

Ok, this seems to be a code that can’t pass the compilation and the linting.

Try using this for compiling:

gcc \
  -Wall \
  -Wextra \
  -Winit-self \
  -Wuninitialized \
  -Wmissing-declarations \
  -Winit-self \
  -ansi \
  -pedantic \
  -Werror \
  <your username>.c \
  -o <your username> \

and this for linting:

cppcheck \
  --error-exitcode=1 \
  <your username>.c \
&&  splint \
  -strict \
  -internalglobs \
  -modfilesys \
  -boundsread \
  <your username>.c

You can found a lot of problems related to your code and see the suggestions and why that happens.

I do not know much about C but log says you are define prototype function, i think there is no need to define names, just types.

look at print_answer definition.

Another suggestion is that you should use the annotation /modifies/ because you can get your code rejected for use mutations.

And how @immune-brain says, you don’t need to declare the prototypes.

Yes, I was declaring the function parameters without the names. I added the names because I didn’t found another way to use the annotation /modifies/, in order to specify which parameter is going to be modified by the function.

Ok, what if you declare functions without prototypes before main declaration?

This is an example how do you can declare a function:

static double azimuth_to_polar (/*@reldef@*/ double azimuth)
  /*@modifies nothing@*/ {
  double degrees;
  /*when azimuth is beetwen 0 and 90 is in the segment +X, +Y*/
  if (azimuth <= 90.0) {
    degrees = (90 - azimuth) * (M_PI / 180);
  /*when azimuth is > 90 you can take 360 and sustract the difference beetwen
    90 and the azimuth, because when azimuth = 90 it becomes the X axis*/
  else {
    degrees = (360 - (azimuth - 90)) * (M_PI / 180);
  return degrees;

You can found some examples of code in C on the repo.

Ok, I think I managed to solve the problem with the annotation @modifies. Now I have other problems due to the new parameters added to the linter and the compilation haha. I’m going to mark this question as solved. Thank you @pastel-code and @immune-brain.

1 Like