TOP

ASN.1/C Compiler Overview

Applies to: ASN.1/C v11.3-11.3.1

Before you start compiling your applications using the OSS ASN.1 command-line compiler or ASN.1 Studio, it's important to understand the following topics:

Using the ASN.1/C compiler

Invoking the command-line compiler

Compiler command-line options begin with a dash ("-"). Options are not case-sensitive and you can use mixed case; however, the specified name must be different from the name of the option. Note that if two command-line options contradict each other (for example, if -headerFile and -noHeaderFile are both present), the compiler will use the last option specified.

NOTE: Starting with version 9.0, by default, the OSS ASN.1 compiler generates TOED files instead of SOED files. The following command lines are equivalent:

asn1

asn1 -toed

The examples below show alternative ways to invoke the compiler:

  • Specifying the input filename:
    1. asn1 input1.asn
    2. asn1 input1
  • Specifying the -noWarning command-line option:
    1. asn1 input1 -noWarning
    2. asn1 input1 -now

In this example, the second invocation assumes the default file extension .asn and uses an abbreviated form of the command-line option.

  • Specifying the command-line option to produce an output listing file:
    1. asn1 input1 input2 -listingFile
    2. asn1 input1 input2 -listingFile myFile

In this example, the first invocation creates an output listing filename input2.lst after compiling the contents of input1.asn and input2.asn. By default, output filenames are derived from the last input filename. The second invocation creates an output listing filenamed myFile.lst after compiling the contents of input1.asn and input2.asn. Note that the last command-line option, myFile, does not start with a dash ("-") because it is the operand of the -listingFile option which precedes it.

Certain keywords accept operands; however, keyword operands cannot start with a dash.

Specifying input filenames

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

  • Input filenames cannot start with a "-" and cannot be operands of keyword options.
  • The default file extension for input files is .asn. If the filename contains no extension, an .asn extension is added before opening the file. To specify a filename without an extension, add a period (".") at the end of the filename. Also, to specify filenames which contain embedded whitespace, enclose the filename in quotation marks, for example, "my syntax definitions.asn".
  • A dash specified as a filename operand causes the output to be written to the standard output.
  • When included, the cross-compiling configuration file (asn1dflt.*) must be the first item on the command line.
  • A file that contains macro definitions must be specified prior to any files that reference them.
  • Similar to most language compilers, the OSS ASN.1 compiler requires a specific format for the input files, namely plain text files (ASCII or UNICODE).

Using ASN.1 Studio

With ASN.1 Studio you can easily check any ASN.1 syntax, create, edit, and view ASN.1 messages using its intuitive user interface.

You can generate C code from the input ASN.1 syntax and add your own code that implements your application 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 a detailed description about how to work with ASN.1 Studio, see the Welcome page that appears when ASN.1 Studio is launched. The page includes links for easy access to the most frequently used ASN.1 Studio Help pages, sample projects, project management operations, and to various online resources.

Compiler Restrictions

The following restrictions apply to the ASN.1 input:

Line Size

The maximum number of bytes in a line of an ASN.1 input file is 4096.

Token Item Size

The maximum number of bytes in an input item (an identifier, a type, value, or module reference, a bstring, a cstring or a hstring) is 1024.

INTEGER Size

To enable support for INTEGERs that have a maximum size of 4096 bytes, you must use the ASN1.HugeInteger or OSS.HUGE directive. Depending on the platform, the size of an INTEGER is 2, 4, or 8 bytes.

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 for the target platform, 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 using MAX or MIN. For 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

REAL Range Constraint

Although the ASN.1 compiler supports the syntax of open ended value range constraint on REAL types, the runtime libraries will not enforce open ended value range constraints using the less than sign ("<") on REAL types. The less than sign is ignored.

To enable support for open ended constraints, use the EXCEPT clause. For example:

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

Can be:

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

ASN.1 Value Notation Encoding Rules (AVN)

ASN.1 Value Notation encoding rules (AVN) are currently supported by the TOED runtime only. The -avn compiler option is not compatible with the -soed option.


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

Copyright © 2024 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.