1#include "flang/Runtime/io-api.h"
2#include "flang/Runtime/main.h"
3#include "flang/Runtime/stop.h"
4#include <cstring>
5#include <limits>
6
7using namespace Fortran::runtime::io;
8
9void output1() {
10 auto io{IONAME(BeginExternalListOutput)()};
11 const char str[]{"Hello, world!"};
12 IONAME(OutputAscii)(io, str, std::strlen(s: str));
13 IONAME(OutputInteger64)(io, 678);
14 IONAME(OutputReal64)(io, 0.0);
15 IONAME(OutputReal64)(io, 2.0 / 3.0);
16 IONAME(OutputReal64)(io, 1.0e99);
17 IONAME(OutputReal64)(io, std::numeric_limits<double>::infinity());
18 IONAME(OutputReal64)(io, -std::numeric_limits<double>::infinity());
19 IONAME(OutputReal64)(io, std::numeric_limits<double>::quiet_NaN());
20 IONAME(OutputComplex64)(io, 123.0, -234.0);
21 IONAME(OutputLogical)(io, false);
22 IONAME(OutputLogical)(io, true);
23 IONAME(EndIoStatement)(io);
24}
25
26void input1() {
27 auto io{IONAME(BeginExternalListOutput)()};
28 const char prompt[]{"Enter an integer value:"};
29 IONAME(OutputAscii)(io, prompt, std::strlen(s: prompt));
30 IONAME(EndIoStatement)(io);
31
32 io = IONAME(BeginExternalListInput)();
33 std::int64_t n{-666};
34 IONAME(InputInteger)(io, n);
35 IONAME(EndIoStatement)(io);
36
37 io = IONAME(BeginExternalListOutput)();
38 const char str[]{"Result:"};
39 IONAME(OutputAscii)(io, str, std::strlen(s: str));
40 IONAME(OutputInteger64)(io, n);
41 IONAME(EndIoStatement)(io);
42}
43
44int main(int argc, const char *argv[], const char *envp[]) {
45 RTNAME(ProgramStart)(argc, argv, envp, nullptr);
46 output1();
47 input1();
48 RTNAME(PauseStatement)();
49 RTNAME(ProgramEndStatement)();
50 return 0;
51}
52

source code of flang/examples/ExternalHelloWorld/external-hello.cpp