Submitted by Gabriël Konat on 31 May 2013 at 12:09

On 1 June 2013 at 12:23 Daco Harkes commented:

C with const variables seems to have multiple problems. Do we want to support this const syntax and simply convert it to c and let the compiler deal with this? Or do we want provide a different means of const variables?


On 1 June 2013 at 12:43 Gabriël Konat commented:

The link you sent is for C++, not C, so it does not apply. Const variables are used to indicate that a variable may not be assigned. This is done to prevent accidental assignments to variables that should not change, and to assist the compiler in optimisation. I think it’s an important feature that should be supported. Syntax wise it’s pretty simple, just add const in front of a variable. It has some implications on the type system and requires an additional constraint check to prevent assignment to const variables.


On 1 June 2013 at 12:45 Daco Harkes commented:

So const is just a simple modifier like volatile.

Than the plan is simple

  1. add to syntax
  2. add to transformation
  3. add type check constraint

On 1 June 2013 at 12:51 Gabriël Konat commented:

Yes, but it does change the type of a variable from just int to const int, the type system has to be changed to support this. It also affects type equality, e.g. is a const volatile int type equal to int?


On 1 June 2013 at 13:14 Daco Harkes commented:

Shouldn’t these modifiers not be a property of a type instead of a type itself?


On 1 June 2013 at 13:23 Gabriël Konat commented:

No they are actually a new type. A property of a type for example is the size of that type. For an int8 this is 1 byte and is true for the entire program. However, if you declare a const int i it does not mean that all int types in the entire program are now const. int and const int are two different types.

You can represent this in the type system as a list of modifiers: int8: Type([], Int8()), const int8: Type([Const()], Int8()), etc.


On 6 June 2013 at 08:42 Dario Nesi commented:

syntax updated


On 6 June 2013 at 15:43 Daco Harkes commented:

Implemented and mapping to base-c implemented. Type-checking and mapping from Statemachine pending (other issues).


On 6 June 2013 at 15:43 Daco Harkes closed this issue.

Log in to post comments