Hi all,
        I have used Msys2 to create a memory stick environment for 1st year Uni 
students. Basically I took a full install, added clang and a few other 
bits and pieces then went to town deleting stuff the students won't need 
- locale, most of the man pages, a lot of apps etc. I've basically gone 
from 1.38GB to 700MB. They run Msys2 from the stick and have a portable 
dev environment. I can't remember how I tested things but I assumed it 
worked and then rolled it out to the students.

        Today was the first time they had to write anything. I got them to 
write a simple app that would basically calculate average speed. The 
students started writing and then confusion reigned. The programme 
should ask for a distance then a time and then print out an average 
speed. The problem is that after the students typed in "./a.exe" they 
got a blank screen, no header or prompt for a distance.

        One student, with the blank screen, still typed in a distance followed 
by a time value and hey presto, the prompts then appeared followed by 
the average speed. In playing around with this, it appears that printf() 
works fine if not followed by a scanf(). Add in a scanf() and for some 
reason the terminal freezes until a value has been entered. The 
behaviour can be seen with this simple programme.

-----------------------------

/*
  * Activity Name:
  * Programmer:
  * Date:
  * Comments:
  */
#include <stdio.h>

int main(void)
{
        // Declare and initialise variables here
        float                   inputValue = 0;
                        
        printf("Hello world\n");
        printf("More from the app\n");
        printf("Even more\n");
        printf("Now lets try a scanf. Enter a float: \n");

        scanf("%f", &inputValue);
        
        return(0);
}

-----------------------------

        I've compiled this using the latest, as of a week ago, versions of both 
clang and gcc and the behaviour is the same. Comment out the scanf() and 
you will see the printf() work, displaying the several lines of output. 
The behaviour can be seen below. The compile with cc, aliased to clang, 
clang and gcc all show the behaviour of no output until a value has been 
entered. The value entered is the number you see after "./a.exe". The 
final cc build is with the scanf() commented out.

-----------------------------

agl@bluey ~ $ cd work/04
agl@bluey ~/work/04 $ cc test.c
agl@bluey ~/work/04 $ ./a.exe
45.6
Hello world
More from the app
Even more
Now lets try a scanf. Enter a float: agl@bluey ~/work/04 $
agl@bluey ~/work/04 $
agl@bluey ~/work/04 $ rm a.exe
agl@bluey ~/work/04 $ clang test.c
agl@bluey ~/work/04 $ ./a.exe
67.8
Hello world
More from the app
Even more
Now lets try a scanf. Enter a float: agl@bluey ~/work/04 $
agl@bluey ~/work/04 $
agl@bluey ~/work/04 $ rm a.exe
agl@bluey ~/work/04 $ gcc test.c
agl@bluey ~/work/04 $ ./a.exe
23.4
Hello world
More from the app
Even more
Now lets try a scanf. Enter a float: agl@bluey ~/work/04 $
agl@bluey ~/work/04 $
agl@bluey ~/work/04 $
agl@bluey ~/work/04 $ rm a.exe
agl@bluey ~/work/04 $ cc test.c
agl@bluey ~/work/04 $ ./a.exe
Hello world
More from the app
Even more
Now lets try a scanf. Enter a float:
agl@bluey ~/work/04 $

-----------------------------

        I've also fired up a Windows 7 cmd.exe, changed into the appropriate 
dir and with the scanf() in place run the app and got the expected behaviour

-----------------------------

C:\apps\devEnv\home\epro04ss\work\04>dir
  Volume in drive C is NTFS_APPS
  Volume Serial Number is AACE-A461

  Directory of C:\apps\devEnv\home\epro04ss\work\04

13/01/2016  06:06 PM    <DIR>          .
13/01/2016  06:06 PM    <DIR>          ..
13/01/2016  06:06 PM           130,076 a.exe
13/01/2016  05:40 PM               374 test.c
                2 File(s)        130,450 bytes
                2 Dir(s)  88,231,211,008 bytes free

C:\apps\devEnv\home\epro04ss\work\04>a.exe
Hello world
More from the app
Even more
Now lets try a scanf. Enter a float: 45.5

C:\apps\devEnv\home\epro04ss\work\04>

-----------------------------

        The machine I'm doing this on is a dual boot machine with Win7 and 
Gentoo Linux. I've rebooted into Linux, accessed the appropriate dir and 
compiled the test app with both clang and gcc, both current versions, 
and everything works as expected, similar to the output with the Win7 
cmd.exe.

        Sorry this is so long and rambling, but I'm teaching a Summer School of 
programming and I need to work out what's going wrong ASAP hence all the 
info I can think of.

        It's my guess that something is screwy with the terminal as the app 
works as expected in other environments. As to what's screwy I have NO 
idea. Any thoughts on what might be wrong would be greatly appreciated.

        Regards,
                Andrew


------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
_______________________________________________
Msys2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/msys2-users

Reply via email to