c-preprocessor Questions
3
Solved
How can I check the size of an unsigned in the preprocessor under g++? sizeof is out of the question since it is not defined when during preprocessing.
Induce asked 6/4, 2010 at 13:1
6
Solved
Is the C preprocessor able to perform integer arithmetic?
E.g.:
#define PI 3.1416
#define OP PI/100
#define OP2 PI%100
Is there a way OP and/or OP2 get calculated in the preprocessing phase?
Minesweeper asked 13/10, 2009 at 13:44
2
Solved
For code:
#if defined(FOO) && FOO(foo)
#error "FOO is defined."
#else
#error "FOO is not defined."
#endif
MSVC 19.38 prints:
<source>(1): warning C4067: unexpec...
Margertmargery asked 30/6, 2024 at 13:41
5
Solved
I have a comment that ends with backslash. Something like
...
// use \
..
Clang(++) warned me, that this is multi-line comment
warning: multi-line // comment [-Wcomment]
// use \
^
So I t...
Countryfied asked 17/5, 2015 at 11:12
3
Solved
I'm implementing The X macro, but I have a problem with a simple macro expansion. This macro (see below) is used into several macros usage examples, by including in this article.
The compiler give...
Overtly asked 4/11, 2012 at 5:55
6
Solved
Is it possible to tell the C preprocessor to check whether a function (not a macro) is declared? I tried the following, but it doesn't appear to work:
#include <stdio.h>
int main(void)
{
#i...
Starflower asked 17/11, 2009 at 14:24
8
Solved
I'm trying to convert the string produced from the __DATE__ macro into a time_t. I don't need a full-blown date/time parser, something that only handles the format of the __DATE__ macro would be gr...
Omentum asked 19/11, 2009 at 17:17
3
Solved
I have a file in my project which contains the project version number. I have to make the content of this file available as a preprocessor definition in my code.
What I need is to somehow pass the...
Salahi asked 19/3, 2014 at 10:50
5
Solved
For example I have a macro:
#define PRINT(int) printf(#int "%d\n",int)
I'm somewhat aware of the outcome.
But how come #int represent the whole thing?
I'm somewhat forget this detail. Ca...
Endways asked 16/1, 2013 at 5:34
4
Solved
I see this being done all the time for example in the Linux kernel. What is the purpose of using the preprocessor commands vs. just normal C++ if else block? Is there a speed advantage or something...
Gardiner asked 6/4, 2014 at 18:13
1
Rules of the standard
The standard says the following about the rescanning phase (after #/##-processing and parameter substitution) of macro expansion (C17 draft, 6.10.3.4 ¶2):
If the name of the ...
Nitroparaffin asked 10/10, 2023 at 10:50
4
Solved
Is there a way to concatenate 2 strings literals to form an include path?
Code stub:
#define INCLUDE_DIR "/include"
#include INCLUDE_DIR "/dummy.h"
Looking at this question, the answers point i...
Memoried asked 19/8, 2016 at 12:16
5
Solved
So I can do something like
#ifdef MSVC
//do compiler specific code here
#endif
Dearing asked 1/5, 2011 at 18:18
11
Solved
I have two macros FOO2 and FOO3:
#define FOO2(x,y) ...
#define FOO3(x,y,z) ...
I want to define a new macro FOO as follows:
#define FOO(x,y) FOO2(x,y)
#define FOO(x,y,z) FOO3(x,y,z)
But this ...
Stephanistephania asked 1/8, 2012 at 14:42
6
It seems I often spend way too much time trying to get a #define macro to do exactly what i want. I'll post my current dilemma below and any help is appreciated. But really the bigger question is w...
Intermediacy asked 11/6, 2010 at 1:21
10
Solved
The question is quite clear I think. I'm trying to write a compiler detection header to be able to include in the application information on which compiler was used and which version.
This is part...
Middleaged asked 24/10, 2009 at 12:23
7
The usual way to test whether a preprocessor symbol is defined is using #ifdef. However, #ifdef cannot be used in a macro. What I need is a way to check in a macro if an argument of that macro is a...
Calkins asked 29/9, 2014 at 12:17
5
Solved
The syntax for disabling warnings is as follows:
#pragma warning disable 414, 3021
Or, expressed more generally:
#pragma warning disable [CSV list of numeric codes]
Is there a list of these n...
Coronal asked 2/6, 2009 at 22:28
18
Solved
I'm currently trying to create a C source code which properly handles I/O whatever the endianness of the target system.
I've selected "little endian" as my I/O convention, which means that, for bi...
Niobous asked 23/1, 2012 at 21:35
18
Solved
I need my code to do different things based on the operating system on which it gets compiled. I'm looking for something like this:
#ifdef OSisWindows
// do Windows-specific stuff
#else
// do Unix...
Matchbook asked 26/9, 2008 at 23:44
13
Solved
Simple question for which I could not find answer on the net. In variadic argument macros, how to find the number of arguments? I am okay with boost preprocessor, if it has the solution.
If it mak...
Cryo asked 23/1, 2010 at 19:11
7
Solved
What's the meaning of #line in the C language? Where would it be used?
Platus asked 7/2, 2010 at 9:29
4
Solved
I have the following macro:
#define IF_TRACE_ENABLED(level) if (IsTraceEnabled(level))
The user code should look following:
IF_TRACE_ENABLED(LEVEL1)
{
... some very smart code
}
The emphasis...
Gambol asked 28/9, 2010 at 7:54
2
I have a project where I have a substantial amount of conditional defines for making cross platform development easier. However I'm having issues convincing Doxygen to extract all the defines, as i...
Twyla asked 17/12, 2016 at 7:15
2
Solved
According to CPPReference, #if is followed by a constant expression. sizeof is a valid operator in constant expressions. But when I write this and compile it with clang or gcc, it fails:
#if sizeof...
Doggoned asked 18/1, 2024 at 14:44
1 Next >
© 2022 - 2025 — McMap. All rights reserved.