enums

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

enums

Lance Dillon-2
What would be the best way to represent enums?  It has been a while since I wrote pike code, so I'm looking in the docs and can't see anything.  Maybe just a bunch of constants?  Or maybe a class (or struct)?

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: enums

Stanislaw Klekot
On Thu, Feb 04, 2021 at 01:08:56PM +0000, Lance Dillon wrote:
> What would be the best way to represent enums?  It has been a while since I wrote pike code, so I'm looking in the docs and can't see anything.  Maybe just a bunch of constants?  Or maybe a class (or struct)?

I think the best enum representation would be just enum.

#v+
enum foo_t { ONE = 0, TWO = 1, THREE = 2 };

foo_t nabla = ONE;

write("ONE + TWO = THREE\n%d + %d = %d\n", ONE, TWO, THREE);
#v-

--
Stanislaw Klekot
Reply | Threaded
Open this post in threaded view
|

Re: enums

Lance Dillon-2
Ah, I was trying to search for enum in the pike docs, but nothing showed up on the web page.  I'll have to try to search further and see where it is located.

Thanks

On Thursday, February 4, 2021, 11:02:12 AM EST, Stanislaw Klekot <[hidden email]> wrote:


On Thu, Feb 04, 2021 at 01:08:56PM +0000, Lance Dillon wrote:

> What would be the best way to represent enums?  It has been a while since I wrote pike code, so I'm looking in the docs and can't see anything.  Maybe just a bunch of constants?  Or maybe a class (or struct)?


I think the best enum representation would be just enum.

#v+
enum foo_t { ONE = 0, TWO = 1, THREE = 2 };

foo_t nabla = ONE;

write("ONE + TWO = THREE\n%d + %d = %d\n", ONE, TWO, THREE);
#v-

--
Stanislaw Klekot