May 20, 2024, 06:18:16 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


ENUM defaults

Started by Earn, August 26, 2008, 10:56:05 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Earn

Shouldn't the default value of the first enumerator be 0 rather than 1?
ENUM test
t0
t1
t2
t3
t4
ENDENUM

OPENCONSOLE

PRINT t0, t1, ,t2, t3, t4

PRINT "Press Any Key"
DO:UNTIL INKEY$<>""
CLOSECONSOLE
END

Earn

Rock Ridge Farm (Larry)

I believe that most basic type languages start with 1.
I think starting with 0 is a 'C' concept.
Could be wrong - would not be the first time.

ts-soft

Use it in this way:
ENUM test
t0 = 0
t1
t2
t3
t4
ENDENUM

OPENCONSOLE

PRINT t0, t1, ,t2, t3, t4

PRINT "Press Any Key"
DO:UNTIL INKEY$<>""
CLOSECONSOLE
END

IMHO normal was beginning with 0

greetings
Thomas
Sorry for my bad english

Earn

Apparently Microsoft defaults it to 0 as it was an MS header I was converting when I came across the problem.  Couldn't find ENUM documented in the EB manual so I assumed ( ohh! That got me again) that the default index would be the same.
Earn

LarryMc

Quote from: Earn on August 26, 2008, 01:31:25 PM
  Couldn't find ENUM documented in the EB manual...
You're correct but there is an example called enum.eba that may or may not have helped you.

This from the version announcement is a dead giveaway.:
QuoteCode:
ENUM days
monday
tuesday
wednesday
thursday
friday
saturday
sunday
ENDENUM

Would create a typedef named 'days' which is an INT and seven constants sequentially numbered from one.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Ionic Wind Support Team

It will be updated in the users guide when I get the chance.  Usually full updates are done with point releases, I just neglected to put the keywords in the alphabetical reference.

As for the default...it matches Aurora.  And I prefer it to start at 1 because I used it for control constants.
Ionic Wind Support Team

Peter

Wouldn't it be simple enough (although I don't know exactly how this is coded thus I might be wrong) to just add an option to enum?
The TYPE-statement has a perfect param, and this:

ENUM Days, 0

... would be an excellent way to choose which number to start from. If needed, even the STEP function could be useful.

Just a thought...

LarryMc

Quote from: Peter on August 27, 2008, 02:01:26 AM

ENUM Days, 0

... would be an excellent way to choose which number to start from.

Again, from the example file, enum.eba:ENUM days
Monday=3
Tuesday
Wednesday
Thursday
Friday
Saturday
Sunday
ENDENUM
print Monday

results in a 3
if you change it to Monday=0 then print Monday results in 0.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Ionic Wind Support Team

Larry, you are correct, there isn't a single "default" with enumerations.  You can use it the same way C does and specify multiple starting points, such as different messages and control identifiers:

ENUM ids
b_cancel
b_ok
m_open = 100
m_save
m_options
m_quit
m_cut = 200
m_copy
m_paste
m_search
ENDENUM

Paul.
Ionic Wind Support Team

LarryMc

didn't realize you could have that 2nd starting point in there.  That's neat!

So why would I want to use a bunch of const instead of using enum.

It appears this would solve what I have always seen as an aggravation of having a list of constants as control ID's or menu IDs and then needing to insert a new one and renumbering from there down.

Can I use the enum's exactly like const; in include files in multiple source files of a project?

What's the drawback, if any?

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Ionic Wind Support Team

Yes, they are constants, and yes you can use them from an include.  They are just a compiler construct to make life easier.

You don't even need to use the automatic numbering and specify a value for each constant, which just saves having to type CONST or $define over and over.

Paul.
Ionic Wind Support Team

LarryMc

I like it; I like it!

Thanks

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library