<< < 7 8 9 10 11 12 13 14 15 16 17 > >>

What is the best style for code layout in C?
What is the best style for code layout in C? While providing the example most often copied, also supply a good excuse for disregarding it: The position of braces is less important, although people hold passionate beliefs. We have chosen one of several popular styles. Pick a style that suits you, the...
2015-05-18, 1118👍, 0💬

How should functions be apportioned among source files?
How should functions be apportioned among source files? Usually, related functions are put together in one file. Sometimes (as when developing libraries) it is appropriate to have exactly one source file (and, consequently, one object module) per independent function. Other times, and especially for...
2015-05-18, 1062👍, 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, 1193👍, 0💬

Why do some people write if(0 == x) instead of if(x == 0)?
Why do some people write if(0 == x) instead of if(x == 0)? It's a trick to guard against the common error of writing if(x = 0) If you're in the habit of writing the constant before the ==, the compiler will complain if you accidentally type if(0 = x) Evidently it can be easier for some people to rem...
2015-05-15, 1115👍, 0💬

I came across some code that puts a (void) cast before each call to printf. Why?
I came across some code that puts a (void) cast before each call to printf. Why? printf does return a value (the number of characters printed, or an error code), though few programs bother to check the return values from each call. Since some compilers (and lint) will warn about discarded return val...
2015-05-13, 1140👍, 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, 1159👍, 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...
2015-05-11, 1089👍, 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, 1162👍, 0💬

Some people say that gotos are evil and that I should never use them. Isnt that a bit extreme
Some people say that gotos are evil and that I should never use them. Isnt that a bit extreme rogramming style, like writing style, is somewhat of an art and cannot be codified by inflexible rules, although discussions about style often seem to center exclusively around such rules. In the case of th...
2015-05-08, 1088👍, 0💬

People always say that good style is important
People always say that good style is important, but when they go out of their way to use clear techniques and make their programs readable, they seem to end up with less efficient programs. Since efficiency is so important, isn't it necessary to sacrifice some style and readability? It's true that g...
2015-05-06, 1104👍, 0💬

I just typed in this program, and it is acting strangely. Can you see anything wrong with it?
I just typed in this program, and it is acting strangely. Can you see anything wrong with it? See if you can run lint first (perhaps with the -a, -c, -h, -p or other options ). Many C compilers are really only half-compilers, taking the attitude that it's not their problem if you didn't say what you...
2015-05-06, 1079👍, 0💬

How can I shut off the warning ...
How can I shut off the ``warning: possible pointer alignment problem'' message which lint gives me for each call to malloc? A modern lint shouldn't be complaining about this. Once upon a time, lint did not and could not know that malloc ``returns a pointer to space suitably aligned for storage of an...
2015-05-05, 1100👍, 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, 1151👍, 0💬

Dont ANSI function prototypes render lint obsolete?
Dont ANSI function prototypes render lint obsolete? Not really. First of all, prototypes work only if they are present and correct; an inadvertently incorrect prototype is worse than useless. Secondly, lint checks consistency across multiple source files, and checks data declarations as well as func...
2015-05-01, 1106👍, 0💬

I need code to parse and evaluate expressions.
I need code to parse and evaluate expressions. Two available packages are ``defunc,'' posted to comp.sources.misc in December, 1993 (V41 i32,33), to alt.sources in January, 1994, and available from sunsite.unc.edu in pub/packages/development/libra ries/defunc-1.3.tar.Z,and ``parse,'' at lamont.ldgo....
2015-05-01, 1033👍, 0💬

How can I read a single character from the keyboard without waiting for the RETURN key?
How can I read a single character from the keyboard without waiting for the RETURN key? How can I stop characters from being echoed on the screen as they're typed? Alas, there is no standard or portable way to do these things in C. Concepts such as screens and keyboards are not even mentioned in the...
2015-04-29, 1636👍, 0💬

How can I find out if there are characters available for reading?
How can I find out if there are characters available for reading (and if so, how many)? Alternatively, how can I do a read that will not block if there are no characters available? These, too, are entirely operating-system-specific. Some versions of curses have a nodelay function. Depending on your ...
2015-04-29, 1083👍, 0💬

How can I display a percentage-done indication that updates itself in place, or show one of those twirling baton progress indica
How can I display a percentage-done indication that updates itself in place, or show one of those twirling baton progress indicators? These simple things, at least, you can do fairly portably. Printing the character '\r' will usually give you a carriage return without a line feed, so that you can ov...
2015-04-27, 1228👍, 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💬

How can I make it pause before closing the program output window?
I'm compiling some test programs on a windows-based system, and the windows containing my program's output are closing so quickly after my program calls exit that I can't see the output. How can I make it pause before closing? After wondering why the author of your compiler's run-time system didn't ...
2015-04-24, 1129👍, 0💬

How do I read the arrow keys? What about function keys?
How do I read the arrow keys? What about function keys? Terminfo, some versions of termcap, and some versions of curses have support for these non-ASCII keys. Typically, a special key sends a multicharacter sequence (usually beginning with ESC, '\033'); parsing these can be tricky. (curses will do t...
2015-04-24, 1175👍, 0💬

How can I do serial comm port I O?
How can I do serial (``comm'') port I/O? It's system-dependent. Under Unix, you typically open, read, and write a device file in /dev, and use the facilities of the terminal driver to adjust its characteristics.Under MS-DOS, you can use the predefined stream stdaux, or a special file like COM1, or s...
2015-04-22, 1140👍, 0💬

How can I direct output to the printer?
How can I direct output to the printer? Under Unix, either use popen to write to the lp or lpr program, or perhaps open a special file like /dev/lp. Under MS-DOS, write to the (nonstandard) predefined stdio stream stdprn, or open the special files PRN or LPT1. Under some circumstances, another (and ...
2015-04-22, 1225👍, 0💬

How do I send escape sequences to control a terminal or other device?
How do I send escape sequences to control a terminal or other device? If you can figure out how to send characters to the device at all , it's easy enough to send escape sequences. In ASCII, the ESC code is 033 (27 decimal), so code like fprintf(ofd, "\033[J"); sends the sequence ESC [ J . Some prog...
2015-04-20, 1314👍, 0💬

<< < 7 8 9 10 11 12 13 14 15 16 17 > >>