Const keyword not recognized by MonkeyC

278 Views Asked by At

I am building project in monkeyc (ConnectIq) from Garmin in Eclipse, and I want to use const instead of var in my code, but it seems that the const keyword is not recognized by the compiler. What could be wrong?

My code is:

const PI = 3.14;

Compiler complain like this:

BUILD: ERROR: C:\Path:155  missing '}' at 'const'

If I change const to var, everything goes well. Where can be a problem? From Garmin documentation MonkeyC should haveconst keyword.

2

There are 2 best solutions below

0
On BEST ANSWER

I realized that const keyword cannot be inside a function, it has to be as a class variable. Then it works. I just do not know if it is a bug or a feature.

0
On

It is neither a bug nor a feature, it is just the way that the language is implemented. The Programmer's Guide explicitly says

Constants are named, immutable values declared with the const keyword. These are useful for storing unchanging values that may be used repeatedly throughout code. Constants must be declared at the module or class level; they cannot be declared within a function.