msys2 / msys2/msys2.github.io

MinGW GCC mixing up the order of the lines I write?

Open
#118 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
CSS
Stars
3.3k
Forks
446
Avg merge
2h 16m
Merged PRs (30d)
1

Description

I recently started using MSYS2 so I haven't had a chance to make anything spectacular with it yet, but I've run into a problem with the C compiler (or what I assume is a problem with the C compiler).

Here's an example program I wrote:

#include <stdio.h>
#include <string.h>
char input[100];
int main() {
        for(;;) {
                printf("> ");
                gets(input);
                if ( strcmp(input, "hello") == 0 ) {
                        printf("hi :)\n");
                } else if ( strcmp(input, "goodbye") == 0 ) {
                        printf("bye :)\n");
                        return 0;
                } else {
                        printf("Could you repeat that?\n");
                }
        }
}

The expected output of this would look something like this:

> hello
hi :)
> d
Can you repeat that?
> goodbye
bye :)

However, the output I actually get looks like this:

hello
d
goodbye
> hi :)
> Can you repeat that?
> bye :)

I found the cause of this to be that even though I wrote the printf("> "); line before the gets(input); line, the compiler switches them at build time.

If I build this code on Cygwin or on a *NIX system it runs as expected, so this must be an issue with MSYS2.

Thanks for reading, and I hope this issue can be resolved. :)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the provided C program under MSYS2 and compare its output with the shown Cygwin or Unix behavior. Check whether the reported line ordering is caused by the compiler or by the runtime environment, then establish whether the issue belongs in MSYS2 and what observable behavior would count as resolved.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.