Skip to content

ncgen behaviour does not match CDL spec for unsigned suffix orderings #3188

@jatkinson1000

Description

@jatkinson1000

Version:

netcdf library version 4.9.3 of Feb  7 2025 21:40:00

Environment:
M2 Mac running macOS 15.7.1
NetCDF installed via homebrew and from source using CMake

From the CDL specification:

Unsigned integer constants can be created by appending the character ‘U’ or ‘u’ between the constant and any trailing size specifier, or immediately at the end of the size specifier. Thus one could say “10U”, “100su”, “100000ul”, or “1000000llu”, for example.

However, it seems that ncgen does not, in fact, allow the u to come after the size-specifier as the following (slightly more than) MWE shows:

netcdf u_size_suff_test {
dimensions:
        dim = 4 ;
variables:
        ushort ushort_arr(dim) ;
                ushort_arr:ok_att = 14US ;
                // ushort_arr:forbidden_att = 16SU ;
        ubyte ubyte_arr(dim) ;
                ubyte_arr:ok_att = 18UB ;
                // ubyte_arr:forbidden_att = 20BU ;
        uint64 uint64_arr(dim) ;
                ubyte_arr:ok_att = 18ULL ;
                // ubyte_arr:forbidden_att = 20LLU ;
data:

 ubyte_arr = 1ub, 2ub, 3ub, 4ub ;

 //ubyte_arr = 1bu, 2bu, 3bu, 4bu ; // We cannot do this

 ushort_arr = 1us, 2us, 3us, 4us ;

 //ushort_arr = 1su, 2su, 3su, 4su ; // We cannot do this

 uint64_arr = 1ul, 2ull, 3ull, 4ull ;

 //uint64_arr = 1llu, 2llu, 3llu, 4llu ; // We cannot do this
}

I believe I have narrowed it down to the regex match in the lexer and will try and open a fixing PR in due course for your consideration.


Side note: I realise the data assignments don't really need suffixes on the types - presumably ncgen, ncdump etc. infers the type based on the variable type declaration and forcibly casts.
This does allow the revolting interesting behaviour whereby we can declare:

 ubyte_arr = 1ub, 2us, 3ul, 4.0E0 ;

and it all gets parsed through ncgen to ubytes and dumped as:

 ubyte_arr = 1, 2, 3, 4 ;

🤣 :trollface:

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