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

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, 1118👍, 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, 1139👍, 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, 1230👍, 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, 1147👍, 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, 1123👍, 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, 1103👍, 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, 1168👍, 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, 1130👍, 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, 1116👍, 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, 1091👍, 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, 1141👍, 0💬

What is the difference between const char .....
What's the difference between const char *p, char const *p, and char * const p? The first two are interchangeable; they declare a pointer to a constant character (you can't change any pointed-to characters). char * const p declares a constant pointer to a (variable) character (i.e. you can't change ...
2016-01-06, 1115👍, 0💬

Why cant I pass a char to a function which expects a const char ?
Why cant I pass a char to a function which expects a const char ? You can use a pointer-to-T (for any type T) where a pointer-to-const-T is expected. However, the rule (an explicit exception) which permits slight mismatches in qualified pointer types is not applied recursively, but only at the top l...
2016-01-04, 1164👍, 0💬

Why is p turning out const, instead of the characters pointed to?
I've got the declarations typedef char *charp; const charp p; Why is p turning out const, instead of the characters pointed to? typedef substitutions are not purely textual.In the declaration const charp p; p is const for the same reason that const int i declares i as const. The typedef'ed declarati...
2016-01-04, 1022👍, 0💬

What is the difference between ......
Q: What's the difference between const MAXSIZE = 100; and #define MAXSIZE 100 A preprocessor #define gives you a true compile-time constant. In C, const gives you a run-time object which you're not supposed to try to modify; ``const'' really means ``readonly''.
2015-12-22, 1535👍, 0💬

What is the correct declaration of main?
What is the correct declaration of main? There are two valid declarations: int main(void) int main(int argc, char **argv) although they can be written in a variety of ways. The second parameter may be declared char *argv[] , you can use any names for the two parameters, and you can use old-style syn...
2015-12-22, 1503👍, 0💬

Can I declare main as void, to shut off these annoying ....
Can I declare main as void, to shut off these annoying ``main returns no value'' messages? No. main must be declared as returning an int, and as taking either zero or two arguments, of the appropriate types. If you're calling exit() but still getting warnings, you may have to insert a redundant retu...
2015-12-20, 1175👍, 0💬

But what about main's third argument, envp?
But what about main's third argument, envp? It's a non-standard (though common) extension. If you really need to access the environment in ways beyond what the standard getenv function provides, though, the global variable environ is probably a better avenue (though it's equally non-standard).
2015-12-20, 1231👍, 0💬

I believe that declaring void main) cant fail ...
I believe that declaring void main() can't fail, since I'm calling exit instead of returning, and anyway my operating system ignores a program's exit/return status. It doesn't matter whether main returns or not, or whether anyone looks at the status; the problem is that when main is misdeclared, its...
2015-12-18, 1216👍, 0💬

So what could go wrong? Are there really any systems where void main doesnt work?
So what could go wrong? Are there really any systems where void main doesnt work? It has been reported that programs using void main() and compiled using BC++ 4.5 can crash. Some compilers (including DEC C V4.1 and gcc with certain warnings enabled) will complain about void main().
2015-12-18, 1211👍, 0💬

Is exit status truly equivalent to returning the same status from main?
Is exit status truly equivalent to returning the same status from main? Yes and no. The Standard says that a return from the initial call to main is equivalent to calling exit. However, a return from main cannot be expected to work if data local to main might be needed during cleanup;A few very old,...
2015-12-16, 1205👍, 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...
2015-12-16, 1252👍, 0💬

What does the message warning macro replacement within a string literal mean?
What does the message warning macro replacement within a string literal mean? 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 ...
2015-12-14, 1281👍, 0💬

I am getting strange syntax errors inside lines I have ifdeffed out.
I am 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 c...
2015-12-14, 1151👍, 0💬

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