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

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

Can I use an ifdef in a #define line ...
Can I use an #ifdef in a #define line, to define something two different ways, like this? #define a b \ #ifdef whatever c d #else e f g #endif No. You can't ``run the preprocessor on itself,'' so to speak. What you can do is use one of two completely separate #define lines, depending on the #ifdef s...
2016-02-03, 1382👍, 0💬

Now I am trying to sort an array of structures with qsort ...
Now I'm trying to sort an array of structures with qsort. My comparison function takes pointers to structures, but the compiler complains that the function is of the wrong type for qsort. How can I cast the function pointer to shut off the warning? The conversions must be in the comparison function,...
2015-08-10, 1381👍, 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, 1381👍, 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, 1380👍, 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, 1380👍, 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, 1380👍, 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, 1379👍, 0💬

What does it really mean for a program to be legal or `valid or ``conforming?
What does it really mean for a program to be legal or `valid or ``conforming? Simply stated, the Standard talks about three kinds of conformance: conforming programs, strictly conforming programs, and conforming implementations. A conforming program is one that is accepted by a conforming implementa...
2015-11-23, 1379👍, 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, 1378👍, 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, 1378👍, 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, 1377👍, 0💬

How can I handle floating-point exceptions gracefully?
How can I handle floating-point exceptions gracefully? On many systems, you can define a function matherr which will be called when there are certain floating-point errors, such as errors in the math routines in . You may also be able to use signal to catch SIGFPE.
2015-06-21, 1377👍, 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, 1377👍, 0💬

Wy compiler is rejecting the simplest possible test programs ...
My compiler is rejecting the simplest possible test programs, with all kinds of syntax errors. It's complaining about the first line of main(int argc, char **argv) { return 0; } Perhaps it is a pre-ANSI compiler, unable to accept function prototypes and the like. If you don't have access to an ANSI ...
2015-12-02, 1376👍, 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, 1374👍, 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, 1374👍, 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, 1374👍, 0💬

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