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

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, 1328👍, 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, 1326👍, 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, 1321👍, 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, 1316👍, 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, 1315👍, 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, 1313👍, 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, 1307👍, 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, 1306👍, 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, 1299👍, 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, 1298👍, 0💬

Are pointers really faster than arrays?
Are pointers really faster than arrays? How much do function calls slow things down? Is ++i faster than i = i + 1? Precise answers to these and many similar questions depend of course on the processor and compiler in use. If you simply must know, you'll have to time test programs carefully. (Often t...
2015-02-09, 1298👍, 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, 1297👍, 0💬

The predefined constant M_PI seems to be missing from my machines copy of math.h.
The predefined constant M_PI seems to be missing from my machines copy of math.h. That constant (which is apparently supposed to be the value of pi, accurate to the machine's precision), is not standard; in fact a standard-conforming copy of should not #define a symbol M_PI. If you need pi, you'll h...
2015-06-24, 1296👍, 0💬

What is a good data structure to use for storing lines of text?
What's a good data structure to use for storing lines of text? I started to use fixed-size arrays of arrays of char, but they're just too restrictive. One good way of doing this is with a pointer (simulating an array) to a set of pointers (each simulating an array) of char. This data structure is so...
2015-02-25, 1295👍, 0💬

So can I query the malloc package to find out how big an allocated block is?
So can I query the malloc package to find out how big an allocated block is? Unfortunately, there is no standard or portable way. (Some compilers provide nonstandard extensions.) If you need to know, you'll have to keep track of it yourself.
2016-03-24, 1293👍, 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, 1293👍, 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, 1291👍, 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, 1290👍, 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, 1290👍, 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, 1288👍, 0💬

How can I open files mentioned on the command line, and parse option flags?
How can I open files mentioned on the command line, and parse option flags? Here is a skeleton which implements a traditional Unix-style argv parse, handling option flags beginning with -, and optional filenames. (The two flags accepted by this example are -a and -b; -b takes an argument.) #include ...
2015-03-11, 1286👍, 0💬

What is assert and when would I use it?
What is assert and when would I use it? It is a macro, defined in &lt;assert.h>, for testing ``assertions''. An assertion essentially documents an assumption being made by the programmer, an assumption which, if violated, would indicate a serious programming error. For example, a function which ...
2015-01-12, 1284👍, 0💬

How can I call FORTRAN?
How can I call FORTRAN? Q: How can I call FORTRAN (C++, BASIC, Pascal, Ada, LISP) functions from C? (And vice versa?) A: The answer is entirely dependent on the machine and the specific calling sequences of the various compilers in use, and may not be possible at all. Read your compiler documentatio...
2015-01-12, 1283👍, 0💬

What is hashing?
What is hashing? Hashing is the process of mapping strings to integers, usually in a relatively small range. A ``hash function'' maps a string (or some other data structure) to a bounded number (the ``hash bucket'') which can more easily be used as an index in an array, or for performing repeated co...
2015-01-07, 1282👍, 0💬

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