1//===-- examples/ExternalHelloWorld/external-hello.cpp ----------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "flang/Runtime/io-api.h"
10#include "flang/Runtime/main.h"
11#include "flang/Runtime/stop.h"
12#include <cstring>
13#include <limits>
14
15using namespace Fortran::runtime::io;
16
17void output1() {
18 auto io{IONAME(BeginExternalListOutput)()};
19 const char str[]{"Hello, world!"};
20 IONAME(OutputAscii)(io, str, std::strlen(s: str));
21 IONAME(OutputInteger64)(io, 678);
22 IONAME(OutputReal64)(io, 0.0);
23 IONAME(OutputReal64)(io, 2.0 / 3.0);
24 IONAME(OutputReal64)(io, 1.0e99);
25 IONAME(OutputReal64)(io, std::numeric_limits<double>::infinity());
26 IONAME(OutputReal64)(io, -std::numeric_limits<double>::infinity());
27 IONAME(OutputReal64)(io, std::numeric_limits<double>::quiet_NaN());
28 IONAME(OutputComplex64)(io, 123.0, -234.0);
29 IONAME(OutputLogical)(io, false);
30 IONAME(OutputLogical)(io, true);
31 IONAME(EndIoStatement)(io);
32}
33
34void input1() {
35 auto io{IONAME(BeginExternalListOutput)()};
36 const char prompt[]{"Enter an integer value:"};
37 IONAME(OutputAscii)(io, prompt, std::strlen(s: prompt));
38 IONAME(EndIoStatement)(io);
39
40 io = IONAME(BeginExternalListInput)();
41 std::int64_t n{-666};
42 IONAME(InputInteger)(io, n);
43 IONAME(EndIoStatement)(io);
44
45 io = IONAME(BeginExternalListOutput)();
46 const char str[]{"Result:"};
47 IONAME(OutputAscii)(io, str, std::strlen(s: str));
48 IONAME(OutputInteger64)(io, n);
49 IONAME(EndIoStatement)(io);
50}
51
52int main(int argc, const char *argv[], const char *envp[]) {
53 RTNAME(ProgramStart)(argc, argv, envp, nullptr);
54 output1();
55 input1();
56 RTNAME(PauseStatement)();
57 RTNAME(ProgramEndStatement)();
58 return 0;
59}
60

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