Hi,
I often wrote my constants in C/C++ in the following form:
#define FOURCC(c0, c1, c2, c3) ( ((DWORD)(c0)) | ((DWORD)(c1) << 8) |
((DWORD)(c2) << 16) | ((DWORD)(c3) << 24) )
#define CONST_A FOURCC('A','B', 'C','D') // A-tag: "ABCD"
#define CONST_B FOURCC('E','F', 'G','H') // B-tag: "EFGH"
#define CONST_C FOURCC('I','J', 'K','L') // C-tag: "IJKL"
How can I write constant (I would prefer enum) in C# tastefully?
I tried the enums and constant variables of a class but either accept direct
expressions only:
public enum MyConstants
{
public None = ('\0' | ('\0' << 8) | ('\0' << 16) | ('\0' << 24)),
public A = ('A' | ('B' << 8) | ('C' << 16) | ('D' << 24)),
public B = ('E' | ('F' << 8) | ('G' << 16) | ('H' << 24)),
public C = ('I' | ('J' << 8) | ('K' << 16) | ('L' << 24))
}
It would be nice if I used the following form (or something similar):
public enum MyConstants
{
public None = FOURCC('\0','\0 ','\0','\0'),
public A = FOURCC('A','B', 'C','D'),
public B = FOURCC('E','F', 'G','H'),
public C = FOURCC('I','J', 'K','L')
}
Thanks for any good suggestion.
LPeter 4 2125
OOps! Of course, the public keywords (before enum fields) must be ignored.
On 4 May, 19:34, LPeter <LPe...@discuss ions.microsoft. comwrote:
Hi,
I often wrote my constants in C/C++ in the following form:
#define FOURCC(c0, c1, c2, c3) ( ((DWORD)(c0)) | ((DWORD)(c1) << 8) |
((DWORD)(c2) << 16) | ((DWORD)(c3) << 24) )
#define CONST_A FOURCC('A','B', 'C','D') // A-tag: "ABCD"
#define CONST_B FOURCC('E','F', 'G','H') // B-tag: "EFGH"
#define CONST_C FOURCC('I','J', 'K','L') // C-tag: "IJKL"
How can I write constant (I would prefer enum) in C# tastefully?
I tried the enums and constant variables of a class but either accept direct
expressions only:
public enum MyConstants
{
* * * * public None = ('\0' | ('\0' << 8) | ('\0' << 16) | ('\0'<< 24)),
* * * * public A = ('A' | ('B' << 8) | ('C' << 16) | ('D' << 24)),
* * * * public B = ('E' | ('F' << 8) | ('G' << 16) | ('H' << 24)),
* * * * public C = ('I' | ('J' << 8) | ('K' << 16) | ('L' << 24))
}
It would be nice if I used the following form (or something similar):
public enum MyConstants
{
* * * * public None = FOURCC('\0','\0 ','\0','\0'),
* * * * public A = FOURCC('A','B', 'C','D'),
* * * * public B = FOURCC('E','F', 'G','H'),
* * * * public C = FOURCC('I','J', 'K','L')
}
Thanks for any good suggestion.
LPeter
Shouldn't you be using struct rather than enum ?
"Stan" wrote:
On 4 May, 19:34, LPeter <LPe...@discuss ions.microsoft. comwrote:
Hi,
I often wrote my constants in C/C++ in the following form:
#define FOURCC(c0, c1, c2, c3) ( ((DWORD)(c0)) | ((DWORD)(c1) << 8) |
((DWORD)(c2) << 16) | ((DWORD)(c3) << 24) )
#define CONST_A FOURCC('A','B', 'C','D') // A-tag: "ABCD"
#define CONST_B FOURCC('E','F', 'G','H') // B-tag: "EFGH"
#define CONST_C FOURCC('I','J', 'K','L') // C-tag: "IJKL"
How can I write constant (I would prefer enum) in C# tastefully?
I tried the enums and constant variables of a class but either accept direct
expressions only:
public enum MyConstants
{
public None = ('\0' | ('\0' << 8) | ('\0' << 16) | ('\0' << 24)),
public A = ('A' | ('B' << 8) | ('C' << 16) | ('D' << 24)),
public B = ('E' | ('F' << 8) | ('G' << 16) | ('H' << 24)),
public C = ('I' | ('J' << 8) | ('K' << 16) | ('L' << 24))
}
It would be nice if I used the following form (or something similar):
public enum MyConstants
{
public None = FOURCC('\0','\0 ','\0','\0'),
public A = FOURCC('A','B', 'C','D'),
public B = FOURCC('E','F', 'G','H'),
public C = FOURCC('I','J', 'K','L')
}
Thanks for any good suggestion.
LPeter
Shouldn't you be using struct rather than enum ?
What are you thinking for?
LPeter
LPeter wrote:
Hi,
I often wrote my constants in C/C++ in the following form:
#define FOURCC(c0, c1, c2, c3) ( ((DWORD)(c0)) | ((DWORD)(c1) << 8) |
((DWORD)(c2) << 16) | ((DWORD)(c3) << 24) )
#define CONST_A FOURCC('A','B', 'C','D') // A-tag: "ABCD"
#define CONST_B FOURCC('E','F', 'G','H') // B-tag: "EFGH"
#define CONST_C FOURCC('I','J', 'K','L') // C-tag: "IJKL"
How can I write constant (I would prefer enum) in C# tastefully?
I tried the enums and constant variables of a class but either accept direct
expressions only:
public enum MyConstants
{
public None = ('\0' | ('\0' << 8) | ('\0' << 16) | ('\0' << 24)),
public A = ('A' | ('B' << 8) | ('C' << 16) | ('D' << 24)),
public B = ('E' | ('F' << 8) | ('G' << 16) | ('H' << 24)),
public C = ('I' | ('J' << 8) | ('K' << 16) | ('L' << 24))
}
It would be nice if I used the following form (or something similar):
public enum MyConstants
{
public None = FOURCC('\0','\0 ','\0','\0'),
public A = FOURCC('A','B', 'C','D'),
public B = FOURCC('E','F', 'G','H'),
public C = FOURCC('I','J', 'K','L')
}
Thanks for any good suggestion.
LPeter
The only way to get "expression s in enum" is to use some kind of code
generator or pre-processor, neither of which is built into C#.
I'd say you'll just have to hardcode the values.
public enum MyConstants
{
None = 0x00000000,
A = 0x40414243,
B = 0x44454647
}
(I don't know how FOURCC combines the values so the above example values
are probably wrong, you'll need to figure out the right values yourself)
--
Lasse Vågsæther Karlsen
mailto:la***@vk arlsen.no http://presentationmode.blogspot.com/
PGP KeyID: 0xBCDEA2E3 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Russell Shaw |
last post by:
Hi,
gcc-3.4 complains about non-integers in:
enum {IDENTIFIER = "<identifier>", WIDGETDEF = "widgetdef"};
even if i cast the strings to integers.
|
by: Sriram Rajagopalan |
last post by:
Hi,
Is the extra comma at the end of an enumerator-list valid according to
the C standards?
With the gcc compiler the following is valid:
enum DAYS {MONDAY, TUESDAY, }day1;
gcc does not even *warn* about the extra comma after "TUESDAY".
|
by: James Brown |
last post by:
I have the following enum declared:
enum TOKEN { TOK_ID = 1000, TOK_NUMBER, TOK_STRING };
(it goes on and on like that)
This is what I would like to do:
TOKEN t1 = TOK_ID; // ok
TOKEN t2 = 5; // compile error (cannot convert from
|
by: Michael C |
last post by:
If a class inherits from another class, say Form inherits from control, then
I can assign the Form to a variable of type Control without needing an
explicit conversion, eg
Form1 f = new Form1();
Control c = f;
An enum value inherits from int but it doesn't get implicitly converted:
HorizontalAlignment h = HorizontalAlignment.Center;
|
by: Visual Systems AB \(Martin Arvidsson\) |
last post by:
Hi!
I have created an enum list like this:
enum myEnum : int
{
This = 2,
That,
NewVal = 10,
LastItm
| |
by: Randy |
last post by:
Hi,
Can anyone point me to a complete, compilable example
of Besser's ENUM++ mechanism? I downloaded it from
CUJ and gave it a try but got errors just trying to compile
the header enum.h.
--Randy Yates
|
by: Randy |
last post by:
Hi,
I downloaded and tried the ENUM++ code from CUJ
http://www.cuj.com/documents/s=8470/cujboost0306besser/
but can't even get it to compile (see following). I
have also downloaded and installed the boost library.
This is using gcc under FC3.
|
by: Laurent Deniau |
last post by:
If I understand well, an enumeration is only garantee to hold at most an
int (6.7.2.2-2). So I would like to know:
how to store a long in an enum?
enum { p2_31 = 1L << 31 };
// boom
how to define a synonym of a constant address?
|
by: sarathy |
last post by:
Hi,
Can anyone just help me with what exactly is constant
expression. I read the section on Constant expression in K&R2. i am not
fully clear with it.
|
by: dspfun |
last post by:
Hi!
The words "expression" and "statement" are often used in C99 and C-
textbooks, however, I am not sure of the clear defintion of these
words with respect to C.
Can somebody provide a sharp defintion of "expression" and
"statement"? What is the difference between an expression and a
statement?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |