Skip to content

Conversation

@ivanhercaz
Copy link

This error was being given on some switches statements and produces errors that avoid to compile the code depending of the compiler.

As the idea is to have something robust and it is an easy fix, I think it can be better to have it implemented. Another thing would be if it will be better to standardize all cases with curly braces.

This branch has been created from your latest main, although the fix is already integrated in all our branches.

Anyway, an example of the error given while trying to compile is this one:

.../bacnet_ex/src/object/binary_input.c: In function ‘binary_input_read_property’:
.../bacnet_ex/src/object/binary_input.c:239:7: error: a label can only be part of a statement and a declaration is not a statement
  239 |       BACNET_CHARACTER_STRING name;
      |       ^~~~~~~~~~~~~~~~~~~~~~~
.../bacnet_ex/src/object/binary_input.c:245:7: error: a label can only be part of a statement and a declaration is not a statement
  245 |       BACNET_CHARACTER_STRING description;
      |       ^~~~~~~~~~~~~~~~~~~~~~~
.../bacnet_ex/src/object/binary_input.c:264:7: error: a label can only be part of a statement and a declaration is not a statement
  264 |       BACNET_CHARACTER_STRING active_text;
      |       ^~~~~~~~~~~~~~~~~~~~~~~
.../bacnet_ex/src/object/binary_input.c:270:7: error: a label can only be part of a statement and a declaration is not a statement
  270 |       BACNET_CHARACTER_STRING inactive_text;
      |       ^~~~~~~~~~~~~~~~~~~~~~~
.../bacnet_ex/src/object/binary_input.c:276:7: error: a label can only be part of a statement and a declaration is not a statement
  276 |       BACNET_BIT_STRING status;
      |       ^~~~~~~~~~~~~~~~~

…is not a statement"

This error was being given on some switchs statements and produces errors that avoid to compile the code.
@abelino
Copy link
Contributor

abelino commented Apr 23, 2025

@ivanhercaz What gcc compiler version are you using? I am not seeing this compiler error on GNU 14.2.1. Historically, it is well known that scoping is required when instantiating a variable within a case and now I am wondering if that has gone away in more recent gcc compiler?

@ivanhercaz
Copy link
Author

What gcc compiler version are you using?

@abelino, the computer in with the error was thrown has gcc 9.4.0 and it is an Ubuntu 20.04.2 (LTS).

In other computer in which I run also debug I have gcc 14.2.1 and it is a Manjaro. In this one the error is not thrown.

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 this pull request may close these issues.

2 participants