S
Stefan Ram
I'll return to Java later, but first I will look at C:
The following C program has a problem:
#include <stdio.h>
int main( void ){ printf( "A" ); }
Readers might try to spot it themselves before
continuing to read the following explanation of the problem.
Spoiler:
ISO/IEC 9899:1999 (E) states:
»A text stream is an ordered sequence of characters
composed into lines, each line consisting of zero or more
characters plus a terminating new-line character. Whether
the last line requires a terminating new-line character is
implementation-defined.«
ISO/IEC 9899:1999 (E), 7.19.2#2
Thus, the last line of a text stream might require a terminating
new-line character in some implementations. The above program,
therefore, might not comply with some implementations, while
the following will never have this problem.
#include <stdio.h>
int main( void ){ printf( "A\n" ); }
Now, my question regarding Java: Is anything wrong with
the following Java program?
public class Main
{ public static void main( final java.lang.String[] args )
{ java.lang.System.out.print( "A" ); }}
The output might look ugly, because it might not be separated
from text following it properly, but is there a wording
similar to ISO/IEC 9899:1999 (E), 7.19.2#2 somewhere in a Java
specification that might condemn this program in a similar
manner to ISO/IEC 9899:1999 (E), 7.19.2#2?
(7.19.2 is in C because the I/O facilities offered by the
environment (operating system) might require a terminating
linefeed. If a Java implementation is running in the same
environment, it should inherit the same limitations from the
same environment. So, if Java guarantees that the last line
never requires a terminating new-line character, how does it
do that? [One answer would be: by excluding those environments
that require a terminating new-line character.])
The following C program has a problem:
#include <stdio.h>
int main( void ){ printf( "A" ); }
Readers might try to spot it themselves before
continuing to read the following explanation of the problem.
Spoiler:
ISO/IEC 9899:1999 (E) states:
»A text stream is an ordered sequence of characters
composed into lines, each line consisting of zero or more
characters plus a terminating new-line character. Whether
the last line requires a terminating new-line character is
implementation-defined.«
ISO/IEC 9899:1999 (E), 7.19.2#2
Thus, the last line of a text stream might require a terminating
new-line character in some implementations. The above program,
therefore, might not comply with some implementations, while
the following will never have this problem.
#include <stdio.h>
int main( void ){ printf( "A\n" ); }
Now, my question regarding Java: Is anything wrong with
the following Java program?
public class Main
{ public static void main( final java.lang.String[] args )
{ java.lang.System.out.print( "A" ); }}
The output might look ugly, because it might not be separated
from text following it properly, but is there a wording
similar to ISO/IEC 9899:1999 (E), 7.19.2#2 somewhere in a Java
specification that might condemn this program in a similar
manner to ISO/IEC 9899:1999 (E), 7.19.2#2?
(7.19.2 is in C because the I/O facilities offered by the
environment (operating system) might require a terminating
linefeed. If a Java implementation is running in the same
environment, it should inherit the same limitations from the
same environment. So, if Java guarantees that the last line
never requires a terminating new-line character, how does it
do that? [One answer would be: by excluding those environments
that require a terminating new-line character.])