Click here to Skip to main content
15,912,897 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: VC++ VS .NET Pin
Roger Wright12-May-04 20:46
professionalRoger Wright12-May-04 20:46 
Generalhelp on using visual c++ toolkit 2003 with vc6 Pin
ljbade12-May-04 19:00
ljbade12-May-04 19:00 
GeneralSet height or width of control bar Pin
alex.barylski12-May-04 17:42
alex.barylski12-May-04 17:42 
GeneralRe: Set height or width of control bar Pin
nguyenvhn12-May-04 17:57
nguyenvhn12-May-04 17:57 
GeneralRe: Set height or width of control bar Pin
alex.barylski12-May-04 18:03
alex.barylski12-May-04 18:03 
Generaldefine Vs. const Pin
Ernesto D.12-May-04 17:31
Ernesto D.12-May-04 17:31 
GeneralRe: define Vs. const Pin
nguyenvhn12-May-04 17:51
nguyenvhn12-May-04 17:51 
GeneralRe: define Vs. const Pin
Maxwell Chen12-May-04 18:10
Maxwell Chen12-May-04 18:10 
1) Regarding to the very purpose in your question, the main difference is ~ scope. A define lasts its definition till the end of the compilation module; but a const literal only lives within its scope. For example, try to compile the code below:
void Foo()
{
#define MAX_SIZE	192
	// ...
}

// ...

bool Bar()
{
#define MAX_SIZE	512	// Oops!
	int iSize = MAX_SIZE;
}

When your program is very large with a lot of source files, and the define(s) hide somewhere very deep in some header file(s) included by the other header files, you would find it annoying, because it needs to undef and ......


2) There are some other reasons about avoiding macros (not related to your question). Please read Section 7.8 - Macro in the book The C++ Programming Language, 3rd by Stroustrup.

"Macros are very important in C but have far fewer uses in C++. The first rule about macros is: Don't use them unless you have to. Almost every macro demonstrates a flaw in the programming language, in the program, or in the programmer. Because they rearrange the program text before the compiler proper sees it, macros are also a major problem for many programming tools. ...... " ~ Stroustrup.
The section demonstrates many flaws!



Maxwell Chen
GeneralRe: define Vs. const Pin
Ernesto D.12-May-04 20:25
Ernesto D.12-May-04 20:25 
GeneralRe: define Vs. const Pin
Joe Woodbury13-May-04 9:21
professionalJoe Woodbury13-May-04 9:21 
GeneralSyntax and Missing Identifiers---LONG Pin
---Mark----12-May-04 17:17
suss---Mark----12-May-04 17:17 
GeneralRe: Syntax and Missing Identifiers---LONG Pin
Maxwell Chen12-May-04 17:32
Maxwell Chen12-May-04 17:32 
GeneralRe: Syntax and Missing Identifiers---LONG Pin
---Mark---12-May-04 18:00
---Mark---12-May-04 18:00 
GeneralRe: Syntax and Missing Identifiers---LONG Pin
---Mark---12-May-04 18:04
---Mark---12-May-04 18:04 
GeneralRe: Syntax and Missing Identifiers---LONG Pin
Maxwell Chen12-May-04 18:22
Maxwell Chen12-May-04 18:22 
GeneralRe: Syntax and Missing Identifiers---LONG Pin
---Mark---12-May-04 18:43
---Mark---12-May-04 18:43 
GeneralAdvice for Books Pin
vnm612-May-04 16:18
vnm612-May-04 16:18 
GeneralRe: Advice for Books Pin
Anthony_Yio12-May-04 16:41
Anthony_Yio12-May-04 16:41 
GeneralRe: Advice for Books Pin
vnm613-May-04 21:01
vnm613-May-04 21:01 
GeneralCATCH_ALL and OnCtlColor Pin
Coremn12-May-04 15:01
Coremn12-May-04 15:01 
GeneralRe: CATCH_ALL and OnCtlColor Pin
monrobot1312-May-04 15:29
monrobot1312-May-04 15:29 
GeneralRe: CATCH_ALL and OnCtlColor Pin
Coremn12-May-04 15:42
Coremn12-May-04 15:42 
GeneralRe: CATCH_ALL and OnCtlColor Pin
Coremn12-May-04 16:17
Coremn12-May-04 16:17 
GeneralRe: CATCH_ALL and OnCtlColor Pin
Ryan Binns12-May-04 18:02
Ryan Binns12-May-04 18:02 
GeneralInterface Methods Pin
monrobot1312-May-04 14:20
monrobot1312-May-04 14:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.