<< < 161 162 163 164 165 166 167 168 169 170 171 > >>   Sort: Date

Why dont C comments nest?
Why don't C comments nest? How am I supposed to comment out code containing comments? Are comments legal inside quoted strings? A: C comments don't nest mostly because PL/I's comments, which C's are borrowed from, don't either. Therefore, it is usually better to ``comment out'' large sections of cod...
2015-01-30, 1272👍, 0💬

Are the outer parentheses in return statements really optional?
Are the outer parentheses in return statements really optional? Yes. Long ago, in the early days of C, they were required, and just enough people learned C then, and wrote code which is still in circulation, that the notion that they might still be required is widespread. (As it happens, parentheses...
2015-02-02, 1271👍, 0💬

How can I read in an object file and jump to locations in it?
How can I read in an object file and jump to locations in it? You want a dynamic linker or loader. It may be possible to malloc some space and read in object files, but you have to know an awful lot about object file formats, relocation, etc., and this approach can't work if code and data reside in ...
2015-03-09, 1270👍, 0💬

Is it legal to pass a null pointer as the first argument to realloc? Why would you want to?
Is it legal to pass a null pointer as the first argument to realloc? Why would you want to? ANSI C sanctions this usage (and the related realloc(..., 0), which frees), although several earlier implementations do not support it, so it may not be fully portable. Passing an initially-null pointer to re...
2016-03-16, 1268👍, 0💬

How can I generate floating-point random numbers?
How can I generate floating-point random numbers? drand48 is a Unix System V routine which returns floating point random numbers (presumably with 48 bits of precision) in the half-open interval [0, 1). (Its companion seed routine is srand48; neither is in the C Standard.) It's easy to write a low-pr...
2015-07-22, 1268👍, 0💬

I had a frustrating problem which turned out to be caused by the line ....
I had a frustrating problem which turned out to be caused by the line printf("%d", n); where n was actually a long int. I thought that ANSI function prototypes were supposed to guard against argument type mismatches like this. A:When a function accepts a variable number of arguments, its prototype d...
2016-01-11, 1266👍, 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, 1266👍, 0💬

I am having trouble with a Turbo C program which crashes
I'm having trouble with a Turbo C program which crashes and says something like ``floating point formats not linked.'' Some compilers for small machines, including Turbo C (and Ritchie's original PDP-11 compiler), leave out certain floating point support if it looks like it will not be needed. In pa...
2015-06-19, 1265👍, 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, 1265👍, 0💬

If the assignment operator were ...
If the assignment operator were :=, wouldn't it then be harder to accidentally write things like if(a = b) ? A: Yes, but it would also be just a little bit more cumbersome to type all of the assignment statements which a typical program contains. In any case, it's really too late to be worrying abou...
2015-01-26, 1265👍, 0💬

Each time I run my program, I get the same sequence of numbers back from rand
Each time I run my program, I get the same sequence of numbers back from rand It's a characteristic of most pseudo-random number generators (and a defined property of the C library rand) that they always start with the same number and go through the same sequence. (Among other things, a bit of predi...
2015-07-29, 1264👍, 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, 1264👍, 0💬

Can I declare main as void, to shut off these annoying ....
Can I declare main as void, to shut off these annoying ``main returns no value'' messages? No. main must be declared as returning an int, and as taking either zero or two arguments, of the appropriate types. If you're calling exit() but still getting warnings, you may have to insert a redundant retu...
2015-12-20, 1263👍, 0💬

I a'm getting strange syntax errors inside lines I have ifdeffed out.
I a'm getting strange syntax errors inside lines I have ifdeffed out. Under ANSI C, the text inside a ``turned off'' #if, #ifdef, or #ifndef must still consist of ``valid preprocessing tokens.'' This means that the characters " and ' must each be paired just as in real C code, and the pairs mustn't ...
2016-01-29, 1262👍, 0💬

Why isnt any of this standardized in C? Any real program has to do some of these things.
Why isnt any of this standardized in C? Any real program has to do some of these things. Actually, some standardization has occurred along the way. In the beginning, C did not have a standard library at all; programmers always had to ``roll their own'' utility routines. After several abortive attemp...
2015-02-27, 1261👍, 0💬

What is the ANSI C Standard?
What is the ANSI C Standard? In 1983, the American National Standards Institute (ANSI) commissioned a committee, X3J11, to standardize the C language. After a long, arduous process, including several widespread public reviews, the committee's work was finally ratified as ANS X3.159-1989 on December ...
2016-01-15, 1260👍, 0💬

How can I write data files which can be read on other machines with different word size, byte order, or floating point formats?
How can I write data files which can be read on other machines with different word size, byte order, or floating point formats? The most portable solution is to use text files (usually ASCII), written with fprintf and read with fscanf or the like. (Similar advice also applies to network protocols.) ...
2015-02-23, 1258👍, 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, 1257👍, 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, 1257👍, 0💬

Should I use symbolic names like TRUE and FALSE for Boolean constants, or plain 1 and 0?
Should I use symbolic names like TRUE and FALSE for Boolean constants, or plain 1 and 0? It's your choice. Preprocessor macros like TRUE and FALSE (and, of course, NULL) are used for code readability, not because the underlying values might ever change. It's a matter of style, not correctness, wheth...
2016-02-29, 1256👍, 0💬

How do I get an accurate error status return from system on MS-DOS?
How do I get an accurate error status return from system on MS-DOS? You can't; COMMAND.COM doesn't tend to provide one. If you don't need COMMAND.COM's services (i.e. if you're just trying to invoke a simple program, without I/O redirection and such) try one of the spawn routines, instead.
2015-03-16, 1256👍, 0💬

How can I call system when parameters (filenames, etc.) of the executed command arent known until run time?
How can I call system when parameters (filenames, etc.) of the executed command arent known until run time? Just use sprintf (or perhaps strcpy and strcat) to build the command string in a buffer, then call system with that buffer. (Make sure the buffer is allocated with enough space; Here is a cont...
2015-03-18, 1255👍, 0💬

Having dynamically allocated an array , can I change its size?
Having dynamically allocated an array , can I change its size? Yes. This is exactly what realloc is for. Given a region of malloced memory its size can be changed using code like: dynarray = realloc(dynarray, 20 * sizeof(int)); Note that realloc may not always be able to enlarge memory regions in-pl...
2016-03-21, 1254👍, 0💬

Why cant I pass a char to a function which expects a const char ?
Why cant I pass a char to a function which expects a const char ? You can use a pointer-to-T (for any type T) where a pointer-to-const-T is expected. However, the rule (an explicit exception) which permits slight mismatches in qualified pointer types is not applied recursively, but only at the top l...
2016-01-04, 1254👍, 0💬

<< < 161 162 163 164 165 166 167 168 169 170 171 > >>   Sort: Date