<< < 2 3 4 5 6 7 8 9 10 11 12 > >>   Sort: Date

Is C a great language, or what?
Is C a great language, or what? Where else could you write something like a+++++b ? A: Well, you can't meaningfully write it in C, either. The rule for lexical analysis is that at each point during a straightforward left-to-right scan, the longest possible token is determined, without regard to whet...
2015-01-26, 1215👍, 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, 1213👍, 0💬

How can I call a function with an argument list built up at run time?
How can I call a function with an argument list built up at run time? There is no guaranteed or portable way to do this. Instead of an actual argument list, you might consider passing an array of generic (void *) pointers. The called function can then step through the array, much like main() might s...
2015-06-03, 1213👍, 0💬

How can I clear the screen? How can I print text in color? How can I move the cursor to a specific x, y position?
How can I clear the screen? How can I print text in color? How can I move the cursor to a specific x, y position? Such things depend on the terminal type (or display) you're using. You will have to use a library such as termcap, terminfo, or curses, or some system-specific routines, to perform these...
2015-04-27, 1212👍, 0💬

Does C have an equivalent to Pascals with statement?
Does C have an equivalent to Pascals with statement? No. The way in C to get quick and easy access to the fields of a structure is to declare a little local structure pointer variable (which, it must be admitted, is not quite as notationally convenient as a with statement and doesn't save quite as m...
2015-01-14, 1212👍, 0💬

Was 2000 a leap year?
Was 2000 a leap year? Q: Is (year % 4 == 0) an accurate test for leap years? (Was 2000 a leap year?) A: No, it's not accurate (and yes, 2000 was a leap year). The actual rules for the present Gregorian calendar are that leap years occur every four years, but not every 100 years, except that they do ...
2015-01-05, 1212👍, 0💬

So what could go wrong? Are there really any systems where void main doesnt work?
So what could go wrong? Are there really any systems where void main doesnt work? It has been reported that programs using void main() and compiled using BC++ 4.5 can crash. Some compilers (including DEC C V4.1 and gcc with certain warnings enabled) will complain about void main().
2015-12-18, 1211👍, 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, 1211👍, 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, 1209👍, 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, 1209👍, 0💬

I need a sort of an approximate strcmp routine ...
I need a sort of an approximate strcmp routine ... Q: I need a sort of an ``approximate'' strcmp routine, for comparing two strings for close, but not necessarily exact, equality. A:Some nice information and algorithms having to do with approximate string matching, as well as a useful bibliography, ...
2015-01-09, 1208👍, 0💬

I have been replacing multiplications and divisions with shift operators, because shifting is more efficient.
I have been replacing multiplications and divisions with shift operators, because shifting is more efficient. This is an excellent example of a potentially risky and usually unnecessary optimization. Any compiler worthy of the name can replace a constant, power-of-two multiplication with a left shif...
2015-02-09, 1207👍, 0💬

Is exit status truly equivalent to returning the same status from main?
Is exit status truly equivalent to returning the same status from main? Yes and no. The Standard says that a return from the initial call to main is equivalent to calling exit. However, a return from main cannot be expected to work if data local to main might be needed during cleanup;A few very old,...
2015-12-16, 1205👍, 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, 1205👍, 0💬

Is there a way to switch on strings?
Is there a way to switch on strings? Not directly. Sometimes, it's appropriate to use a separate function to map strings to integer codes, and then switch on those: #define CODE_APPLE 1 #define CODE_ORANGE 2 #define CODE_NONE 0 switch(classifyfunc(string)) { case CODE_APPLE: ... case CODE_ORANGE: .....
2015-02-04, 1204👍, 0💬

Why do some versions of toupper act strangely if given an upper-case letter?
Why do some versions of toupper act strangely if given an upper-case letter? Why does some code call islower before toupper? In earlier times, toupper was a function-like preprocessor macro and was defined to work only on lower-case letters; it misbehaved if applied to digits, punctuation, or letter...
2015-08-17, 1202👍, 0💬

How can I write a generic macro to swap two values?
How can I write a generic macro to swap two values? There is no good answer to this question. If the values are integers, a well-known trick using exclusive-OR could perhaps be used, but it will not work for floating-point values or pointers, or if the two values are the same variable. If the macro ...
2016-02-24, 1201👍, 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, 1200👍, 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, 1199👍, 0💬

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

Does C have circular shift operators?
Does C have circular shift operators? No. (Part of the reason why is that the sizes of C's types aren't precisely defined----but a circular shift makes most sense when applied to a word of a particular known size.) You can implement a circular shift using two regular shifts and a bitwise OR: (x &...
2015-01-28, 1196👍, 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, 1195👍, 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, 1194👍, 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, 1194👍, 0💬

<< < 2 3 4 5 6 7 8 9 10 11 12 > >>   Sort: Date