Solved

Question on #define values

Posted on 2004-09-17
2
204 Views
Last Modified: 2010-04-01
I'm looking at some code, this is purely an example, but I see often things like this:

-----------------------------
#define WRITEMODE_TRACKATONCE         0x00
#define WRITEMODE_DISCATONCE          0x01
#define WRITEMODE_DISCATONCE_RAW      0x02
#define WRITEMODE_SESSIONATONCE       0x03
#define WRITEMODE_PACKET_VARIABLE     0x04
#define WRITEMODE_PACKET_FIXED        0x05

#define DISCTYPE_CDR                  0
#define DISCTYPE_CDRW                 1
#define DISCTYPE_DDCDR                2
#define DISCTYPE_DDCDRW               3
#define DISCTYPE_DVDR                 4
--------------------------------------


that's from a CD write/read library.. My question is, why are constants defined at times like 0x02  and at other times, 2 (for example) What is the fundamental difference and when choosing to go with an 0x type value, from where to do you define the values??
thanks
-paul
0
Comment
Question by:PMH4514
2 Comments
 
LVL 13

Accepted Solution

by:
SteH earned 50 total points
ID: 12085372
0x is hex representation. So after 0x09 comes 0x0a. It makes most sense if you want to test bit combinations which are easier to recognize in hex representation ie:
 0x0001  1
 0x0002  2
 ...
 0x0200  512
 ..
 0x1000 4096

Otherwise it is the pure choice/preference of the author of the header.
0
 

Author Comment

by:PMH4514
ID: 12085753
yeah, I realize they are hex representation.. I just wasn't sure why you'd choose one defintion over the other.  the intent to test bit combinations makes perfect sense.

thanks!
-Paul
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now