fpjohnston / TECO-64

Enhanced and portable version of TECO text editor in C.
24 stars 6 forks source link

Variable declaration after goto Label #6

Closed polluks closed 2 years ago

polluks commented 2 years ago
Making env_sys.o
../src/env_sys.c: In function 'teco_env':
../src/env_sys.c:225:13: error: a label can only be part of a statement and a declaration is not a statement
  225 |             pid_t pid = tcgetpgrp(STDIN_FILENO);
      |             ^~~~~
make: *** [Makefile:411: env_sys.o] Error 1

https://stackoverflow.com/questions/8384388/variable-declaration-after-goto-label

fpjohnston commented 2 years ago

I'm a little confused about the error, but I think it's probably occurring because your compiler won't allow declarations following case statements. So the remedy would then be to enclose the body of the case in braces, as follows:

    case -5:
    {
        pid_t pid = tcgetpgrp(STDIN_FILENO);

        if (pid == -1)
        {
            return -1;              // Process is child or detached
        }
        else if (pid == getpgrp())
        {
            return (int)pid;        // Foreground process
        }
        else
        {
            return 0;               // Background process
        }
    }

Could you please try this and let me know if it fixes the problem? If so, I can include the change in the next release.

Thanks.

On Fri, Mar 11, 2022 at 7:27 PM Stefan @.***> wrote:

Making env_sys.o ../src/env_sys.c: In function 'teco_env': ../src/env_sys.c:225:13: error: a label can only be part of a statement and a declaration is not a statement 225 | pid_t pid = tcgetpgrp(STDIN_FILENO); | ^~~~~ make: *** [Makefile:411: env_sys.o] Error 1

https://stackoverflow.com/questions/8384388/variable-declaration-after-goto-label

— Reply to this email directly, view it on GitHub https://github.com/fpjohnston/TECO-64/issues/6, or unsubscribe https://github.com/notifications/unsubscribe-auth/AK73X7C63MVKD5TDICR7UILU7PQG3ANCNFSM5QRBXT7A . You are receiving this because you are subscribed to this thread.Message ID: @.***>

polluks commented 2 years ago

works, thx