Ecere SDK/eC Forums • View topic - An enum in place of an int




Ecere SDK/eC Forums

Ecere Developers Community

An enum in place of an int

General help: new users, installing the Ecere SDK, using the IDE to compile and run applications.

An enum in place of an int

Postby pber » Tue Oct 21, 2014 5:55 pm

Hi Jerome,
can I use an enum value where an int was expected?

Having:
enum DataType { t1, t2 };

and a class
class Data { int type; }

I can not assign t1 to the type field of an instance of Data.

enum DataType : int { t1, t2 };
does not help.

PS
...did I ever said eC is great?

paolo
pber
 
Posts: 17
Joined: Mon Aug 18, 2014 2:09 am

Re: An enum in place of an int

Postby jerome » Tue Oct 21, 2014 6:45 pm

Hi Paolo,

Enumerated values will not resolve unless you assign them to an int, they're only visible where their enumeration type is expected. That allows you to have the same enumerated values in different enums (e.g. 'none')
If you really want to assign it to an int, you can do:

type = DataType::t1;

or even:

type = (DataType)t1;

Yes you did :) Thanks! ;)

How are your eC projects going? Anything interesting to talk about and share with our small community? :)

-Jerome
jerome
Site Admin
 
Posts: 622
Joined: Sat Jan 16, 2010 11:16 pm

Re: An enum in place of an int

Postby pber » Tue Oct 21, 2014 7:33 pm

Hi Jerome,
thanks for the hints.

In a few days I'll start to publish my toy-project.
At now it is able to parse many constructs of an esotic AL (abstract language),
more or less eC :roll: (without parametric classes).

the parser is a hand-written discent parser. And it's still too incomplete to be able to measure
its speed with a large code base.

A small (and ridicoulously incomplete) VM is already able to perform this:
int c; for(c=0; c<1E6; c++);
in 60 msecs.
Not a record, but it sounds a miracle to me!

Today I started the second part (of three) of the game, the QL (query language).
It's a lisp-like syntax with which express matching and replacement rules to query
and transform the AST.

I'm quite happy of the work done till now (even if my code and design is still orrible).
Now I try to understand how to upload to github...
pber
 
Posts: 17
Joined: Mon Aug 18, 2014 2:09 am

Re: An enum in place of an int

Postby jerome » Tue Oct 21, 2014 8:18 pm

Cool :)

Had you taken a look at my own attempt at a RD parser for eC?

https://github.com/ecere/ecere-sdk/tree ... ler/libec2

It is mostly working, just a few language features were missing. I just haven't had time to complete it and make it work together with everything else yet!

-Jerome
jerome
Site Admin
 
Posts: 622
Joined: Sat Jan 16, 2010 11:16 pm

Re: An enum in place of an int

Postby pber » Tue Oct 21, 2014 9:25 pm

Your code is always very clean,
so that everything seems so simple in eC...
I got some errors in ec2 / ASTList (some weeks ago I remember I tried to fix them,
maybe now I could be more happy).
pber
 
Posts: 17
Joined: Mon Aug 18, 2014 2:09 am


Return to General Help

Who is online

Users browsing this forum: No registered users and 1 guest

cron