Linked Questions
12 questions linked to/from Why would someone use #define to define constants?
74 votes
6 answers
136k views
What is the difference between #define and const? [duplicate]
Possible Duplicates: Why would someone use #define to define constants? difference between a macro and a const in c++ C++ - enum vs. const vs. #define What is the difference between using #...
-1 votes
1 answer
3k views
Which is better #define PI or const double PI? [duplicate]
Which is better: #define PI 3.14 or const double PI = 3.14; This was an interview question, and I don't seem to find an unambiguous answer. I suppose I should prefer not to use macros, but I'd like ...
1 vote
1 answer
297 views
Definition of constant variable vs. #define [duplicate]
I would like to understand the difference between defining a constant variable as follows: const int ONE = 1; and using a preprocessor directive: #define ONE (1) I know that in the second case "1" ...
158 votes
16 answers
169k views
Determining 32 vs 64 bit in C++
I'm looking for a way to reliably determine whether C++ code is being compiled in 32 vs 64 bit. We've come up with what we think is a reasonable solution using macros, but was curious to know if ...
49 votes
10 answers
8k views
Shall I prefer constants over defines?
In C, shall I prefer constants over defines? I've reading a lot of code lately, and all of the examples make heavy use of defines.
18 votes
5 answers
1k views
What is an appropriate use scenario of #define in C++? [closed]
I know the basic rules, use inline, enum and const instead of #define, that is not what I'm after with this question. What I want to know is what is considered an acceptable scenario in which you ...
7 votes
6 answers
12k views
Why is #define bad and what is the proper substitute? [closed]
#define dItemName L"CellPhone"
3 votes
3 answers
26k views
#define a string literal then assign it to a char*
#define MAXSTR "Maximum number reached" char *str = MAXSTR; While doing this kind of operation. Code is working & running fine but I am getting lint error. How I can resolve it? Error: ...
4 votes
3 answers
10k views
In C++, is it better to use #define or const to avoid magic numbers?
What are the advantages and disadvantages of using #define over const (and vice versa)? When I read about bad programming practices specifically magic numbers, I found myself using #define more ...
1 vote
2 answers
597 views
Global constants in an iOS application [closed]
What's the best practice for the use of some static info like: Server base url Some path file ... I think that we can found some different solutions for this: It's possible to add these informations ...
0 votes
4 answers
484 views
Why use macro when same job is done by a variable? in C language? [duplicate]
I don't see the need of using macro to define something , say in below example: #define TELEPHONE 443 //why use this int telephone = 443; //when same job is done by a regular variable why would any ...
0 votes
0 answers
122 views
Segmentation Fault in C++ before the program enter main
I'm writing a program that need to using two mutex and 30+25 threads to run. However it made a segmentation fault. It successful complie, but fail to run. The segmentation fault is start in the ...