<< < 5 6 7 8 9 10 11 12 13 14 15 > >>   Sort: Date

What is the right way to use errno?
What is the right way to use errno? In general, you should detect errors by checking return values, and use errno only to distinguish among the various causes of an error, such as ``File not found'' or ``Permission denied''. (Typically, you use perror or strerror to print these discriminating error ...
2015-02-23, 1168👍, 0💬

What is Hungarian Notation? Is it worthwhile?
What is Hungarian Notation? Is it worthwhile? Hungarian Notation is a naming convention, invented by Charles Simonyi, which encodes information about a variable's type (and perhaps its intended use) in its name. It is well-loved in some circles and roundly castigated in others. Its chief advantage i...
2015-05-08, 1167👍, 0💬

Which is more efficient, a switch statement or an if else chain?
Which is more efficient, a switch statement or an if else chain? The differences, if any, are likely to be slight. The switch statement was designed to be efficiently implementable, though the compiler may choose to use the equivalent of an if/else chain (as opposed to a compact jump table) if the c...
2015-02-04, 1166👍, 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, 1165👍, 0💬

If NULL and 0 are equivalent as null pointer constants, which should I use?
If NULL and 0 are equivalent as null pointer constants, which should I use? Many programmers believe that NULL should be used in all pointer contexts, as a reminder that the value is to be thought of as a pointer. Others feel that the confusion surrounding NULL and 0 is only compounded by hiding 0 b...
2015-05-11, 1165👍, 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, 1164👍, 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, 1164👍, 0💬

There seem to be a few missing operators ..
There seem to be a few missing operators, like ^^, &amp;&amp;=, and -&gt;=. A:A logical exclusive-or operator (hypothetically ``^^'') would be nice, but it couldn't possibly have short-circuiting behavior analogous to &amp;&amp; and || Similarly, it's not clear how short-circuiti...
2015-01-28, 1164👍, 0💬

People seem to make a point of distinguishing between ...
People seem to make a point of distinguishing between implementation-defined, unspecified, and undefined behavior. What do these mean? First of all, all three of these represent areas in which the C Standard does not specify exactly what a particular construct, or a program which uses it, must do. T...
2015-11-23, 1163👍, 0💬

How can I convert integers to binary or hexadecimal?
How can I convert integers to binary or hexadecimal? Make sure you really know what you're asking. Integers are stored internally in binary, although for most purposes it is not incorrect to think of them as being in octal, decimal, or hexadecimal, whichever is convenient. The base in which a number...
2015-02-13, 1163👍, 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, 1162👍, 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, 1162👍, 0💬

Why does everyone say not to use scanf? What should I use instead?
Why does everyone say not to use scanf? What should I use instead? scanf has a number of problems, its %s format has the same problem that gets() has --it's hard to guarantee that the receiving buffer won't overflow. More generally, scanf is designed for relatively structured, formatted input (its n...
2015-10-21, 1162👍, 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, 1162👍, 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, 1161👍, 0💬

What does pragma once mean? I found it in some header files.
What does pragma once mean? I found it in some header files. It is an extension implemented by some preprocessors to help make header files idempotent; that is, to make sure that their contents are processed exactly once even if they are #included multiple times.Some people claim that #pragma once c...
2015-12-11, 1161👍, 0💬

Does C have anything like the `substr (extract substring) routine present in other languages?
Does C have anything like the `substr (extract substring) routine present in other languages? Not as such. To extract a substring of length LEN starting at index POS in a source string, use something like char dest[LEN+1]; strncpy(dest, &amp;source[POS], LEN); dest[LEN] = '\0'; /* ensure \0 term...
2015-08-19, 1161👍, 0💬

I mm compiling a program, and I seem to be missing one of the header files it requires
I mm compiling a program, and I seem to be missing one of the header files it requires There are several situations, depending on what sort of header file it is that's ``missing''. If the missing header file is truly a standard one (that is, one defined by the ANSI C Standard, such as &lt;stdio....
2016-02-05, 1160👍, 0💬

What printf format should I use for a typedef like size_t when I don't know whether it is long or some other type?
What printf format should I use for a typedef like size_t when I don't know whether it is long or some other type? Use a cast to convert the value to a known, conservatively-sized type, then use the printf format matching that type. For example, to print the size of a type, you might use printf("%lu...
2015-11-04, 1160👍, 0💬

How can I do PEEK and POKE in C?
How can I access memory (a memory-mapped device, or graphics memory) located at a certain address? How can I do PEEK and POKE in C? Set a pointer, of the appropriate type, to the right number (using an explicit cast to assure the compiler that you really do intend this nonportable conversion): unsig...
2015-03-20, 1160👍, 0💬

How do I create a directory? How do I remove a directory (and its contents)?
How do I create a directory? How do I remove a directory (and its contents)? If your operating system supports these services, they are likely to be provided in C via functions named mkdir and rmdir. Removing a directory's contents as well will require listing them and calling remove . If you don't ...
2015-04-01, 1159👍, 0💬

How can I allocate arrays or structures bigger than 64K?
How can I allocate arrays or structures bigger than 64K? A reasonable computer ought to give you transparent access to all available memory. If you're not so lucky, you'll either have to rethink your program's use of memory, or use various system-specific techniques. 64K is (still) a pretty big chun...
2015-03-30, 1159👍, 0💬

I am appalled that the ANSI Standard leaves so many issues undefined ...
I'm appalled that the ANSI Standard leaves so many issues undefined. Isn't a Standard's whole job to standardize these things? It has always been a characteristic of C that certain constructs behaved in whatever way a particular compiler or a particular piece of hardware chose to implement them. Thi...
2015-11-18, 1158👍, 0💬

What does it mean when the linker says that _end is undefined?
What does it mean when the linker says that _end is undefined? That message is a quirk of the old Unix linkers. You get an error about _end being undefined only when other symbols are undefined, too--fix the others, and the error about _end will disappear.
2015-07-06, 1158👍, 0💬

<< < 5 6 7 8 9 10 11 12 13 14 15 > >>   Sort: Date