<< < 1 2 3 4 5 6 7 8 9 10 > >>   Sort: Rank

How can I construct preprocessor if expressions which compare strings?
How can I construct preprocessor if expressions which compare strings? You can't do it directly; preprocessor #if arithmetic uses only integers. An alternative is to #define several macros with symbolic names and distinct integer values, and implement conditionals on those: #define RED 1 #define BLU...
2016-02-05, 6759👍, 0💬

Does the sizeof operator work in preprocessor if directives?
Does the sizeof operator work in preprocessor if directives? No. Preprocessing happens during an earlier phase of compilation, before type names have been parsed. Instead of sizeof, consider using the predefined constants in ANSI's &lt;limits.h>, if applicable, or perhaps a ``configure'' script....
2016-02-03, 1280👍, 0💬

Can I use an ifdef in a #define line ...
Can I use an #ifdef in a #define line, to define something two different ways, like this? #define a b \ #ifdef whatever c d #else e f g #endif No. You can't ``run the preprocessor on itself,'' so to speak. What you can do is use one of two completely separate #define lines, depending on the #ifdef s...
2016-02-03, 1271👍, 0💬

Is there anything like an ifdef for typedefs?
Is there anything like an ifdef for typedefs? Unfortunately, no. (There can't be, because types and typedefs haven't been parsed at preprocessing time.) You may have to keep sets of preprocessor macros (e.g. MY_TYPE_DEFINED) recording whether certain typedefs have been declared.
2016-02-01, 1241👍, 0💬

How can I use a preprocessorif expression to ? ....
How can I use a preprocessor #if expression to tell whether a machine's byte order is big-endian or little-endian? You probably can't. The usual techniques for detecting endianness involve pointers or arrays of char, or maybe unions, but preprocessor arithmetic uses only long integers, and there is ...
2016-02-01, 1270👍, 0💬

I a'm getting strange syntax errors inside lines I have ifdeffed out.
I a'm getting strange syntax errors inside lines I have ifdeffed out. Under ANSI C, the text inside a ``turned off'' #if, #ifdef, or #ifndef must still consist of ``valid preprocessing tokens.'' This means that the characters " and ' must each be paired just as in real C code, and the pairs mustn't ...
2016-01-29, 1243👍, 0💬

I inherited some code which contains far too many ...
I inherited some code which contains far too many #ifdef's for my taste. How can I preprocess the code to leave only one conditional compilation set, without running it through the preprocessor and expanding all of the #include's and #define's as well? There are programs floating around called unifd...
2016-01-29, 1192👍, 0💬

How can I list all of the predefined identifiers?
How can I list all of the predefined identifiers? There's no standard way, although it is a common need. gcc provides a -dM option which works with -E, and other compilers may provide something similar. If the compiler documentation is unhelpful, the most expedient way is probably to extract printab...
2016-01-27, 1238👍, 0💬

I have some old code that tries to construct identifiers with a macro like ...
I have some old code that tries to construct identifiers with a macro like #define Paste(a, b) a/**/b but it doesn't work any more. It was an undocumented feature of some early preprocessor implementations (notably Reiser's) that comments disappeared entirely and could therefore be used for token pa...
2016-01-27, 1191👍, 0💬

I have an old macro that doesn't seem to work any more....
I have an old macro #define CTRL(c) ('c' &amp; 037) that doesn't seem to work any more. The intended use of this macro is in code like tchars.t_eofc = CTRL(D); which is expected to expand to tchars.t_eofc = ('D' &amp; 037); based on the assumption that the actual value of the parameter c wil...
2016-01-25, 1152👍, 0💬

Why is the macro giving me the warning
Why is the macro #define TRACE(n) printf("TRACE: %d\n", n) giving me the warning ``macro replacement within a string literal''? It seems to be expanding TRACE(count); as printf("TRACE: %d\count", count); Some pre-ANSI compilers/preprocessors interpreted macro definitions like #define TRACE(var, fmt)...
2016-01-25, 1121👍, 0💬

How can I use a macro argument inside a string literal in the macro expansion?
How can I use a macro argument inside a string literal in the macro expansion? Some pre-ANSI compilers/preprocessors interpreted macro definitions like #define TRACE(var, fmt) printf("TRACE: var = fmt\n", var) such that invocations like TRACE(i, %d); were expanded as printf("TRACE: i = %d\n", i); In...
2016-01-22, 1237👍, 0💬

I am trying to use the ANSI stringizing preprocessing operator ....
I'm trying to use the ANSI ``stringizing'' preprocessing operator `#' to insert the value of a symbolic constant into a message, but it keeps stringizing the macro's name rather than its value. It turns out that the definition of # says that it's supposed to stringize a macro argument immediately, w...
2016-01-22, 1234👍, 0💬

I have got this tricky preprocessing I want to do and I cant figure out a way to do it.
I have got this tricky preprocessing I want to do and I cant figure out a way to do it. C's preprocessor is not intended as a general-purpose tool. (Note also that it is not guaranteed to be available as a separate program.) Rather than forcing it to do something inappropriate, you might want to wri...
2016-01-19, 1184👍, 0💬

How can I write a macro which takes a variable number of arguments ....
How can I write a macro which takes a variable number of arguments, or use the preprocessor to ``turn off'' a function call with a variable number of arguments? One popular trick is to define and invoke the macro with a single, parenthesized ``argument'' which in the macro expansion becomes the enti...
2016-01-19, 1210👍, 0💬

How can I include expansions of the macros .....
How can I include expansions of the __FILE__ and __LINE__ macros in a general-purpose debugging macro? One solution involves writing your debug macro in terms of a varargs function , and an auxiliary function which stashes the values of __FILE__ and __LINE__ away in static variables, as in: #include...
2016-01-15, 1296👍, 0💬

What is the ANSI C Standard?
What is the ANSI C Standard? In 1983, the American National Standards Institute (ANSI) commissioned a committee, X3J11, to standardize the C language. After a long, arduous process, including several widespread public reviews, the committee's work was finally ratified as ANS X3.159-1989 on December ...
2016-01-15, 1247👍, 0💬

My ANSI compiler complains about a mismatch when it see
My ANSI compiler complains about a mismatch when it sees extern int func(float); int func(x) float x; { ... You have mixed the new-style prototype declaration ``extern int func(float);'' with the old-style definition ``int func(x) float x;''. It is usually possible to mix the two styles but not in t...
2016-01-13, 1200👍, 0💬

Can you mix old-style and new-style function syntax?
Can you mix old-style and new-style function syntax? Doing so is legal (and can be useful for backwards compatibility), but requires a certain amount of care . Modern practice, however, is to use the prototyped form in both declarations and definitions. (The old-style syntax is marked as obsolescent...
2016-01-13, 1167👍, 0💬

Why does the declaration extern int .....
Why does the declaration extern int f(struct x *p); give me an obscure warning message about ``struct x declared inside parameter list''? In a quirk of C's normal block scoping rules, a structure declared (or even mentioned) for the first time within a prototype cannot be compatible with other struc...
2016-01-11, 1234👍, 0💬

I had a frustrating problem which turned out to be caused by the line ....
I had a frustrating problem which turned out to be caused by the line printf("%d", n); where n was actually a long int. I thought that ANSI function prototypes were supposed to guard against argument type mismatches like this. A:When a function accepts a variable number of arguments, its prototype d...
2016-01-11, 1238👍, 0💬

I heard that you have to include ......
I heard that you have to #include before calling printf. Why? So that a proper prototype for printf will be in scope. A compiler may use a different calling sequence for functions which accept variable-length argument lists. (It might do so if calls using variable-length argument lists were less eff...
2016-01-08, 1176👍, 0💬

I dont understand why I cant use const values in initializers ....
I don't understand why I can't use const values in initializers and array dimensions, as in const int n = 5; int a[n]; The const qualifier really means ``read-only''; an object so qualified is a run-time object which cannot (normally) be assigned to. The value of a const-qualified object is therefor...
2016-01-08, 1178👍, 0💬

If you cant modify string literals, why arent they defined as being arrays of const characters?
If you cant modify string literals, why arent they defined as being arrays of const characters? One reason is that so very much code contains lines like char *p = "Hello, world!"; which are not necessarily incorrect. These lines would suffer the diagnostic messages, but it's really any later attempt...
2016-01-06, 1234👍, 0💬

<< < 1 2 3 4 5 6 7 8 9 10 > >>   Sort: Rank