Questions tagged [predefined-macro]
38 questions
55
votes
7 answers
How to use __DATE__ and __TIME__ predefined macros in as two integers, then stringify?
Want to use __ DATE __ and __ TIME __ as integer for giving automated version to my code in compile time.
#define STRINGIZER(arg) #arg
#define STR_VALUE(arg) STRINGIZER(arg)
#define DATE_as_int_str useD(__DATE__) // What can be done…

Rick2047
- 1,565
- 7
- 24
- 35
41
votes
6 answers
How can I use #pragma message() so that the message points to the file(lineno)?
In order to add 'todo' items into my code, I want to put a message in the compiler output.
I would like it to look like this:
c:/temp/main.cpp(104): TODO - add code to implement this
in order to make use of the Visual Studio build output…

xtofl
- 40,723
- 12
- 105
- 192
26
votes
2 answers
What is this #ifdef __GNUC__ about?
I've found these lines in the libmagic code. What do they mean?
#ifdef __GNUC__
__attribute__((unused))
#endif
What does __GNUC__ mean?
It seems to check whether GCC is installed.
What is __attribute__((unused))?
There's a code snippet here but no…

alvas
- 115,346
- 109
- 446
- 738
19
votes
5 answers
Detect ICC vs GCC at compile time
How to detect at compile time if I'm using gcc or icc?
(I was quite puzzled to find out that icc defines __GNUC__ -- and even __GNUC_MINOR__ and __GNUC_PATCHLEVEL__ ! why?)

Znorg
- 681
- 1
- 7
- 19
12
votes
3 answers
#error in Swift (how to mark compile-time error)
What is swift replacement of traditional c-style #error keyword?
I need it to raise compile-time error when pre-defines failed:
#if CONFIG1
...
#elseif CONFIG2
...
#else
#error "CONFIG not defined"
#endif

brigadir
- 6,874
- 6
- 46
- 81
11
votes
1 answer
Are there any guarantees about consistency of __LINE__ directives?
GCC 9 has recently changed the behavior of the __LINE__ directive in some cases. The program below illustrates the change:
#include
#define expand() __LINE__
int main() {
printf("%d\n",expand(
));
return 0;
}
Because…

anol
- 8,264
- 3
- 34
- 78
9
votes
1 answer
How to set predefined macros in Code::Blocks
Is there a way to set some predefined Macros for my local installation of Code::Blocks.
To elaborate on that, basically I would like to have certain blocks compiled only at pc and not anyplace I send the code to. One way to achieve this is as…

Shamim Hafiz - MSFT
- 21,454
- 43
- 116
- 176
9
votes
5 answers
How can I write a 'clamp' / 'clip' / 'bound' macro for returning a value in a given range?
I often find myself writing something like
int computedValue = ...;
return MAX(0, MIN(5, computedValue));
I would like to be able to write this as a single one-line macro. It must be free of side effects, in the same way that the existing system…

hfossli
- 22,616
- 10
- 116
- 130
5
votes
1 answer
__cplusplus < 201402L return true in gcc even when I specified -std=c++14
The directive:
#ifndef __cplusplus
#error C++ is required
#elif __cplusplus < 201402L
#error C++14 is required
#endif
The command-line: g++ -Wall -Wextra -std=c++14 -c -o header.o header.hpp
My g++ version: g++ (tdm-1) 4.9.2
The error C++14 is…

DMaster
- 603
- 1
- 10
- 23
4
votes
0 answers
Make Visual Studio 2017 IDE #define __cplusplus when looking at header file
I'm using Visual Studio 2017 to work with an embedded project with both C and C++ files, and I'm using a C++ compiler for everything.
When viewing a header file in the IDE, the predefined symbol __cplusplus is not defined. This affects the…

Tom the Toolman
- 166
- 11
4
votes
2 answers
C++ get the month as number at compile time
I have a c++ project that has to print a revision string. The revision string is company wise specified and the protocol includes the build time as yyyy/mm/dd.
I use to specify this as macro from the build system, but this is no longer an option…

gsf
- 6,612
- 7
- 35
- 64
3
votes
2 answers
Detecting Aligned Memory requirement on target CPU
I'm currently trying to build a code which is supposed to work on a wide range of machines, from handheld pockets and sensors to big servers in data centers.
One of the (many) differences between these architectures is the requirement for aligned…

Cyan
- 13,248
- 8
- 43
- 78
3
votes
3 answers
Is there a preprocessor macro that expands to the current selector?
Possible Duplicate:
Dynamically retrieving current method's name
Obj-C introspection: How can a method reference it's own selector?
This applies to Objective-C, is there a preprocessor macro or something to get the SEL value of the current…

adib
- 8,285
- 6
- 52
- 91
3
votes
1 answer
How to achieve a c++ macros like this
#define idebug(...) \
\#ifdef _DEBUG\
printf(__VA_ARGS__);\
\#endif\
#endif
It is difficult to describe the intention,
which generally means that i predefine a macros idebug which to save some code.
If _ DEBUG flag is predefined, then print…

anti-gravity
- 122
- 6
3
votes
2 answers
Linking to the correct library
I dont think my question here was answered here already. So here it is,
I have a static library that I maintain and update periodically. I also update the version number correctly. Now my application which uses this library must link to…

Hari
- 97
- 1
- 8