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

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, 1437👍, 0💬

Why does the ANSI Standard place limits on the length and case-significance of external identifiers?
Why does the ANSI Standard place limits on the length and case-significance of external identifiers? The problem is linkers which are under control of neither the ANSI/ISO Standard nor the C compiler developers on the systems which have them. The limitation is only that identifiers be significant in...
2015-12-04, 1437👍, 0💬

Which of the following is the C# escape character for Null?
Which of the following is the C# escape character for Null? Which of the following is the C# escape character for Null? * \n * \0 * \f * \v \0
2014-08-06, 1436👍, 0💬

What is the difference between these initializations? ....
What is the difference between these initializations? char a[] = "string literal"; char *p = "string literal"; My program crashes if I try to assign a new value to p[i]. A string literal (the formal term for a double-quoted string in C source) can be used in two slightly different ways: 1. As the in...
2016-03-09, 1434👍, 0💬

How do I set variables to, or test for IEEE NaN?
How do I set variables to, or test for IEEE NaN (``Not a Number'') and other special values? Many systems with high-quality IEEE floating-point implementations provide facilities (e.g. predefined constants, and functions like isnan(), either as nonstandard extensions in &lt;math.h> or perhaps in...
2015-06-21, 1431👍, 0💬

Suggesting that there can be 62 seconds in a minute?
Suggesting that there can be 62 seconds in a minute? Q: Why can tm_sec in the tm structure range from 0 to 61, suggesting that there can be 62 seconds in a minute? A: That's actually a buglet in the Standard. There can be 61 seconds in a minute during a leap second. It's possible for there to be two...
2015-01-05, 1418👍, 0💬

What is the right type to use for Boolean values in C? ....
What is the right type to use for Boolean values in C? Is there a standard type? Should I use #defines or enums for the true and false values? Traditionally, C did not provide a standard Boolean type, partly and partly to allow the programmer to make the appropriate space/time tradeoff. (Using an in...
2016-03-02, 1417👍, 0💬

How can I get the numeric value corresponding to a character? ....
How can I get the numeric value (i.e. ASCII or other character set code) corresponding to a character, or vice versa? In C, characters are represented by small integers corresponding to their values in the machine's character set. Therefore, you don't need a conversion function: if you have the char...
2016-03-07, 1412👍, 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, 1409👍, 0💬

Why doesnt C have nested functions?
Why doesnt C have nested functions? It's not trivial to implement nested functions such that they have the proper access to local variables in the containing function(s), so they were deliberately left out of C as a simplification. (gcc does allow them, as an extension.) For many potential uses of n...
2015-01-14, 1404👍, 0💬

Is there a way to have non-constant case labels (i.e. ranges or arbitrary expressions)?
Is there a way to have non-constant case labels (i.e. ranges or arbitrary expressions)? No. The switch statement was originally designed to be quite simple for the compiler to translate, therefore case labels are limited to single, constant, integral expressions. You can attach several case labels t...
2015-02-02, 1403👍, 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, 1399👍, 0💬

Why doesn't C have an exponentiation operator?
Why doesn't C have an exponentiation operator? One reason is probably that few processors have a built-in exponentiation instruction. C has a pow function (declared in &lt;math.h>) for performing exponentiation, although explicit multiplication is usually better for small positive integral expon...
2015-06-24, 1399👍, 0💬

Why doesnt strcat work? ....
Why doesn't strcat(string, '!'); work? There is a very real difference between characters and strings, and strcat concatenates strings. A character constant like '!' represents a single character. A string literal between double quotes usually represents multiple characters. A string literal like "!...
2016-03-14, 1393👍, 0💬

How can I direct output to the printer?
How can I direct output to the printer? Under Unix, either use popen to write to the lp or lpr program, or perhaps open a special file like /dev/lp. Under MS-DOS, write to the (nonstandard) predefined stdio stream stdprn, or open the special files PRN or LPT1. Under some circumstances, another (and ...
2015-04-22, 1390👍, 0💬

How can I specify a variable width in a scanf format string?
How can I specify a variable width in a scanf format string? You can't; an asterisk in a scanf format string means to suppress assignment. You may be able to use ANSI stringizing and string concatenation to construct a constant format specifier based on a preprocessor macro containing the desired wi...
2015-10-26, 1389👍, 0💬

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, 1387👍, 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, 1385👍, 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, 1384👍, 0💬

How can I recover the file name given an open stream or file descriptor?
How can I recover the file name given an open stream or file descriptor? This problem is, in general, insoluble. Under Unix, for instance, a scan of the entire disk (perhaps involving special permissions) would theoretically be required, and would fail if the descriptor were connected to a pipe or r...
2015-04-10, 1384👍, 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, 1382👍, 0💬

How can I manipulate individual bits??
How can I manipulate individual bits?? Bit manipulation is straightforward in C, and commonly done. To extract (test) a bit, use the bitwise AND (&amp;) operator, along with a bit mask representing the bit(s) you're interested in: value &amp; 0x04 To set a bit, use the bitwise OR (| or |=) o...
2015-02-20, 1380👍, 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, 1379👍, 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, 1378👍, 0💬

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