dave@cs.arizona.edu (Dave P. Schaumann) (03/04/91)
I've come across a curious incompatability between Manx and Lattice, and I'm hoping that someone can clear the air for me. Through the course of events, a friend and I both compiled the following code. I with Manx 3.6a, he with a Lattice compiler (sorry, don't know the version): /* Please excuse any typos; I typed this from memory. */ #include <stdio.h> main() { FILE *my_win ; int c ; if( (my_win = fopen( "CON:10/10/100/200/C window", "a+" )) == NULL ) { puts( "Can't open window!" ) ; exit(1) ; } fprintf( my_win, "Some text\nAnd more text\n" ) ; while( (c = fgetc(my_win)) != EOF ) putc( c ) ; fclose( my_win ) ; puts( "Successful!" ) ; exit(0) ; } As you can see, this is a very straight forward, simple program that opens a window, prints some text, then enters a loop that reads characters from the program window and prints them to the shell window. My version of this works fine. The version compiled with Lattice sees EOF at fgetc() the first time it is executed, and exits immediately, whatever the input is. My question is: is the Lattice compiler broken/deficient, or is this an example of code with undefined behaviour? -- Dave Schaumann dave@cs.arizona.edu 'Dog Gang'! Where do they get off calling us the 'Dog Gang'? I'm beginning to think the party's over. I'm beginning to think maybe we don't need a dog. Or maybe we need a *new* dog. Or maybe we need a *cat*! - Amazing Stories
markv@kuhub.cc.ukans.edu (03/12/91)
In article <1001@caslon.cs.arizona.edu>, dave@cs.arizona.edu (Dave P. Schaumann) writes: > I've come across a curious incompatability between Manx and Lattice, and > I'm hoping that someone can clear the air for me. > >Through the course of events, a friend and I both compiled the following code. >I with Manx 3.6a, he with a Lattice compiler (sorry, don't know the version): > > /* Please excuse any typos; I typed this from memory. > */ > #include <stdio.h> > > main() { > > FILE *my_win ; > int c ; > > if( (my_win = fopen( "CON:10/10/100/200/C window", "a+" )) == NULL ) { > puts( "Can't open window!" ) ; exit(1) ; You may be running into the fact that CON: is an Interactive stream device and does not support seeking, so I wouldn't count on the behavior of anything like fseek() or something that might call it implicitly like an "a+" mode stream. Try "r+" or "w+". > My version of this works fine. The version compiled with Lattice sees EOF > at fgetc() the first time it is executed, and exits immediately, whatever > the input is. Probably Lattice is calling Seek() (Amiga DOS) internally which will fail on CON:, and then returns an EOF because of it. > My question is: is the Lattice compiler broken/deficient, or is this an > example of code with undefined behaviour? -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Mark Gooderum Only... \ Good Cheer !!! Academic Computing Services /// \___________________________ University of Kansas /// /| __ _ Bix: mgooderum \\\ /// /__| |\/| | | _ /_\ makes it Bitnet: MARKV@UKANVAX \/\/ / | | | | |__| / \ possible... Internet: markv@kuhub.cc.ukans.edu ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~