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

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, 1271👍, 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, 1270👍, 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, 1269👍, 0💬

People seem to make a point of distinguishing between ...
People seem to make a point of distinguishing between implementation-defined, unspecified, and undefined behavior. What do these mean? First of all, all three of these represent areas in which the C Standard does not specify exactly what a particular construct, or a program which uses it, must do. T...
2015-11-23, 1269👍, 0💬

Where can I get an ANSI-compatible lint?
Where can I get an ANSI-compatible lint? Products called PC-Lint and FlexeLint are available from Gimpel Software. The Unix System V release 4 lint is ANSI-compatible, and is available separately (bundled with other C tools) from UNIX Support Labs or from System V resellers. Another ANSI-compatible ...
2015-05-05, 1269👍, 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, 1269👍, 0💬

What is Hungarian Notation? Is it worthwhile?
What is Hungarian Notation? Is it worthwhile? Hungarian Notation is a naming convention, invented by Charles Simonyi, which encodes information about a variable's type (and perhaps its intended use) in its name. It is well-loved in some circles and roundly castigated in others. Its chief advantage i...
2015-05-08, 1268👍, 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, 1268👍, 0💬

Why doesnt the call scanf work?
Why doesn't the call scanf("%d", i) work? The arguments you pass to scanf must always be pointers: for each value converted, scanf ``returns'' it by filling in one of the locations you've passed pointers to. To fix the fragment above, change it to scanf("%d", &i) .
2015-11-02, 1267👍, 0💬

How can I read a directory in a C program?
How can I read a directory in a C program? See if you can use the opendir and readdir functions, which are part of the POSIX standard and are available on most Unix variants. Implementations also exist for MS-DOS, VMS, and other systems. (MS-DOS also has FINDFIRST and FINDNEXT routines which do esse...
2015-04-01, 1267👍, 0💬

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

What does the message Automatic aggregate intialization is an ANSI feature mean?
What does the message Automatic aggregate intialization is an ANSI feature'' mean? My compiler is complaining about valid ANSI code. Messages like these are typically emitted by pre-ANSI compilers which have been upgraded just enough to detect (but not properly translate) new C features which were i...
2015-11-30, 1262👍, 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, 1262👍, 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, 1261👍, 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, 1261👍, 0💬

What should malloc0 do? Return a null pointer or a pointer to 0 bytes?
What should malloc0 do? Return a null pointer or a pointer to 0 bytes? The ANSI/ISO Standard says that it may do either; the behavior is implementation-defined Portable code must either take care not to call malloc(0), or be prepared for the possibility of a null return.
2015-12-04, 1260👍, 0💬

Here is a neat trick for checking whether two strings are equal
Q: Here's a neat trick for checking whether two strings are equal: if(!strcmp(s1, s2)) Is this good style? It is not particularly good style, although it is a popular idiom. The test succeeds if the two strings are equal, but the use of ! (``not'') suggests that it tests for inequality. Another opti...
2015-05-15, 1260👍, 0💬

What is the difference between memcpy and memmove?
What is the difference between memcpy and memmove? memmove offers guaranteed behavior if the memory regions pointed to by the source and destination arguments overlap. memcpy makes no such guarantee, and may therefore be more efficiently implementable. When in doubt, it's safer to use memmove. It se...
2015-12-07, 1259👍, 0💬

I am sure I've got the trig functions declared correctly, but they are still giving me wrong answers.
I am sure I've got the trig functions declared correctly, but they are still giving me wrong answers. You weren't handing them angles in degrees, were you? C's trig functions (like FORTRAN's and most other languages) accept angles in radians. The conversion from degrees to radians is simple enough: ...
2015-06-29, 1258👍, 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, 1256👍, 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, 1256👍, 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, 1253👍, 0💬

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