eigenartiger gebrauch von enum
-
hallo leute
in VS2012 - datei: xiosbase steht folgendes:
enum _Iostate { // constants for stream states _Statmask = 0x17}; static const _Iostate goodbit = (_Iostate)0x0; static const _Iostate eofbit = (_Iostate)0x1; static const _Iostate failbit = (_Iostate)0x2; static const _Iostate badbit = (_Iostate)0x4; static const _Iostate _Hardfail = (_Iostate)0x10;was hat das fuer einen sinn goodbit usw. so zu definieren?
Meep Meep
-
Man kann das enum als Bitmaske benutzen.
-
knivil schrieb:
Man kann das enum als Bitmaske benutzen.
Könnte man auch sonst.
-
-
karneval schrieb:
knivil schrieb:
Man kann das enum als Bitmaske benutzen.
Könnte man auch sonst.
Nee, wenn einzelne Bits getestet werden sollen, dann ist ein aequivalenter Zahlwert von 3 eher bloed.
-
Ich meine, warum nicht so?
enum _Iostate { // constants for stream states goodbit = 0x0, eofbit = 0x1, failbit = 0x2, badbit = 0x4, _Hardfail = 0x10, _Statmask = 0x17 };Nach meinem Verständnis kommt das aufs Gleiche raus.
-
Die Definition
enum _Iostate { goodbit = 0x0 };ist semantisch fast äquivalent zu
enum _Iostate {}; static constexpr _Iostate goodbit = (_Iostate)0x0;The identifiers in anenumerator-list are declared as constants, and can appear wherever constants are required.
[...]
Following the closing brace of an enum-specifier, each enumerator has the type of its enumeration.
[...]
Each enum-name and each unscoped enumerator is declared in the scope that immediately contains the enum-specifier.
-
karneval schrieb:
Ich meine, warum nicht so?
enum _Iostate { // constants for stream states goodbit = 0x0, eofbit = 0x1, failbit = 0x2, badbit = 0x4, _Hardfail = 0x10, _Statmask = 0x17 };Nach meinem Verständnis kommt das aufs Gleiche raus.
Kommt auf's gleiche raus ist das eine.
Im Standard steht aber:namespace std { class ios_base { // ... // 27.5.3.1.3 iostate typedef T2 iostate; static constexpr iostate badbit = unspecified ; static constexpr iostate eofbit = unspecified ; static constexpr iostate failbit = unspecified ; static constexpr iostate goodbit = see below; }; }Da ist nix dran zu rütteln.
gcc machts übrigens anders als msvc:
namespace std{ enum _Ios_Iostate { _S_goodbit = 0, _S_badbit = 1L << 0, _S_eofbit = 1L << 1, _S_failbit = 1L << 2, _S_ios_iostate_end = 1L << 16 }; class ios_base{ //... typedef _Ios_Iostate iostate; static const iostate badbit = _S_badbit; static const iostate eofbit = _S_eofbit; static const iostate failbit = _S_failbit; static const iostate goodbit = _S_goodbit; }; }
-
Ich meine, warum nicht so?
Dann sag, was du meinst, anstatt Raetselraten auszuloesen.