Skip to content
Snippets Groups Projects
  • Per Hedbor's avatar
    0ad650bf
    Added a two new operators: "?->" and "?:" · 0ad650bf
    Per Hedbor authored
    ?-> can be used to index something that is either indexable or null.
    ?: is an alias for ||
    
    Very useful for things like:
    
    C c = a && a->b && a->b->c;
    
    which can now be rewritten as
    
    C c = a?->b?->c;
    
    The code in language.yacc also supports ?. and ?[], but there are
    syntax conflicts with ?: for those:
    
    ?. conflicts with expr?.Module:...
    ?[] conflicts wtih expr?[softcast]:...
    
    ?: was added mostly to be compatible with other 'modern' C-like
    languages.
    0ad650bf
    History
    Added a two new operators: "?->" and "?:"
    Per Hedbor authored
    ?-> can be used to index something that is either indexable or null.
    ?: is an alias for ||
    
    Very useful for things like:
    
    C c = a && a->b && a->b->c;
    
    which can now be rewritten as
    
    C c = a?->b?->c;
    
    The code in language.yacc also supports ?. and ?[], but there are
    syntax conflicts with ?: for those:
    
    ?. conflicts with expr?.Module:...
    ?[] conflicts wtih expr?[softcast]:...
    
    ?: was added mostly to be compatible with other 'modern' C-like
    languages.