Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating 1 byte enum 2

Status
Not open for further replies.

ErrorLINE1CHAR1

Programmer
Dec 3, 2010
24
US
I need help turning the following into a 1 byte enum if possible, if its not could you please explain why not..

(
all original names have been omitted but the strings: _zz1, _zz2, _blank, none = 0xFF
)

I have already completed my program, BUT i can add a whole new section to it if i can get this into a 1 byte enum...

Code:
[purple]enum[/purple] CHARID [blue]{[/blue]

	Name1,
	Name2,
	Name3,
	Name4,
	Name5,
	Name6,
	Name7,
	Name8,
	Name9,
	_zz1,
	_zz2,
	_blank,
	Name10,
	Name11,
	Name12,
	Name13,
	None = 0xFF
};

I'm confused with how to do enum's i read a tutorial but I cant find any thing for my part where None = 0xFF (affraid that will throw a error, but i cant get this to where I need so i cant test that..)
Do I need to:

#define Name1 0
#define Name2 1
... etc


and for the 'None' do:

#define None

[purple]int[/purple] [red]0xFF[/red] = None;

instead of 'None = 0xFF' inside the enum??


Will credit in source for your help!!
-DEVON

Devon
Intel Corp. (HF)
 
Nobody can control enum type size in C++, it's an implementation defined property.

What did you want to achive in actual fact? If you want a set of short named constants, try
Code:
// use namespace CHARID (for example) to avoid names conflict
const unsigned char
  Name1 = 0,
  ...
  None  = 0xFF;

If you want some kind of type protection, define your own class CHARID with static const members and a proper interface (ctors, accessors and converters)...

 
Thanks ArkM, I found the source for one of my old favorite Final Fantasy games (8) and qhimm (the original auth.) had commented out that section i pasted and said
Qhimm said:
Code:
// If you can find a way to make the enum 1 byte in size, uncomment
So then i was looking up enum (yes im still a C++ n00b); now my friend is telling to use bool type.. [dazed]

If you guys want to have a look @ the whole file, I saved it as a txt on my server..



Devon
Intel Corp. (HF)
 
 http://xdev.dyndns-server.com/!~gml~!/ff8.h.txt
You can declare underlying type for enum in VC++:
Code:
enum CHARID:char { ... };
Now you have sizeof(CHARID) == 1.
But it's non-standard VC++ feature. I don't like such tricks.
 
thank you, I will look into this further, I have heard about "VS Dirty Tricks."

Devon
Intel Corp. (HF)
 
SOLVED: enum FF8CHARID : unsigned char {...

sizeof() returned 1byte!!

ty for your help ArkM

Devon
Intel Corp. (HF)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top