comp.lang.ada
 help / color / mirror / Atom feed
From: wojtek@power.com.pl (Wojtek Narczynski)
Subject: Constants instead of enum?
Date: 18 Dec 2002 07:03:21 -0800
Date: 2002-12-18T15:03:21+00:00	[thread overview]
Message-ID: <5ad0dd8a.0212180703.71f5b6b7@posting.google.com> (raw)

Hello,

I have the following situation: I read request record from network, an
Unsigned_8 (byte) denotes its type. Valid types are 1..10. Response
record has the same structure as request record. I also want to reuse
the memory allocated for request as the response. Now problem: for
every unimplemented request type (outside 1..10 range) I am supposed
to send a response record with type 11 back.

I am trying to use enumeration with representation clause for this,
but it just doesn't work. I read an Unsigned_8 from network, and all
its values are valid and should be handled gracefully, so I cannot use
this enum in the request structure. Because of this I have to convert
from Unsigned_8 to enumeration, but only sometimes. Then I have to use
unchecked conversion to get the enumeration's underlying Unsigned_8 to
store it in the response record (same structure and memory) as
request, so it has to be Unsigned_8.

If I defined types as constants for 1..11 range the amount of code
necessary and conversions will reduce.

So my question is - would this be fine to use a group of consts in
this specific case instead of an enum? I could encapsulate them into a
nested package.


Thanks,
Wojtek



             reply	other threads:[~2002-12-18 15:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-12-18 15:03 Wojtek Narczynski [this message]
2002-12-18 16:36 ` Constants instead of enum? John McCabe
2002-12-18 17:52 ` Robert A Duff
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox