Author Topic: Allow compile time variables (Part of macro proposal)  (Read 7671 times)

lerno

  • Full Member
  • ***
  • Posts: 247
    • View Profile
Allow compile time variables (Part of macro proposal)
« on: November 16, 2018, 11:31:12 AM »
I suggest the introduction of macro compile time variables, prefixed with the sigil $. These can only hold compile time values and are evaluated top down.

This is a variant of what already exists in C, but in a syntactically more friendly way.

For example this would be ok:

Code: [Select]
macro swap(a, b) {
  $x = typeof(a);
  static_assert(typeof(b) == $x);
  $x temp = a;
  a = b;
  b = a;
}

The example above is a bit contrived as in the above example we could simply have:

Code: [Select]
macro swap(a, b) {
  static_assert(typeof(b) == typeof(b));
  typeof(a) temp = a;
  a = b;
  b = a;
}

But still, it serves as an example on how to use it.