2.5 Using stdin to input source code to the compiler

Instead of creating a file for your source code, you can use stdin to input source code directly on the command line.

This is useful if you want to test a short piece of code without having to create a file for it.

Procedure

  1. Invoke the compiler with the command-line options you want to use. The default compiler mode is C. Use the minus character (-) as the source filename to instruct the compiler to take input from stdin. For example:

    armcc --bigend -c -

    If you want an object file to be written, use the -o option. If you want preprocessor output to be sent to the output stream, use the -E option. If you want the output to be sent to stdout, use the -o- option. If you want an assembly listing of the keyboard input to be sent to the output stream after input has been terminated, use none of these options.

  2. You cannot input on the same line after the minus character. You must press the return key if you have not already done so.

    The command prompt waits for you to enter more input.

  3. Enter your input. For example:
    #include <stdio.h>
    int main(void)
    { printf("Hello world\n"); }
    
  4. Terminate your input:
    • Press Ctrl+Z then Return on Microsoft Windows systems.
    • Press Ctrl+D on Red Hat Linux systems.

An assembly listing for the keyboard input is sent to the output stream after input has been terminated if both the following are true:

  • No output file is specified.

  • No preprocessor-only option is specified, for example -E.

Otherwise, an object file is created or preprocessor output is sent to the standard output stream, depending on whether you used the -o option or the -E option.

The compiler accepts source code from the standard input stream in combination with other files, when performing a link step. For example, the following are permitted:

  • armcc -o output.axf - object.o mylibrary.a

  • armcc -o output.axf --c90 source.c -

Executing the following command compiles the source code you provide on standard input, and links it into test.axf:

armcc -o test.axf -

You can only combine standard input with other source files when you are linking code. If you attempt to combine standard input with other source files when not linking, the compiler generates an error.

Non-ConfidentialPDF file icon PDF versionARM DUI0472M
Copyright © 2010-2016 ARM Limited or its affiliates. All rights reserved.