POV-Ray : Newsgroups : povray.programming : enum { SOMETHING = 'Thing' } ? Server Time
3 Jul 2024 05:29:33 EDT (-0400)
  enum { SOMETHING = 'Thing' } ? (Message 11 to 13 of 13)  
<<< Previous 10 Messages Goto Initial 10 Messages
From: Thorsten Froehlich
Subject: Re: enum { SOMETHING = 'Thing' } ?
Date: 5 Feb 2004 07:59:11
Message: <40223e1f@news.povray.org>
In article <402230f2$1@news.povray.org> , "AngleWyrm" 
<no_### [at] hotmailcom> wrote:

> * I've overlooked something totally obvious, and should go get another cup
> of coffee

Bingo! ;-)  If you want to create programs that can exchange data including
enumerations, you absolutely have to assign each enumeration a distinct
value.  Otherwise all programs would have to be updated each time
enumeration value if added or removed.  The one kind of value that is on the
one hand easy to read when debugging, and on the other hand will result in a
fairly unique enumeration value is a four character constant.  That is also
why you find them used in many operating system programming interfaces.

    Thorsten

____________________________________________________
Thorsten Froehlich, Duisburg, Germany
e-mail: tho### [at] trfde

Visit POV-Ray on the web: http://mac.povray.org


Post a reply to this message

From: AngleWyrm
Subject: Re: enum { SOMETHING = 'Thing' } ?
Date: 6 Feb 2004 04:56:11
Message: <402364bb$1@news.povray.org>
"Thorsten Froehlich" <tho### [at] trfde> wrote in message
news:40223cef$1@news.povray.org...
> In article <40222523@news.povray.org> , "AngleWyrm"
> <no_### [at] hotmailcom> wrote:
>
> > If the enums were given specific values,
>> it was my guess that at some point in the program
>> a comparison to, or usage of those specific values would take place.
>> Makes sense?

> No, nobody would define enums and then not use them.
Have you seen these enum values used somewhere?
This is what I have gone looking, and haven't found them used anywhere.

> Enums are given "names" because those mean more to a human when debugging.
Doesn't your debugger display enums directly?
enum CRITTERS {CAT, DOG, MOUSE};
CRITTERS animal = CAT;
debugger says:" animal = CAT " which is plenty clear enough.
And this works for any external program that uses the header file in which
the enum is defined.

What is gained by saying the variable 'animal', which has a value of CAT,
also has a numerical value that can be translated to 'cat'?


Post a reply to this message

From: Thorsten Froehlich
Subject: Re: enum { SOMETHING = 'Thing' } ?
Date: 6 Feb 2004 08:13:45
Message: <40239309@news.povray.org>
In article <402364bb$1@news.povray.org> , "AngleWyrm" 
<no_### [at] hotmailcom> wrote:

>> No, nobody would define enums and then not use them.
>
> Have you seen these enum values used somewhere?
> This is what I have gone looking, and haven't found them used anywhere.

Well, as has been pointed out, you have to search for the enum names, not
their values.  As they are used by POVMS messages, look into the code
sending and receiving POVMS messages.

>> Enums are given "names" because those mean more to a human when debugging.
>
> Doesn't your debugger display enums directly?

Most high-level debbuggers do display enums directly, yes.  However,
low-level debuggers don't, and neither do queue/network loggers.  Thus, if
doing IPC, you quickly learn to appreciate being able to read what is going
on.

> enum CRITTERS {CAT, DOG, MOUSE};
> CRITTERS animal = CAT;
> debugger says:" animal = CAT " which is plenty clear enough.
> And this works for any external program that uses the header file in which
> the enum is defined.

Yes, but is does not work well if you ever want to *extend* the enum.  You
quickly end up with hard to find bugs or having to recompile all external
programs every time some extension is made, even if that extension is not
used by the external program at all.

> What is gained by saying the variable 'animal', which has a value of CAT,
> also has a numerical value that can be translated to 'cat'?

See what I outlined above.

    Thorsten

____________________________________________________
Thorsten Froehlich, Duisburg, Germany
e-mail: tho### [at] trfde

Visit POV-Ray on the web: http://mac.povray.org


Post a reply to this message

<<< Previous 10 Messages Goto Initial 10 Messages

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.