<< < 6 7 8 9 10 11 12 13 14 15 16 > >>

I am having trouble with a Turbo C program which crashes
I'm having trouble with a Turbo C program which crashes and says something like ``floating point formats not linked.'' Some compilers for small machines, including Turbo C (and Ritchie's original PDP-11 compiler), leave out certain floating point support if it looks like it will not be needed. In pa...
2015-06-19, 1146👍, 0💬

I heard that you have to include stdio.h before calling printf. Why?
I heard that you have to include stdio.h 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 l...
2015-06-17, 1115👍, 0💬

How can f be used for both float and double arguments in printf? Aren't they different types?
How can f be used for both float and double arguments in printf? Aren't they different types? In the variable-length part of a variable-length argument list, the ``default argument promotions'' apply: types char and short int are promoted to int, and float is promoted to double. (These are the same ...
2015-06-17, 1161👍, 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. When a function accepts a variable number of arguments, its prototype doe...
2015-06-15, 1131👍, 0💬

How can I write a function that takes a variable number of arguments?
How can I write a function that takes a variable number of arguments? Use the facilities of the &lt;stdarg.h> header. Here is a function which concatenates an arbitrary number of strings into malloc'ed memory: #include &lt;stdlib.h> /* for malloc, NULL, size_t */ #include &lt;stdarg.h> /...
2015-06-15, 1074👍, 0💬

How can I write a function that takes a format string and a variable number of arguments
How can I write a function that takes a format string and a variable number of arguments, like printf, and passes them to printf to do most of the work? Use vprintf, vfprintf, or vsprintf. These routines are like their counterparts printf, fprintf, and sprintf, except that instead of a variable-leng...
2015-06-12, 1139👍, 0💬

How can I write a function analogous to scanf
How can I write a function analogous to scanf, i.e. that accepts similar arguments, and calls scanf to do most of the work? C99 (but not any earlier C Standard) supports vscanf, vfscanf, and vsscanf.
2015-06-12, 1058👍, 0💬

I have a pre-ANSI compiler, without stdarg.h What can I do?
I have a pre-ANSI compiler, without stdarg.h What can I do? There's an older header, &lt;varargs.h>, which offers about the same functionality. Here is the vstrcat function, rewritten to use &lt;varargs.h>: #include &lt;stdio.h> #include &lt;varargs.h> #include &lt;string.h> exte...
2015-06-10, 1135👍, 0💬

How can I discover how many arguments a function was actually called with?
How can I discover how many arguments a function was actually called with? This information is not available to a portable program. Some old systems provided a nonstandard nargs function, but its use was always questionable, since it typically returned the number of words passed, not the number of a...
2015-06-10, 1237👍, 0💬

My compiler isnt letting me declare a function
My compiler isnt letting me declare a function A; My compiler isn't letting me declare a function int f(...) { } i.e. accepting a variable number of arguments, but with no fixed arguments at all. A: Standard C requires at least one fixed argument, in part so that you can hand it to va_start. (In any...
2015-06-08, 1086👍, 0💬

I have a varargs function which accepts a float parameter
I have a varargs function which accepts a float parameter. Why isn't va_arg(argp, float) working? In the variable-length part of variable-length argument lists, the old ``default argument promotions'' apply: arguments of type float are always promoted (widened) to type double, and types char and sho...
2015-06-08, 1163👍, 0💬

I cant get va_arg to pull in an argument of type pointer-to-function.
I cant get va_arg to pull in an argument of type pointer-to-function. Try using a typedef for the function pointer type. The type-rewriting games which the va_arg macro typically plays are stymied by overly-complicated types such as pointer-to-function. To illustrate, a simplified implementation of ...
2015-06-05, 1163👍, 0💬

How can I write a function which takes a variable number of arguments
How can I write a function which takes a variable number of arguments and passes them to some other function (which takes a variable number of arguments)? In general, you cannot. Ideally, you should provide a version of that other function which accepts a va_list pointer. Suppose you want to write a...
2015-06-05, 1189👍, 0💬

How can I call a function with an argument list built up at run time?
How can I call a function with an argument list built up at run time? There is no guaranteed or portable way to do this. Instead of an actual argument list, you might consider passing an array of generic (void *) pointers. The called function can then step through the array, much like main() might s...
2015-06-03, 1214👍, 0💬

Why is this loop always executing once?
Why is this loop always executing once? for(i = start; i &lt; end; i++); { printf("%d\n", i); } A: The accidental extra semicolon hiding at the end of the line containing the for constitutes a null statement which is, as far as the compiler is concerned, the loop body. The following brace-enclos...
2015-06-03, 1141👍, 0💬

I am getting baffling syntax errors which make no sense at all
I'm getting baffling syntax errors which make no sense at all, and it seems like large chunks of my program aren't being compiled. Check for unclosed comments, mismatched #if/#ifdef/#ifndef/#else/#endi fdirectives, and perhaps unclosed quotes; remember to check header files, too.
2015-06-01, 1108👍, 0💬

Why isnt my procedure call working? The compiler seems to skip right over it
Why isnt my procedure call working? The compiler seems to skip right over it Does the code look like this? myprocedure; C has only functions, and function calls always require parenthesized argument lists, even if empty. Use myprocedure(); Without the parentheses, the reference to the function name ...
2015-06-01, 1115👍, 0💬

This program crashes before it even runs!
This program crashes before it even runs! (When single-stepping with a debugger, it dies before the first statement in main.) You probably have one or more very large (kilobyte or more) local arrays. Many systems have fixed-size stacks, and even those which perform dynamic stack allocation automatic...
2015-05-29, 1148👍, 0💬

I have a program that seems to run correctly
I have a program that seems to run correctly, but it crashes as it's exiting, after the last statement in main(). What could be causing this? A:There are at least three things to look for: 1. If a semicolon in a previous declaration is missing, main might be inadvertently declared as returning a str...
2015-05-29, 1124👍, 0💬

This program runs perfectly on one machine ...
This program runs perfectly on one machine, but I get weird results on another. Stranger still, adding or removing a debugging printout changes the symptoms... Lots of things could be going wrong; here are a few of the more common things to check: * uninitialized local variables integer overflow, es...
2015-05-27, 1224👍, 0💬

Why does this code crash?
Why does this code: char *p = "hello, world!"; p[0] = 'H'; crash? String constants are in fact constant. The compiler may place them in nonwritable storage, and it is therefore not safe to modify them. When you need writable strings, you must allocate writable memory for them, either by declaring an...
2015-05-27, 1128👍, 0💬

I have seen function declarations that look like this
I've seen function declarations that look like this: extern int func __((int, int)); What are those extra parentheses and underscores for? They're part of a trick which allows the prototype part of the function declaration to be turned off for a pre-ANSI compiler. Somewhere else is a conditional def...
2015-05-23, 1350👍, 0💬

I have got some code that is trying to unpack external structures
I've got some code that's trying to unpack external structures, but it's crashing with a message about an ``unaligned access.'' What does this mean? The code looks like this: struct mystruct { char c; long int i32; int i16; } s; char buf[7], *p; fread(buf, 7, 1, fp); p = buf; s.c = *p++; s.i32 = *(l...
2015-05-20, 1143👍, 0💬

What do Segmentation violation, `Bus error, and General protection fault mean? What is a core dump?
What do Segmentation violation, `Bus error, and General protection fault mean? What is a core dump? These symptoms (and any similar messages having to do with memory access violations or protection faults) generally mean that your program tried to access memory it shouldn't have, invariably as a res...
2015-05-20, 1200👍, 0💬

<< < 6 7 8 9 10 11 12 13 14 15 16 > >>