The define tag has no wiki summary.
71
votes
15answers
26k views
Should I use #define, enum or const?
In a C++ project I'm working on, I have a flag kind of value which can have four values. Those four flags can be combined. Flags describe the records in database and can be:
new record
deleted ...
3
votes
2answers
1k views
Initializing PHP class property declarations with simple expressions yields syntax error
According to the PHP docs, one can initialize properties in classes with the following restriction:
"This declaration may include an initialization, but this initialization must be a constant ...
35
votes
10answers
2k 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.
8
votes
16answers
3k views
Can this macro be converted to a function?
While refactoring code and ridding myself of all those #defines that we're now taught to hate, I came across this beauty used to calculate the number of elements in a structure:
#define STRUCTSIZE(s) ...
21
votes
4answers
4k views
What is the possible use for “#define for if (false) {} else for”?
In another question, I just spotted this little pearl of C wisom:
#define for if (false) {} else for
which caused MSVC to spit out "constant expression" warnings for a quite valid statement:
for ...
25
votes
7answers
4k views
Indenting #defines
I know that #defines, etc. are normally never indented. Why?
I'm working in some code at the moment which has a horrible mixture of #defines, #ifdefs, #elses, #endifs, etc. All these often mixed in ...
25
votes
5answers
19k views
Is the sizeof(enum) == sizeof(int), always?
Is the sizeof(enum) == sizeof(int), always ?
Or is it compiler dependent?
Is it wrong to say, as complier are optimized for word lengths (memory alignment) ie y int is the word-size on a particular ...
41
votes
1answer
31k views
Why are #ifndef and #define used in c++ header files
I have been seeing code like this usually in the start of header files
#ifndef HEADERFILE_H
#define HEADERFILE_H
and at the end of the file is
#endif
I am confused about the purpose of this ..?
...
17
votes
12answers
4k views
#include header guard format?
I know it makes little difference to a project but, assuming you use #defined header guards for your C++ code, what format do you use? e.g. assuming a header called foo.hpp:
#ifndef __FOO_HPP__
...
...
5
votes
1answer
689 views
Use a variable to define a PHP function
I'd like to dynamically name a few functions using variables, like this:
$thing = 'some_function';
function $thing() {
echo 'hi!';
}
I know I can call a function using a variable like this:
...
51
votes
2answers
13k views
GCC dump preprocessor defines
Is there a way for gcc/g++ to dump its preprocessor defines from the command line?
I mean things like __GNUC__, __STDC__, and so on.
22
votes
3answers
4k views
Complete list of defines for Delphi versions
Does anyone know of a good place where I can find the complete list of version defines for all the Delphi versions, right up to Delphi 2009?
9
votes
2answers
13k views
Macro for concatenating two strings in C
I'm trying to define a macro which is suppose to take 2 string values and return them concatenated with a one space between them. It seems I can use any character I want besides space, for example:
...
5
votes
4answers
5k views
MSBuild.exe not accepting either /p:DefineConstants nor /p:PreprocessorDefinitions
I've been through quite a number of articles on stack overflow that answered the question "How do I pass preprocessor definitions to the compiler from the MSBuild command line," and they all responded ...
8
votes
5answers
1k views
What does “#define STR(a) #a” do?
I'm reading the phoneME's source code. It's a FOSS JavaME implementation. It's written in C++, and I stumbled upon this:
// Makes a string of the argument (which is not macro-expanded)
#define STR(a) ...