![]()
C and C++ |
Home —» C and C++> —» brackets and braces C Tutorial: Brackets and Braces Some of the characters C uses aren't standard on mainframe terminals. If you're using a 3270-terminal emulator, make sure your settings will handle all the characters below. You need to be able to view them and also type them in and have the correct hex values generated. You might need to adjust the font, terminal type, keyboard mapping or code page. Using trigraphs is also a alternative, in which case you'll need to check the compiler options to make sure they're enabled. Some of these special characters have two hex versions. For example, square brackets may also be represented by 0xBA and 0xBB, and the vertical bar (OR) may be 0x6A. The compiler will generate an 'invalid character' error message if it can't interpret a symbol. Tip: It's easier to spot syntax errors if C code displays in color. To turn colors on, enter HILITE C on the TSO/E command line. The result should look like this: Square brackets are used to specify an array member. Braces, also called curly brackets, are used to enclose compound statements. C is a freeform language: the compiler ignores blanks, except to distinguish between two-character symbols such as /* (comment) and two single characters such as / (divide by) followed by * (asterisk). However, there are four common indentation schemes to make life easier for the human programmer: Whitesmiths: This is the scheme used in the example above. The left and right braces are placed vertically above each other, indented from the keyword. Kernighan & Ritchie: This is the standard used in text books, because it uses the fewest lines. It's also the hardest to read and debug, because the braces don't line up. K&R is the de facto standard for Java.
Allman: This is similar to Whitesmiths, except that the braces aren't indented:
GNU: This is similar to Whitesmiths, except that the enclosed statement(s) are indented further than the braces. That can force a long line to wrap if you're only using the standard 72-column ISPF screen:
Sticking to one consistent scheme makes it is easier to locate mismatched braces by using TSO's exclude and find commands: X ALL If all the braces are on a line by themselves, with the right brace placed vertically beneath the left brace, you can exclude the matching pairs until you find the unmatched brace. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TOP OF PAGE | One of the main causes of the fall of the Roman Empire was that, lacking zero, they had no way to indicate successful termination of their C programs. (Robert Firth) |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||