Skip to content

flag data type #474

Closed
Closed
@PavelVozenilek

Description

@PavelVozenilek

This is suggestion for minor feature - boolean like data type with restrictions.

  1. flag can be local variable in a function or member of a struct, or item in array, but not function parameter.

  2. flag has to be initialized by true or false and the value has to be known at compile time.

    var x : flag = false;

  3. flag can be assigned only to negation of initial value, also has to be known at compile time.

    if (...) x = true;

  4. flag can be compared with bool, converted to bool in assignment or passed to bool function parameter.

  5. address of flag variable cannot be taken. This protects against unchecked change and also allows the compiler to reduce used memory to 1 bit when member of a struct.

What is it good for?

  1. Using flag instead of bool makes intent slightly more explicit.
  2. Forbids misuse of variable intended as flag as free-for-anything.
  3. Low cognitive overhead - no special syntactic forms are used, just one word gets replaced, with no other changes in the code.
  4. Flag arrays can be compressed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementSolving this issue will likely involve adding new logic or components to the codebase.proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions