A step by step tutorial teaching you how to create your own chat client and chat server easily in C#, for local networks or the Internet.
A C# tutorial showing you how to make use of WMI to extract information on disk drives, such as model, capacity, sectors and serial number.
This tutorial will teach you how to calculate the shipping cost based on the weight, height, length and depth of the box, the distance and the UPS service type.
Creating a Rich Text Editor using JavaScript is easier to do than you might think, thanks to the support of modern browsers; this tutorial will walk you through it.
What is the difference between #define and const? |
On Monday, May 21st 2007 at 01:13 AM By Andrew Pociu (View Profile) ![]() ![]() ![]() ![]() (Rated 3.9 with 10 votes) |
||
|
While
they both serve a similar purpose, #define and const act differently. When using #define the identifier gets replaced by the specified value by the compiler, before the code is turned into binary. This means that the compiler makes the substitution when you compile the application. Take for example: #define number 108 In this case every instance of "number" will be replaced by the actual number 108 in your code, and this means the final compiled program will have the number 108 (in binary). On the other hand, when you use const and the application runs, memory is allocated for the constant and the value gets replaced when the applicaton is ran: const int number = 108; |
|||
Digg It!
Del.icio.us
Reddit
StumbleIt
Newsvine
Furl
BlinkList
|
|||
|
|||
Current CommentsConst is a declaration of constant, compiler will do appropriate checks during the compile time. #define is a macro compiler will see a value. Speaking in terms of memory const declaration could be more efficient:
const short x = 1;
// this will allocate 16 bits for x (actually it depends on the machine,
I assume unix platform with 32 bits integers)
#define x (short)1
// this will probably allocate 32 bits to hold the constant 1.
Use const instead of #define mainly because of compiler checks. And inline functions instead of macros as well. Preprocessor is the obsolete remnant from early C days, there's no use of it in the oop environment.
2)
no diffence realy in memory, both are compiled as numbers, but with const's you can define it per namespace or class so that you can use it like mylinklist::maxmemebers, it looks better and more readable.
3)
#define macro does not take any space on stack, but it gets replaced in the code by its definition thereby increasing the size of exe.
Constant variable occupies space on stack and does not increase the size of the exe.
excellent performance on this topic
الفرق بين const,#define
الفرق بين const,#define?
الفرق بين const,#define?
الفرق بين const,#define?
Once you have recreated the problem and captured these steps, you can save them to a file and send it to your support person, who can then open it up and view
Related Knowledge Base Articles
Related Source Code
Related Tutorials
C++ Job SearchFrom the creators of Geekpedia, a revolutionary new coupon website!
BargainEZ has coupons codes, printable coupons, bargains and it is the leading source of Passbook coupons for iPhone and iPod touch devices.