Keil Logo

Environment

14.3 Environment

Describes implementation-defined aspects of the ARM C compiler and C library relating to environment, as required by the ISO C standard requires.

The mapping of a command line from the ARM architecture-based environment into arguments to main() is implementation-specific. The generic ARM C library supports the following:

main()

The arguments given to main() are the words of the command line not including input/output redirections, delimited by whitespace, except where the whitespace is contained in double quotes.

Note

  • A whitespace character is any character where the result of isspace() is true.
  • A double quote or backslash character \ inside double quotes must be preceded by a backslash character.
  • An input/output redirection is not recognized inside double quotes.

Interactive device

In a nonhosted implementation of the ARM C library, the term interactive device might be meaningless. The generic ARM C library supports a pair of devices, both called :tt, intended to handle keyboard input and VDU screen output. In the generic implementation:
  • stdin, stdout, and stderr connect to :tt by default, but this does not affect how they are buffered.
  • If stdin, stdout, and stderr are not redirected, they are line buffered.
  • If stdin, stdout, and stderr are redirected, stdin and stdout are line buffered, and stderr is not line buffered.
  • If stderr and stdout are redirected to the same file, neither are line buffered.

Redirecting standard input, output, and error streams

Using the generic ARM C library, the standard input, output and error streams can be redirected at runtime. For example, if mycopy is a program running on a host debugger that copies the standard input to the standard output, the following line runs the program:
mycopy < infile > outfile 2> errfile
and redirects the files as follows:
stdin
The standard input stream is redirected to infile.
stdout
The standard output stream is redirected to outfile.
stderr
The standard error stream is redirected to errfile.
The permitted redirections are:
0< filename
Reads stdin from filename.
< filename
Reads stdin from filename.
1> filename
Writes stdout to filename.
> filename
Writes stdout to filename.
2> filename
Writes stderr to filename.
2>&1
Writes stderr to the same place as stdout.
>& file
Writes both stdout and stderr to filename.
>> filename
Appends stdout to filename.
>>& filename
Appends both stdout and stderr to filename.
To redirect stdin, stdout, and stderr on the target, you must define:
#pragma import(_main_redirection)
File redirection is done only if either:
  • The invoking operating system supports it.
  • The program reads and writes characters and has not replaced the C library functions fputc() and fgetc().
Non-ConfidentialPDF file icon PDF versionARM DUI0375H
Copyright © 2007, 2008, 2011, 2012, 2014-2016 ARM. All rights reserved. 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.