Skip to content

ASN.1 definitions with C reserved words cause faulty generated code #357

Description

@swthorn

Hi,

first of all, very cool project. Some ASN.1 specifications define reserved words as part of an enum. e.g, this is from cellular network specs (RRC):

TimingMaintainedSynchInd ::= ENUMERATED { false }

This generates code with asn1scc --field-prefix AUTO that looks something like this:

typedef enum {
    false = 0
} TimingMaintainedSynchInd;

If you try to compile this, you'll get an error like this:

file.c:11:
file.h:1312:5: error: expected identifier
 1312 |     false = 0
      |     ^
/usr/lib/llvm-17/lib/clang/17/include/stdbool.h:22:15: note: expanded from macro 'false'
   22 | #define false 0
      |               ^
In file included from /data/asn1scc_DL-DataToUL-ACK-DCI-1-2-r17_uper.c:12:
file.h:1312:5: error: expected identifier

I think this issue may expand to other named values in enums that are reserved words, but I did not test. I suggest making the field prefix CLI argument also prefix enum values to resolve the issue, but this may cause backward compatibility problems.

The full list of reserved words for C is here: https://en.cppreference.com/w/c/keyword.html

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions