<< < 159 160 161 162 163 164 165 166 167 168 169 > >>   Sort: Date

I thought that ANSI function prototypes were supposed to guard against argument type mismatches.
I thought that ANSI function prototypes were supposed to guard against argument type mismatches. When a function accepts a variable number of arguments, its prototype does not (and cannot) provide any information about the number and types of those variable arguments. Therefore, the usual protection...
2015-11-06, 1264👍, 0💬

I am still getting errors due to library functions being undefined
I'm still getting errors due to library functions being undefined, even though I'm explicitly requesting the right libraries while linking. Many linkers make one pass over the list of object files and libraries you specify, and extract from libraries only those modules which satisfy references which...
2015-07-14, 1264👍, 0💬

What was noalias and what ever happened to it?
What was noalias and what ever happened to it? noalias was another type qualifier, in the same syntactic class as const and volatile, which was intended to assert that an object was not pointed to (``aliased'') by other pointers. The primary application, which is an important one, would have been fo...
2015-12-02, 1263👍, 0💬

What is the difference between calloc and malloc? ....
What's the difference between calloc and malloc? Which should I use? Is it safe to take advantage of calloc's zero-filling? Does free work on memory allocated with calloc, or do you need a cfree? calloc(m, n) is essentially equivalent to p = malloc(m * n); memset(p, 0, m * n); There is no important ...
2016-03-16, 1262👍, 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, 1261👍, 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, 1261👍, 0💬

fopen isnt letting me open files like "$HOME/.profile" and "~/.myrcfile".
fopen isn't letting me open files like "$HOME/.profile" and "~/.myrcfile". Under Unix, at least, environment variables like $HOME, along with the home-directory notation involving the ~ character, are expanded by the shell, and there's no mechanism to perform these expansions automatically when you ...
2015-04-06, 1261👍, 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, 1260👍, 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, 1259👍, 0💬

How can I find out how much memory is available?
How can I find out how much memory is available? Your operating system may provide a routine which returns this information, but it's quite system-dependent. (Also, the number may vary over time.) If you're trying to predict whether you'll be able to allocate a certain amount of memory, just try it-...
2015-03-30, 1259👍, 0💬

How can I display a percentage-done indication that updates itself in place, or show one of those twirling baton progress indica
How can I display a percentage-done indication that updates itself in place, or show one of those twirling baton progress indicators? These simple things, at least, you can do fairly portably. Printing the character '\r' will usually give you a carriage return without a line feed, so that you can ov...
2015-04-27, 1258👍, 0💬

Can I use base-2 constants (something like 0b101010)? Is there a printf format for binary?
Can I use base-2 constants (something like 0b101010)? Is there a printf format for binary? No, on both counts, although there are various preprocessor tricks you can try. You can convert base-2 string representations to integers with strtol. If you need to print numbers out in base 2, .
2015-02-13, 1257👍, 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, 1256👍, 0💬

What is wrong with this code?
What's wrong with this code? char c; while((c = getchar()) != EOF) ... For one thing, the variable to hold getchar's return value must be an int. EOF is an ``out of band'' return value from getchar: it is distinct from all possible char values which getchar can return. (On modern systems, it does no...
2015-11-16, 1253👍, 0💬

I am using header files which accompany two different third-party libraries...
I'm using header files which accompany two different third-party libraries, and they are ``helpfully'' defining common macros such as TRUE, FALSE, Min(), and Max(), but the definitions clash with each other and with definitions I'd already established in my own header files. What can I do? This is i...
2016-02-10, 1251👍, 0💬

Must I free allocated memory before the program exits?
Must I free allocated memory before the program exits? You shouldn't have to. A real operating system definitively reclaims all memory and other resources when a program exits; the system cannot afford to have memory integrity depend on the whims of random programs. (Strictly speaking, it is not eve...
2016-03-28, 1250👍, 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, 1250👍, 0💬

Does C have an equivalent to Pascals with statement?
Does C have an equivalent to Pascals with statement? No. The way in C to get quick and easy access to the fields of a structure is to declare a little local structure pointer variable (which, it must be admitted, is not quite as notationally convenient as a with statement and doesn't save quite as m...
2015-01-14, 1250👍, 0💬

How can I write a generic macro to swap two values?
How can I write a generic macro to swap two values? There is no good answer to this question. If the values are integers, a well-known trick using exclusive-OR could perhaps be used, but it will not work for floating-point values or pointers, or if the two values are the same variable. If the macro ...
2016-02-24, 1248👍, 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, 1246👍, 0💬

Was 2000 a leap year?
Was 2000 a leap year? Q: Is (year % 4 == 0) an accurate test for leap years? (Was 2000 a leap year?) A: No, it's not accurate (and yes, 2000 was a leap year). The actual rules for the present Gregorian calendar are that leap years occur every four years, but not every 100 years, except that they do ...
2015-01-05, 1245👍, 0💬

Why are some ANSI ISO Standard library functions showing you
Why are some ANSI/ISO Standard library functions showing up as undefined, even though I've got an ANSI compiler? It's possible to have a compiler available which accepts ANSI syntax, but not to have ANSI-compatible header files or run-time libraries installed. (In fact, this situation is rather comm...
2015-11-30, 1244👍, 0💬

How can I clear the screen? How can I print text in color? How can I move the cursor to a specific x, y position?
How can I clear the screen? How can I print text in color? How can I move the cursor to a specific x, y position? Such things depend on the terminal type (or display) you're using. You will have to use a library such as termcap, terminfo, or curses, or some system-specific routines, to perform these...
2015-04-27, 1244👍, 0💬

Is C a great language, or what?
Is C a great language, or what? Where else could you write something like a+++++b ? A: Well, you can't meaningfully write it in C, either. The rule for lexical analysis is that at each point during a straightforward left-to-right scan, the longest possible token is determined, without regard to whet...
2015-01-26, 1244👍, 0💬

<< < 159 160 161 162 163 164 165 166 167 168 169 > >>   Sort: Date