To: d791013 AT hntp2 DOT hinet DOT net (d791013) Cc: djgpp AT sun DOT soe DOT clarkson DOT edu (DJGPP list) Subject: Re: named enum? Date: Wed, 14 Sep 1994 13:36:10 +0100 From: Olly Betts In message <9409140618 DOT AA20013 AT hntp2 DOT hinet DOT net>, d791013 writes: > Can the named enumeration be implemented in DJGPP? For example, when >I compile the small program below: > > enum bool {false, true}; change this to: typedef enum {false, true} bool; > void main () { > bool foo = false; > } > Another question is that: I want to print out the hexidecimal code >using cout, like that: (referenced to the book "The C++ Programming >Language," Bjarne Stroustrup, 2nd, p54) > > #include > void main () { > char ch; > while (cin >> ch) > cout << hex(ch); You probably want: cout << hex << (unsigned int)ch; > } >and it did not work. After that I use the following codes: > > #include > const MASK = 0xff; > void main () { > char ch; > while (cin >> ch) > cout << hex << (MASK & ch); > } That's because the & will return int (since int is wider than char). The mask will throw away the upper bits produced by sign extension in the implicit cast. Cast to unsigned int to avoud this sign extension. Olly