racer home

Onyx versus C++ - differences

 

Home Extend beyond the boundaries.


Dolphinity Organiser - free planning, project management and organizing software for all your action lists

Introduction

Onyx is a language that looks a lot like just-in-time compiled C++. That is one goal, since it makes writing code familiar to using basic C++ syntax. However, there are some differences that may be pitfalls if you're not aware of them.

Here are a number of key differences which are good to know.

The '$' keyword

This token is really a keyword which ends compilation. Especially for small test scripts, this may be more useful than embedding pieces of code between #ifdef/#endif pairs.

Consider this example:

float f;

void main()
{
  f=123;
  echo(f);
}

$ // end compilation

f=f+1;
echo(f);   // We'll never get here
bla bla;    // A syntax error

$

// more code...

The script above will compile upto the line with the dollar sign, but will not see 'f=f+1'. It will stop compiling, so syntax errors and such in the rest of the code will not be found.

 

Modulo with floats (and negative numbers)

In C++, you can use expressions such as 5%3. In Onyx, this also works for floats.

Here is an example:

float f;

void main()
{
  echo(-7.0%3.0);
  echo(7.0%-3.0);
  echo(-7%3);
  echo(7%-3);
}

The script prints:

-1.000000
1.000000
-1 1

The example uses negative numbers to demonstrate the behavior used, which is compliant with C++'s fmod(). Not so long ago, this behavior was implementation dependent in C++ (!).

 


Dolphinity Organiser - free planning, project management and organizing software for all your action lists

(last updated March 14, 2014 )