ASN.1/C++ Compiler Overview

Applies to: ASN.1/C++ 6.5

Using the Command Line

  • Compiler command-line options are prefixed by a dash ("-"). They can be shortened to the fewest number of characters needed to differentiate them from other keywords.
  • Command-line options are not case-sensitive; they can be specified in all uppercase, all lowercase, or mixed case.
  • If two command-line options contradict each other (for example, both -headerFile and -noHeaderFile are specified), the rightmost option is used.
  • Some keywords accept operands; keyword operands are not prefixed with a dash.
  • For those command-line options that accept a filename operand, such as -listingFile, -modListingFile, and -output, specifying a filename operand of only a dash ("–") will cause the output to be written to the standard output.

NOTE: The OSS ASN.1 Compiler generates the Time-Optimized Encoder/Decoder (TOED) by default. Prior to version 5.0, the Space Optimized Control File (SOED) was generated instead. The following command lines are equivalent:

asn1cpp -toed

Example Compiler Invocations

  • The following command lines will both compile the contents of input1.asn, but specify the input filename differently. The second command line assumes the default .asn file extension.
    asn1cpp input1.asn
    asn1cpp input1
  • These command lines use the -noWarning option to suppress all warning messages when compiling the contents of input1.asn. Both assume the default .asn file extension. The second command line uses an abbreviated form of the ‑noWarning option.
    asn1cpp input1 -noWarning
    asn1cpp input1 -now
  • These command lines show two ways to specify the -listingFile option. After compiling the contents of input1.asn and input2.asn, the first command line creates the input2.lst output listing file; the second command line creates the myFile.lst output listing file. By default, output filenames are derived from the last input filename, as in the first command line. The last entry on the second command line, myFile, is not prefixed with a dash ("-") because it is an operand to the -listingFile keyword before it.
    asn1cpp input1 input2 –listingFile
    asn1cpp input1 input2 -listingFile myFile

Specifying Input Filenames

When you specify input filenames on the command line, consider the following:

  • Input filenames cannot start with a dash ("-") and cannot be operands of keyword options.
  • The default file extension for input files is .asn. If the filename lacks an extension, the .asn extension is added before opening the file. To specify a filename without an extension, add a period (".") to the end of the filename. To specify filenames containing spaces, enclose the filename in quotation marks, for example, "my syntax definitions.asn".
  • When a dash ("-") is used as a filename operand, the compiler output is written to the standard output device.
  • When specified, the asn1dflt.* cross-compile configuration file must be the first item on the command line.
  • A file that contains macro definitions must be specified before any file that references those definitions.
  • Like most computer language compilers, the OSS ASN.1/C++ compiler expects input files to be plain text files (ASCII or UNICODE).

Using ASN.1 Studio®

With ASN.1 Studio's intuitive user interface you can easily check any ASN.1 syntax, as well as create, edit, and view ASN.1 messages.

You can generate C++ code from the input ASN.1 syntax and add your own code that implements your application's business logic. Then you can export your ASN.1 Studio project to an ASN.1 compiler command-line file, a Visual Studio project, a makefile, or a shell script.

For details on working with ASN.1 Studio, see the Welcome page that opens when ASN.1 Studio is launched. There you'll find links to the most frequently used ASN.1 Studio Help pages, sample projects, project management operations, and to various online resources.

Compiler Restrictions

ASN.1 Input

Line Size

The maximum number of bytes in a single line of input is 4096.

Token Item Size

1024 bytes is the maximum size of an input item such as an identifier; a type, value, or module reference; a binary string; a character string; or a hexidecimal string.


To enable support for INTEGERs having a maximum size of 4096 bytes, use the ASN1.HugeInteger or OSS.HUGE directive. Otherwise, an integer can be 2, 4, or 8 bytes long.

INTEGER Range Constraint

The OSS ASN.1 compiler interprets MAX or MIN in a constraint on an INTEGER type as the maximum or minimum value of an int in C++, which is a 4-byte integer on most machines. To extend an integer into an 8-byte integer range, specify the actual values in the constraint rather than MAX or MIN, as shown by C in the following example:

A ::= INTEGER (0..MAX)            -- this will become an unsigned int
B ::= INTEGER (MIN..30)           -- this will become an int
C ::= INTEGER (-1..3422147483647) -- this will become a long long

Special REAL Values

If the input ASN.1 uses REAL types and contains value notation with special REAL values, such as NOT-A-NUMBER or -0, then the code generated by the ASN.1/C++ compiler is not C++ compilable.

REAL Range Constraint

The ASN.1 Compiler supports the syntax of an open-ended value range constraint using the less than sign ("<") on REAL types. However, the runtime libraries will not enforce these constraints; any less than signs are ignored. If the open-ended constraint must be enforced use the EXCEPT clause to do so.

For example, change

A ::= REAL (0<..MAX)
B ::= REAL (100<..<1000)


A ::= REAL ((0..MAX) EXCEPT 0)
B ::= REAL ((100<..<1000) EXCEPT (100 | 1000))

-genDirectives Compiler Option

When the –gendirectives option is used, the compiler does not generate the ASN1.Nickname or OSS.TYPENAME directive for mangled names in internal OSS type definitions, such as ObjectID, External, EmbeddedPDV, ABSTRACT_SYNTAX, and TYPE-IDENTIFIER.

↩Compiler Restrictions

Time-Optimized Encoder/Decoder (TOED)

Length Forms of BER Encodings

The Time-Optimized encoder supports only the definite length form of BER encodings. On the other hand, the Time-Optimized decoder supports all valid BER encodings, including those in the indefinite length form.

Canonical Encoding Rules

The Time-Optimized Encoder/Decoder does not support the Canonical Encoding Rules (CER); the –cer option can only be used with the -soed option.

Pattern Constraints

The Time-Optimized Encoder/Decoder does not check pattern constraints.

Preprocessor Macros

When C++-compiling generated TOED code, you can set C++ preprocessor macros to enable or disable various features in the result. By default, only encoding and decoding functions will be present in the compiled code. See C++ Compiler Macros to Optimize Size and Speed when Using the TOED for details.

See Also

Runtime Restrictions: Time-Optimized Encoder/Decoder

↩Compiler Restrictions

Lean Encoder/Decoder (LED)

C++ Representations

Except for REAL and UTF8String, all ASN.1 types have only one C++ representation, unless the –soed option is specified.

The REAL type is represented as a double by default. You can change its representation to OssDecimal by applying the OSS.DECIMAL directive.

ASN.1 C++
Length1 ::= REAL
Length2 ::= REAL --<DECIMAL>--
typedef double Length1;
typedef OssDecimal Length2;

The UTF8String type can be represented as an OssString (default), an OssBMPString, or as an OssUniversalString. To obtain the OssBMPString representation, use the OSS.BMPSTRING directive; for the OssUniversalString representation, use the OSS.UNIVERSALSTRING directive.

ASN.1 C++
Name1 ::= UTF8String
Name2 ::= UTF8String --<UNIVERSALSTRING>--
Name3 ::= UTF8String --<BMPSTRING>--
typedef OssString Name1;
typedef OssUniversalString Name2;
typedef OssBMPString Name3;

Length Forms of BER Encodings

The Lean encoder supports only the DEFINITE length form of BER encodings. On the other hand, the Lean decoder supports all valid BER encodings, including those that are in the INDEFINITE form.

Compiler Directives

The ASN.1 compiler does not accept the OSS.INT, OSS.LONG, or OSS.SHORT compiler directives when -lean is specified. These directives are accepted when –soed is used.

Canonical Encoding Rules

The Lean Encoder/Decoder does not support the Canonical Encoding Rules (CER); the –cer option can be used only with the –soed option.

See Also

Runtime Restrictions: Lean Encoder/Decoder

↩Compiler Restrictions

XML Encoding Rules (XER/CXER/E-XER)

The XER/CXER/E-XER encoder/decoder does not support

  • Forward referenced component relation constraints
  • The ASN1.DeferDecoding compiler directive

↩Compiler Restrictions

Octet Encoding Rules / Canonical Octet Encoding Rules (OER/C-OER)

The OER/C-OER encoder/decoder does not support the ASN1.DeferDecoding compiler directive.

↩Compiler Restrictions

This documentation applies to release 6.5 and later of the OSS® ASN.1 Tools for C++.

Copyright © 2017 OSS Nokalva, Inc. All rights reserved.
No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means electronic, mechanical, photocopying, recording or otherwise, without the prior permission of OSS Nokalva, Inc.
Every distributed copy of the OSS® ASN.1 Tools for C++ is associated with a specific license and related unique license number. That license determines, among other things, what functions of the OSS ASN.1 Tools for C++ are available to you.