add directory study
BIN
study/CLK-5.0.1-WithCover.pdf
Normal file
BIN
study/ECLK-5.0.1-WithCover.pdf
Normal file
BIN
study/PM_Examples.zip
Normal file
86
study/Ref-docs/ASCII/ANSI Escape Sequences.htm
Normal file
@@ -0,0 +1,86 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
||||
<!-- saved from url=(0038)http://www.vmunix.com/~gabor/ansi.html -->
|
||||
<HTML><HEAD><TITLE>ANSI Escape Sequences</TITLE>
|
||||
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
|
||||
<META content="ansi escape sequence" name=keywords>
|
||||
<META content="MSHTML 5.00.3502.5390" name=GENERATOR></HEAD>
|
||||
<BODY><PRE>Esc Seq Function
|
||||
======= ==========================================
|
||||
|
||||
E[nA move cursor up n lines
|
||||
|
||||
E[nB move cursor down n lines
|
||||
|
||||
E[nC move cursor right n characters
|
||||
|
||||
E[nD move cursor left n characters
|
||||
|
||||
E[n` move cursor to character position n
|
||||
|
||||
E[na move cursor right n characters
|
||||
|
||||
E[nd move cursor to line n
|
||||
|
||||
E[ne move cursor down n lines
|
||||
|
||||
E[nF move cursor to start of line, n lines up
|
||||
|
||||
E[nE move cursor to start of line, n lines down
|
||||
|
||||
E[y;xH Move cursor to x, y E[H homes cursor
|
||||
|
||||
E[y;xf Move cursor to x, y
|
||||
|
||||
E[nZ Move cursor back n tab stops
|
||||
|
||||
E[nL Insert n blank lines
|
||||
|
||||
E[n@ Insert n blank characters
|
||||
|
||||
E[nM Delete n lines
|
||||
|
||||
E[nP Delete n characters
|
||||
|
||||
E[nJ Erase part or all of display:
|
||||
n = 0 from cursor to end of display,
|
||||
n = 1 from begin of display to cursor,
|
||||
n = 2 entire display.
|
||||
|
||||
E[nK Erase part or all of line:
|
||||
n = 0 from cursor to end of line,
|
||||
n = 1 from begin of line to cursor,
|
||||
n = 2 entire line.
|
||||
|
||||
E[nX Erase n characters
|
||||
|
||||
E[nS Scroll display n lines up (forward)
|
||||
|
||||
E[nT Scroll display n lines down (reverse)
|
||||
|
||||
|
||||
E[nm Set character attributes:
|
||||
n = 0 normal attribute (all off)
|
||||
n = 1 bold
|
||||
n = 4 underscore
|
||||
n = 5 blink
|
||||
n = 7 reverse
|
||||
n = 3X set foreground color
|
||||
n = 4X set background color
|
||||
|
||||
X = 0 black X = 1 red
|
||||
X = 2 green X = 3 brown
|
||||
X = 4 blue X = 5 magenta
|
||||
X = 6 cyan X = 7 white
|
||||
|
||||
You can set more than one thing by separating them with a
|
||||
semi-colon. eg. E[0;1;33;40m
|
||||
|
||||
E[s Save cursor position
|
||||
|
||||
E[u Restore saved cursor position
|
||||
|
||||
E means 0X1B
|
||||
|
||||
if n is 0 then it can also be left off
|
||||
E[0J == E[J
|
||||
</PRE></BODY></HTML>
|
||||
BIN
study/Ref-docs/ASCII/ASCII-TABLE.doc
Normal file
781
study/Ref-docs/ASCII/ansicode.txt
Normal file
@@ -0,0 +1,781 @@
|
||||
Summary of ANSI standards for ASCII terminals Joe Smith, 18-May-84
|
||||
|
||||
Contents:
|
||||
1. Overview and Definitions
|
||||
2. General rules for interpreting an ESCape Sequence
|
||||
3. General rules for interpreting a Control Sequence
|
||||
4. C0 and C1 control codes in numeric order
|
||||
5. Two and three-character ESCape Sequences in numeric order
|
||||
6. Control Sequences in numeric order
|
||||
7. VT100 emulation requirements
|
||||
|
||||
The VT100 USER GUIDE and ANSI standard X3.64-1979 both list the ANSI ESCape
|
||||
sequences in alphabetic order by mnemonic, but do not have a have a cross
|
||||
reference in order by ASCII code. This paper lists the combination of all
|
||||
definitions from the three ANSI standards in numeric order. For a description
|
||||
of the advantages of using these standards, see the article "Toward
|
||||
Standardized Video Terminals" in the April-1984 issue of BYTE magazine.
|
||||
|
||||
ANSI X3.4-1977 defines the 7-bit ASCII character set (C0 and G0). It was
|
||||
written in 1968, revised in 1977, and explains the decisions made in laying out
|
||||
the ASCII code. In particular, it explains why ANSI chose to make ASCII
|
||||
incompatible with EBCDIC in order to make it self-consistant.
|
||||
|
||||
ANSI X3.41-1974 introduces the idea of an 8-bit ASCII character set (C1 and G1
|
||||
in addition to the existing C0 and G0). It describes how to use the 8-bit
|
||||
features in a 7-bit environment. X3.41 defines the format of all ESCape
|
||||
sequences, but defines only the 3-character ones with a parameter character
|
||||
in the middle. These instruct the terminal how to interpret the C0, G0, C1,
|
||||
and G1 characters (such as by selecting different character-set ROMs).
|
||||
|
||||
Note: NAPLPS does videotex graphics by redefining the C1 set and
|
||||
selecting alternate G0, G1, G2, and G3 sets.
|
||||
See the February 1983 issue of BYTE magazine for details.
|
||||
|
||||
ANSI X3.64-1979 defines the remaining ESCape sequences. It defines all the C1
|
||||
control characters, and specifies that certain two-character ESCape sequences
|
||||
in the 7-bit environment are to act exactly like the 8-bit C1 control set.
|
||||
X3.64 introduces the idea of a Control-Sequence, which starts with CSI
|
||||
character, has an indefinite length, and is terminated by an alphabetic
|
||||
character. The VT100 was one of the first terminals to implement this
|
||||
standard.
|
||||
|
||||
Definitions:
|
||||
|
||||
Control Character - A single character with an ASCII code with the range
|
||||
of 000 to 037 and 200 to 237 octal, 00 to 1F and 80 to 9F hex.
|
||||
|
||||
Escape Sequence - A two or three character string staring with ESCape.
|
||||
(Four or more character strings are allowed but not defined.)
|
||||
|
||||
Control Sequence - A string starting with CSI (233 octal, 9B hex) or
|
||||
with ESCape Left-Bracket, and terminated by an alphabetic character.
|
||||
Any number of parameter characters (digits 0 to 9, semicolon, and
|
||||
question mark) may appear within the Control Sequence. The terminating
|
||||
character may be preceded by an intermediate character (such as space).
|
||||
Character classifications:
|
||||
|
||||
C0 Control 000-037 octal, 00-1F hex (G0 is 041-176 octal, 21-7E hex)
|
||||
SPACE 040+240 octal, 20+A0 hex Always and everywhere a blank space
|
||||
Intermediate 040-057 octal, 20-2F hex !"#$%&'()*+,-./
|
||||
Parameters 060-077 octal, 30-3F hex 0123456789:;<=>?
|
||||
Uppercase 100-137 octal, 40-5F hex @ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_
|
||||
Lowercase 140-176 octal, 60-7E hex `abcdefghijlkmnopqrstuvwxyz{|}~
|
||||
Alphabetic 100-176 octal, 40-7E hex (all of upper and lower case)
|
||||
Delete 177 octal, 7F hex Always and everywhere ignored
|
||||
C1 Control 200-237 octal, 80-9F hex 32 additional control characters
|
||||
G1 Displayable 241-376 octal, A1-FE hex 94 additional displayable characters
|
||||
Special 240+377 octal, A0+FF hex Same as SPACE and DELETE
|
||||
|
||||
Note that in this paper, the terms uppercase, lowercase, and alphabetics
|
||||
include more characters than just A to Z.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
General rules for interpreting an ESCape Sequence:
|
||||
|
||||
An ESCape Sequence starts with the ESC character (033 octal, 1B hex).
|
||||
The length of the ESCape Sequence depends on the character that immediately
|
||||
follows the ESCape.
|
||||
|
||||
If the next character is
|
||||
C0 control: Interpret it first, then resume processing ESCape sequence.
|
||||
Example: CR, LF, XON, and XOFF work as normal within an ESCape sequence.
|
||||
Intermediate: Expect zero or more intermediates, a parameter terminates
|
||||
a private function, an alphabetic terminates a standard sequence.
|
||||
Example: ESC ( A defines standard character set, ESC ( 0 a DEC set.
|
||||
Parameter: End of a private 2-character escape sequence.
|
||||
Example: ESC = sets special keypad mode, ESC > clears it.
|
||||
Uppercase: Translate it into a C1 control character and act on it.
|
||||
Example: ESC D does indexes down, ESC M indexes up. (CSI is special)
|
||||
Lowercase: End of a standard 2-character escape sequence.
|
||||
Example: ESC c resets the terminal.
|
||||
Delete: Ignore it, and continue interpreting the ESCape sequence
|
||||
C1 and G1: Treat the same as their 7-bit counterparts
|
||||
|
||||
Note that CSI is the two-character sequence ESCape left-bracket or the 8-bit
|
||||
C1 code of 233 octal, 9B hex. CSI introduces a Control Sequence, which
|
||||
continues until an alphabetic character is received.
|
||||
|
||||
General rules for interpreting a Control Sequence:
|
||||
|
||||
1) It starts with CSI, the Control Sequence Introducer.
|
||||
2) It contains any number of parameter characters (0123456789:;<=>?).
|
||||
3) It terminates with an alphabetic character.
|
||||
4) Intermediate characters (if any) immediately precede the terminator.
|
||||
|
||||
If the first character after CSI is one of "<=>?" (074-077 octal, 3C-3F hex),
|
||||
then Control Sequence is to be interpreted according to private standards (such
|
||||
as setting and resetting modes not defined by ANSI). The terminal should
|
||||
expect any number of numeric parameters, separated by semicolons (073 octal,
|
||||
3B hex). Only after the terminating alphabetic character is received should
|
||||
the terminal act on the Control Sequence.
|
||||
|
||||
=============================================================================
|
||||
C0 set of 7-bit control characters (from ANSI X3.4-1977).
|
||||
|
||||
Oct Hex Name * (* marks function used in DEC VT series or LA series terminals)
|
||||
--- -- - --- - --------------------------------------------------------------
|
||||
000 00 @ NUL * Null filler, terminal should ignore this character
|
||||
001 01 A SOH Start of Header
|
||||
002 02 B STX Start of Text, implied end of header
|
||||
003 03 C ETX End of Text, causes some terminal to respond with ACK or NAK
|
||||
004 04 D EOT End of Transmission
|
||||
005 05 E ENQ * Enquiry, causes terminal to send ANSWER-BACK ID
|
||||
006 06 F ACK Acknowledge, usually sent by terminal in response to ETX
|
||||
007 07 G BEL * Bell, triggers the bell, buzzer, or beeper on the terminal
|
||||
010 08 H BS * Backspace, can be used to define overstruck characters
|
||||
011 09 I HT * Horizontal Tabulation, move to next predetermined position
|
||||
012 0A J LF * Linefeed, move to same position on next line (see also NL)
|
||||
013 0B K VT * Vertical Tabulation, move to next predetermined line
|
||||
014 0C L FF * Form Feed, move to next form or page
|
||||
015 0D M CR * Carriage Return, move to first character of current line
|
||||
016 0E N SO * Shift Out, switch to G1 (other half of character set)
|
||||
017 0F O SI * Shift In, switch to G0 (normal half of character set)
|
||||
020 10 P DLE Data Link Escape, interpret next control character specially
|
||||
021 11 Q XON * (DC1) Terminal is allowed to resume transmitting
|
||||
022 12 R DC2 Device Control 2, causes ASR-33 to activate paper-tape reader
|
||||
023 13 S XOFF* (DC2) Terminal must pause and refrain from transmitting
|
||||
024 14 T DC4 Device Control 4, causes ASR-33 to deactivate paper-tape reader
|
||||
025 15 U NAK Negative Acknowledge, used sometimes with ETX and ACK
|
||||
026 16 V SYN Synchronous Idle, used to maintain timing in Sync communication
|
||||
027 17 W ETB End of Transmission block
|
||||
030 18 X CAN * Cancel (makes VT100 abort current escape sequence if any)
|
||||
031 19 Y EM End of Medium
|
||||
032 1A Z SUB * Substitute (VT100 uses this to display parity errors)
|
||||
033 1B [ ESC * Prefix to an ESCape sequence
|
||||
034 1C \ FS File Separator
|
||||
035 1D ] GS Group Separator
|
||||
036 1E ^ RS * Record Separator (sent by VT132 in block-transfer mode)
|
||||
037 1F _ US Unit Separator
|
||||
|
||||
040 20 SP * Space (should never be defined to be otherwise)
|
||||
177 7F DEL * Delete, should be ignored by terminal
|
||||
|
||||
==============================================================================
|
||||
C1 set of 8-bit control characters (from ANSI X3.64-1979)
|
||||
|
||||
Oct Hex Name * (* marks function used in DEC VT series or LA series terminals)
|
||||
--- -- - --- - --------------------------------------------------------------
|
||||
200 80 @ Reserved for future standardization
|
||||
201 81 A Reserved
|
||||
202 82 B Reserved
|
||||
203 83 C Reserved
|
||||
204 84 D IND * Index, moves down one line same column regardless of NL
|
||||
205 85 E NEL * NEw Line, moves done one line and to first column (CR+LF)
|
||||
206 86 F SSA Start of Selected Area to be sent to auxiliary output device
|
||||
207 87 G ESA End of Selected Area to be sent to auxiliary output device
|
||||
210 88 H HTS * Horizontal Tabulation Set at current position
|
||||
211 89 I HTJ Hor Tab Justify, moves string to next tab position
|
||||
212 8A J VTS Vertical Tabulation Set at current line
|
||||
213 8B K PLD Partial Line Down (subscript)
|
||||
214 8C L PLU Partial Line Up (superscript)
|
||||
215 8D M RI * Reverse Index, go up one line, reverse scroll if necessary
|
||||
216 8E N SS2 * Single Shift to G2
|
||||
217 8F O SS3 * Single Shift to G3 (VT100 uses this for sending PF keys)
|
||||
220 90 P DCS * Device Control String, terminated by ST (VT125 enters graphics)
|
||||
221 91 Q PU1 Private Use 1
|
||||
222 92 R PU2 Private Use 2
|
||||
223 93 S STS Set Transmit State
|
||||
224 94 T CCH Cancel CHaracter, ignore previous character
|
||||
225 95 U MW Message Waiting, turns on an indicator on the terminal
|
||||
226 96 V SPA Start of Protected Area
|
||||
227 97 W EPA End of Protected Area
|
||||
230 98 X Reserved for for future standard
|
||||
231 99 Y Reserved
|
||||
232 9A Z * Reserved, but causes DEC terminals to respond with DA codes
|
||||
233 9B [ CSI * Control Sequence Introducer (described in a seperate table)
|
||||
234 9C \ ST * String Terminator (VT125 exits graphics)
|
||||
235 9D ] OSC Operating System Command (reprograms intelligent terminal)
|
||||
236 9E ^ PM Privacy Message (password verification), terminated by ST
|
||||
237 9F _ APC Application Program Command (to word processor), term by ST
|
||||
|
||||
==============================================================================
|
||||
Character set selection sequences (from ANSI X3.41-1974)
|
||||
All are 3 characters long (including the ESCape). Alphabetic characters
|
||||
as 3rd character are defined by ANSI, parameter characters as 3rd character
|
||||
may be interpreted differently by each terminal manufacturer.
|
||||
|
||||
Oct Hex * (* marks function used in DEC VT series or LA series terminals)
|
||||
--- -- -- - ------------------------------------------------------------------
|
||||
040 20 ANNOUNCER - Determines whether to use 7-bit or 8-bit ASCII
|
||||
A G0 only will be used. Ignore SI, SO, and G1.
|
||||
B G0 and G1 used internally. SI and SO affect G0, G1 is ignored.
|
||||
C G0 and G1 in an 8-bit only environment. SI and SO are ignored.
|
||||
D G0 and G1 are used, SI and SO affect G0.
|
||||
E
|
||||
F * 7-bit transmission, VT240/PRO350 sends CSI as two characters ESC [
|
||||
G * 8-bit transmission, VT240/PRO350 sends CSI as single 8-bit character
|
||||
041 21 ! Select C0 control set (choice of 63 standard, 16 private)
|
||||
042 22 " Select C1 control set (choice of 63 standard, 16 private)
|
||||
043 23 # Translate next character to a special single character
|
||||
#3 * DECDHL1 - Double height line, top half
|
||||
#4 * DECDHL2 - Double height line, bottom half
|
||||
#5 * DECSWL - Single width line
|
||||
#6 * DECDWL - Double width line
|
||||
#7 * DECHCP - Make a hardcopy of the graphics screen (GIGI,VT125,VT241)
|
||||
#8 * DECALN - Alignment display, fill screen with "E" to adjust focus
|
||||
044 24 $ MULTIBYTE CHARACTERS - Displayable characters require 2-bytes each
|
||||
045 25 % SPECIAL INTERPRETATION - Such as 9-bit data
|
||||
046 26 & Reserved for future standardization
|
||||
047 27 ' Reserved for future standardization
|
||||
050 28 ( * SCS - Select G0 character set (choice of 63 standard, 16 private)
|
||||
(0 * DEC VT100 line drawing set (affects lowercase characters)
|
||||
(1 * DEC Alternate character ROM set (RAM set on GIGI and VT220)
|
||||
(2 * DEC Alternate character ROM set with line drawing
|
||||
(5 * DEC Finnish on LA100
|
||||
(6 * DEC Norwegian/Danish on LA100
|
||||
(7 * DEC Swedish on LA100
|
||||
(9 * DEC French Canadian
|
||||
(< * DEC supplemental graphics (everything not in USASCII)
|
||||
(A * UKASCII (British pound sign)
|
||||
(B * USASCII (American pound sign)
|
||||
(C * ISO Finnish on LA120
|
||||
(E * ISO Norwegian/Danish on LA120
|
||||
(H * ISO Swedish on LA120
|
||||
(K * ISO German on LA100,LA120
|
||||
(R * ISO French on LA100,LA120
|
||||
(Y * ISO Italian on LA100
|
||||
(Z * ISO Spanish on LA100
|
||||
051 29 ) * SCS - Select G1 character set (choice of 63 standard, 16 private)
|
||||
* (same character sets as listed under G0)
|
||||
052 2A * * SCS - Select G2 character set
|
||||
* (same character sets as listed under G0)
|
||||
053 2B + * SCS - Select G3 character set
|
||||
* (same character sets as listed under G0)
|
||||
054 2C , SCS - Select G0 character set (additional 63+16 sets)
|
||||
055 2D - SCS - Select G1 character set (additional 63+16 sets)
|
||||
056 2E . SCS - Select G2 character set
|
||||
057 2F / SCS - Select G3 character set
|
||||
|
||||
==============================================================================
|
||||
Private two-character escape sequences (allowed by ANSI X3.41-1974)
|
||||
These can be defined differently by each terminal manufacturer.
|
||||
|
||||
Oct Hex * (* marks function used in DEC VT series or LA series terminals)
|
||||
--- -- - - ------------------------------------------------------------------
|
||||
060 30 0
|
||||
061 31 1 DECGON graphics on for VT105, DECHTS horiz tab set for LA34/LA120
|
||||
062 32 2 DECGOFF graphics off VT105, DECCAHT clear all horz tabs LA34/LA120
|
||||
063 33 3 DECVTS - set vertical tab for LA34/LA120
|
||||
064 34 4 DECCAVT - clear all vertical tabs for LA34/LA120
|
||||
065 35 5 * DECXMT - Host requests that VT132 transmit as if ENTER were pressed
|
||||
066 36 6
|
||||
067 37 7 * DECSC - Save cursor position and character attributes
|
||||
070 38 8 * DECRC - Restore cursor and attributes to previously saved position
|
||||
071 39 9
|
||||
072 3A :
|
||||
073 3B ;
|
||||
074 3C < * DECANSI - Switch from VT52 mode to VT100 mode
|
||||
075 3D = * DECKPAM - Set keypad to applications mode (ESCape instead of digits)
|
||||
076 3E > * DECKPNM - Set keypad to numeric mode (digits intead of ESCape seq)
|
||||
077 3F ?
|
||||
|
||||
DCS Device Control Strings used by DEC terminals (ends with ST)
|
||||
|
||||
Pp = Start ReGIS graphics (VT125, GIGI, VT240, PRO350)
|
||||
Pq = Start SIXEL graphics (screen dump to LA34, LA100, screen load to VT125)
|
||||
Pr = SET-UP data for GIGI, $PrVC0$\ disables both visible cursors.
|
||||
Ps = Reprogram keys on the GIGI, $P0sDIR<CR>$\ makes keypad 0 send "DIR<CR>"
|
||||
0-9=digits on keypad, 10=ENTER, 11=minus, 12=comma, 13=period,
|
||||
14-17=PF1-PF4, 18-21=cursor keys. Enabled by $[?23h (PK1).
|
||||
Pt = Start VT105 graphics on a VT125
|
||||
|
||||
==============================================================================
|
||||
|
||||
Standard two-character escape sequences (defined by ANSI X3.64-1979)
|
||||
|
||||
100 40 @ See description of C1 control characters
|
||||
An ESCape followed by one of these uppercase characters is translated
|
||||
to an 8-bit C1 control character before being interpreted.
|
||||
220 90 P DCS - Device Control String, terminated by ST - see table above.
|
||||
133 5B [ CSI - Control Sequence Introducer - see table below.
|
||||
137 5F _ See description of C1 control characters
|
||||
|
||||
==============================================================================
|
||||
|
||||
Indepenent control functions (from Appendix E of X3.64-1977).
|
||||
These four controls have the same meaning regardless of the current
|
||||
definition of the C0 and C1 control sets. Each control is a two-character
|
||||
ESCape sequence, the 2nd character is lowercase.
|
||||
|
||||
Oct Hex * (* marks function used in DEC VT series or LA series terminals)
|
||||
--- -- - - --------------------------------------------------------------------
|
||||
140 60 ` DMI - Disable Manual Input
|
||||
141 61 a INT - INTerrupt the terminal and do special action
|
||||
142 62 b EMI - Enable Manual Input
|
||||
143 63 c * RIS - Reset to Initial State (VT100 does a power-on reset)
|
||||
... The remaining lowercase characters are reserved by ANSI.
|
||||
153 6B k NAPLPS lock-shift G1 to GR
|
||||
154 6C l NAPLPS lock-shift G2 to GR
|
||||
155 6D m NAPLPS lock-shift G3 to GR
|
||||
156 6E n * LS2 - Shift G2 to GL (extension of SI) VT240,NAPLPS
|
||||
157 6F o * LS3 - Shift G3 to GL (extension of SO) VT240,NAPLPS
|
||||
... The remaining lowercase characters are reserved by ANSI.
|
||||
174 7C | * LS3R - VT240 lock-shift G3 to GR
|
||||
175 7D } * LS2R - VT240 lock-shift G2 to GR
|
||||
176 7E ~ * LS1R - VT240 lock-shift G1 to GR
|
||||
|
||||
==============================================================================
|
||||
Control Sequences (defined by ANSI X3.64-1979)
|
||||
|
||||
Control Sequences are started by either ESC [ or CSI and are terminated by an
|
||||
"alphabetic" character (100 to 176 octal, 40 to 7E hex). Intermediate
|
||||
characters are space through slash (40 to 57 octal, 20 to 2F hex) and parameter
|
||||
characters are zero through question mark (60 to 77 octal, 30 to 3F hex,
|
||||
including digits and semicolon). Parameters consist of zero or more decimal
|
||||
numbers separated by semicolons. Leading zeros are optional, leading blanks
|
||||
are not allowed. If no digits precede the final character, the default
|
||||
parameter is used. Many functions treat a parameter of 0 as if it were 1.
|
||||
|
||||
Oct Hex * (* marks function used in DEC VT series or LA series terminals)
|
||||
--- -- - - --------------------------------------------------------------------
|
||||
100 40 @ ICH - Insert CHaracter
|
||||
[10@ = Make room for 10 characters at current position
|
||||
101 41 A * CUU - CUrsor Up
|
||||
* [A = Move up one line, stop at top of screen, [9A = move up 9
|
||||
102 42 B * CUD - CUrsor Down
|
||||
* [B = Move down one line, stop at bottom of screen
|
||||
103 43 C * CUF - CUrsor Forward
|
||||
* [C = Move forward one position, stop at right edge of screen
|
||||
104 44 D * CUB - CUrsor Backward
|
||||
* [D = Same as BackSpace, stop at left edge of screen
|
||||
105 45 E CNL - Cursor to Next Line
|
||||
[5E = Move to first position of 5th line down
|
||||
106 46 F CPL - Cursor to Previous Line
|
||||
[5F = Move to first position of 5th line previous
|
||||
107 47 G CHA - Cursor Horizontal position Absolute
|
||||
[40G = Move to column 40 of current line
|
||||
110 48 H * CUP - CUrsor Position
|
||||
* [H = Home, [24;80H = Row 24, Column 80
|
||||
111 49 I CHT - Cursor Horizontal Tabulation
|
||||
[I = Same as HT (Control-I), [3I = Go forward 3 tabs
|
||||
112 4A J * ED - Erase in Display (cursor does not move)
|
||||
* [J = [0J = Erase from current position to end (inclusive)
|
||||
* [1J = Erase from beginning to current position (inclusive)
|
||||
* [2J = Erase entire display
|
||||
* [?0J = Selective erase in display ([?1J, [?2J similar)
|
||||
113 4B K * EL - Erase in Line (cursor does not move)
|
||||
* [K = [0K = Erase from current position to end (inclusive)
|
||||
* [1K = Erase from beginning to current position
|
||||
* [2K = Erase entire current line
|
||||
* [?0K = Selective erase to end of line ([?1K, [?2K similar)
|
||||
114 4C L * IL - Insert Line, current line moves down (VT102 series)
|
||||
[3L = Insert 3 lines if currently in scrolling region
|
||||
115 4D M * DL - Delete Line, lines below current move up (VT102 series)
|
||||
[2M = Delete 2 lines if currently in scrolling region
|
||||
116 4E N EF - Erase in Field (as bounded by protected fields)
|
||||
[0N, [1N, [2N act like [L but within currend field
|
||||
117 4F O EA - Erase in qualified Area (defined by DAQ)
|
||||
[0O, [1O, [2O act like [J but within current area
|
||||
120 50 P * DCH - Delete Character, from current position to end of field
|
||||
[4P = Delete 4 characters, VT102 series
|
||||
121 51 Q SEM - Set Editing extent Mode (limits ICH and DCH)
|
||||
[0Q = [Q = Insert/delete character affects rest of display
|
||||
[1Q = ICH/DCH affect the current line only
|
||||
[2Q = ICH/DCH affect current field (between tab stops) only
|
||||
[3Q = ICH/DCH affect qualified area (between protected fields)
|
||||
122 52 R * CPR - Cursor Position Report (from terminal to host)
|
||||
* [24;80R = Cursor is positioned at line 24 column 80
|
||||
123 53 S SU - Scroll up, entire display is moved up, new lines at bottom
|
||||
[3S = Move everything up 3 lines, bring in 3 new lines
|
||||
124 54 T SD - Scroll down, new lines inserted at top of screen
|
||||
[4T = Scroll down 4, bring previous lines back into view
|
||||
125 55 U NP - Next Page (if terminal has more than 1 page of memory)
|
||||
[2U = Scroll forward 2 pages
|
||||
126 56 V PP - Previous Page (if terminal remembers lines scrolled off top)
|
||||
[1V = Scroll backward 1 page
|
||||
127 57 W CTC - Cursor Tabulation Control
|
||||
[0W = Set horizontal tab for current line at current position
|
||||
[1W = Set vertical tab stop for current line of current page
|
||||
[2W = Clear horiz tab stop at current position of current line
|
||||
[3W = Clear vert tab stop at current line of current page
|
||||
[4W = Clear all horiz tab stops on current line only
|
||||
[5W = Clear all horiz tab stops for the entire terminal
|
||||
[6W = Clear all vert tabs stops for the entire terminal
|
||||
130 58 X ECH - Erase CHaracter
|
||||
[4X = Change next 4 characters to "erased" state
|
||||
131 59 Y CVT - Cursor Vertical Tab
|
||||
[2Y = Move forward to 2nd following vertical tab stop
|
||||
132 5A Z CBT - Cursor Back Tab
|
||||
[3Z = Move backwards to 3rd previous horizontal tab stop
|
||||
133 5B [ Reserved for future standardization left bracket
|
||||
134 5C \ Reserved reverse slant
|
||||
135 5D ] Reserved right bracket
|
||||
136 5E ^ Reserved circumflex
|
||||
137 5F _ Reserved underscore
|
||||
140 60 ` * HPA - Horizontal Position Absolute (depends on PUM)
|
||||
[720` = Move to 720 decipoints (1 inch) from left margin
|
||||
* [80` = Move to column 80 on LA120
|
||||
141 61 a * HPR - Horizontal Position Relative (depends on PUM)
|
||||
[360a = Move 360 decipoints (1/2 inch) from current position
|
||||
* [40a = Move 40 columns to right of current position on LA120
|
||||
142 62 b REP - REPeat previous displayable character
|
||||
[80b = Repeat character 80 times
|
||||
143 63 c * DA - Device Attributes
|
||||
* [c = Terminal will identify itself
|
||||
* [?1;2c = Terminal is saying it is a VT100 with AVO
|
||||
* [>0c = Secondary DA request (distinguishes VT240 from VT220)
|
||||
144 64 d * VPA - Vertical Position Absolute (depends on PUM)
|
||||
[90d = Move to 90 decipoints (1/8 inch) from top margin
|
||||
* [10d = Move to line 10 if before that else line 10 next page
|
||||
145 65 e * VPR - Vertical Position Relative (depends on PUM)
|
||||
[720e = Move 720 decipoints (1 inch) down from current position
|
||||
* [6e = Advance 6 lines forward on LA120
|
||||
146 66 f * HVP - Horizontal and Vertical Position (depends on PUM)
|
||||
[720,1440f = Move to 1 inch down and 2 inches over (decipoints)
|
||||
* [24;80f = Move to row 24 column 80 if PUM is set to character
|
||||
147 67 g * TBC - Tabulation Clear
|
||||
* [0g = Clear horizontal tab stop at current position
|
||||
* [1g = Clear vertical tab stop at current line (LA120)
|
||||
* [2g = Clear all horizontal tab stops on current line only LA120
|
||||
* [3g = Clear all horizontal tab stops in the terminal
|
||||
150 68 h * SM - Set Mode (. means permanently set on VT100)
|
||||
[0h = Error, this command is ignored
|
||||
* [1h = GATM - Guarded Area Transmit Mode, send all (VT132)
|
||||
[2h = KAM - Keyboard Action Mode, disable keyboard input
|
||||
[3h = CRM - Control Representation Mode, show all control chars
|
||||
* [4h = IRM - Insertion/Replacement Mode, set insert mode (VT102)
|
||||
[5h = SRTM - Status Report Transfer Mode, report after DCS
|
||||
* [6h = ERM - ERasure Mode, erase protected and unprotected
|
||||
[7h = VEM - Vertical Editing Mode, IL/DL affect previous lines
|
||||
[8h, [9h are reserved
|
||||
[10h = HEM - Horizontal Editing mode, ICH/DCH/IRM go backwards
|
||||
[11h = PUM - Positioning Unit Mode, use decipoints for HVP/etc
|
||||
. [12h = SRM - Send Receive Mode, transmit without local echo
|
||||
[13h = FEAM - Format Effector Action Mode, FE's are stored
|
||||
[14h = FETM - Format Effector Transfer Mode, send only if stored
|
||||
[15h = MATM - Multiple Area Transfer Mode, send all areas
|
||||
* [16h = TTM - Transmit Termination Mode, send scrolling region
|
||||
[17h = SATM - Send Area Transmit Mode, send entire buffer
|
||||
[18h = TSM - Tabulation Stop Mode, lines are independent
|
||||
[19h = EBM - Editing Boundry Mode, all of memory affected
|
||||
* [20h = LNM - Linefeed Newline Mode, LF interpreted as CR LF
|
||||
* [?1h = DECCKM - Cursor Keys Mode, send ESC O A for cursor up
|
||||
* [?2h = DECANM - ANSI Mode, use ESC < to switch VT52 to ANSI
|
||||
* [?3h = DECCOLM - COLumn mode, 132 characters per line
|
||||
* [?4h = DECSCLM - SCrolL Mode, smooth scrolling
|
||||
* [?5h = DECSCNM - SCreeN Mode, black on white background
|
||||
* [?6h = DECOM - Origin Mode, line 1 is relative to scroll region
|
||||
* [?7h = DECAWM - AutoWrap Mode, start newline after column 80
|
||||
* [?8h = DECARM - Auto Repeat Mode, key will autorepeat
|
||||
* [?9h = DECINLM - INterLace Mode, interlaced for taking photos
|
||||
* [?10h = DECEDM - EDit Mode, VT132 is in EDIT mode
|
||||
* [?11h = DECLTM - Line Transmit Mode, ignore TTM, send line
|
||||
[?12h = ?
|
||||
* [?13h = DECSCFDM - Space Compression/Field Delimiting on,
|
||||
* [?14h = DECTEM - Transmit Execution Mode, transmit on ENTER
|
||||
[?15h = ?
|
||||
* [?16h = DECEKEM - Edit Key Execution Mode, EDIT key is local
|
||||
[?17h = ?
|
||||
* [?18h = DECPFF - Print FormFeed mode, send FF after printscreen
|
||||
* [?19h = DECPEXT - Print Extent mode, print entire screen
|
||||
* [?20h = OV1 - Overstrike, overlay characters on GIGI
|
||||
* [?21h = BA1 - Local BASIC, GIGI to keyboard and screen
|
||||
* [?22h = BA2 - Host BASIC, GIGI to host computer
|
||||
* [?23h = PK1 - GIGI numeric keypad sends reprogrammable sequences
|
||||
* [?24h = AH1 - Autohardcopy before erasing or rolling GIGI screen
|
||||
* [?29h = - Use only the proper pitch for the LA100 font
|
||||
* [?38h = DECTEK - TEKtronix mode graphics
|
||||
151 69 i * MC - Media Copy (printer port on VT102)
|
||||
* [0i = Send contents of text screen to printer
|
||||
[1i = Fill screen from auxiliary input (printer's keyboard)
|
||||
[2i = Send screen to secondary output device
|
||||
[3i = Fill screen from secondary input device
|
||||
* [4i = Turn on copying received data to primary output (VT125)
|
||||
* [4i = Received data goes to VT102 screen, not to its printer
|
||||
* [5i = Turn off copying received data to primary output (VT125)
|
||||
* [5i = Received data goes to VT102's printer, not its screen
|
||||
* [6i = Turn off copying received data to secondary output (VT125)
|
||||
* [7i = Turn on copying received data to secondary output (VT125)
|
||||
* [?0i = Graphics screen dump goes to graphics printer VT125,VT240
|
||||
* [?1i = Print cursor line, terminated by CR LF
|
||||
* [?2i = Graphics screen dump goes to host computer VT125,VT240
|
||||
* [?4i = Disable auto print
|
||||
* [?5i = Auto print, send a line at a time when linefeed received
|
||||
152 6A j Reserved for future standardization
|
||||
153 6B k Reserved for future standardization
|
||||
154 6C l * RM - Reset Mode (. means permanently reset on VT100)
|
||||
* [1l = GATM - Transmit only unprotected characters (VT132)
|
||||
. [2l = KAM - Enable input from keyboard
|
||||
. [3l = CRM - Control characters are not displayable characters
|
||||
* [4l = IRM - Reset to replacement mode (VT102)
|
||||
. [5l = SRTM - Report only on command (DSR)
|
||||
* [6l = ERM - Erase only unprotected fields
|
||||
. [7l = VEM - IL/DL affect lines after current line
|
||||
[8l, [9l are reserved
|
||||
. [10l = HEM - ICH and IRM shove characters forward, DCH pulls
|
||||
. [11l = PUM - Use character positions for HPA/HPR/VPA/VPR/HVP
|
||||
[12l = SRM - Local echo - input from keyboard sent to screen
|
||||
. [13l = FEAM - HPA/VPA/SGR/etc are acted upon when received
|
||||
. [14l = FETM - Format Effectors are sent to the printer
|
||||
[15l = MATM - Send only current area if SATM is reset
|
||||
* [16l = TTM - Transmit partial page, up to cursor position
|
||||
[17l = SATM - Transmit areas bounded by SSA/ESA/DAQ
|
||||
. [18l = TSM - Setting a tab stop on one line affects all lines
|
||||
. [19l = EBM - Insert does not overflow to next page
|
||||
* [20l = LNM - Linefeed does not change horizontal position
|
||||
* [?1l = DECCKM - Cursor keys send ANSI cursor position commands
|
||||
* [?2l = DECANM - Use VT52 emulation instead of ANSI mode
|
||||
* [?3l = DECCOLM - 80 characters per line (erases screen)
|
||||
* [?4l = DECSCLM - Jump scrolling
|
||||
* [?5l = DECSCNM - Normal screen (white on black background)
|
||||
* [?6l = DECOM - Line numbers are independent of scrolling region
|
||||
* [?7l = DECAWM - Cursor remains at end of line after column 80
|
||||
* [?8l = DECARM - Keys do not repeat when held down
|
||||
* [?9l = DECINLM - Display is not interlaced to avoid flicker
|
||||
* [?10l = DECEDM - VT132 transmits all key presses
|
||||
* [?11l = DECLTM - Send page or partial page depending on TTM
|
||||
[?12l = ?
|
||||
* [?13l = DECSCFDM - Don't suppress trailing spaces on transmit
|
||||
* [?14l = DECTEM - ENTER sends ESC S (STS) a request to send
|
||||
[?15l = ?
|
||||
* [?16l = DECEKEM - EDIT key transmits either $[10h or $[10l
|
||||
[?17l = ?
|
||||
* [?18l = DECPFF - Don't send a formfeed after printing screen
|
||||
* [?19l = DECPEXT - Print only the lines within the scroll region
|
||||
* [?20l = OV0 - Space is destructive, replace not overstrike, GIGI
|
||||
* [?21l = BA0 - No BASIC, GIGI is On-Line or Local
|
||||
* [?22l = BA0 - No BASIC, GIGI is On-Line or Local
|
||||
* [?23l = PK0 - Ignore reprogramming on GIGI keypad and cursors
|
||||
* [?24l = AH0 - No auto-hardcopy when GIGI screen erased
|
||||
* [?29l = Allow all character pitches on the LA100
|
||||
* [?38l = DECTEK - Ignore TEKtronix graphics commands
|
||||
155 6D m * SGR - Set Graphics Rendition (affects character attributes)
|
||||
* [0m = Clear all special attributes
|
||||
* [1m = Bold or increased intensity
|
||||
* [2m = Dim or secondary color on GIGI (superscript on XXXXXX)
|
||||
[3m = Italic (subscript on XXXXXX)
|
||||
* [4m = Underscore, [0;4m = Clear, then set underline only
|
||||
* [5m = Slow blink
|
||||
[6m = Fast blink (overscore on XXXXXX)
|
||||
* [7m = Negative image, [0;1;7m = Bold + Inverse
|
||||
[8m = Concealed (do not display character echoed locally)
|
||||
[9m = Reserved for future standardization
|
||||
* [10m = Select primary font (LA100)
|
||||
* [11m - [19m = Selete alternate font (LA100 has 11 thru 14)
|
||||
[20m = FRAKTUR (whatever that means)
|
||||
* [22m = Cancel bold or dim attribute only (VT220)
|
||||
* [24m = Cancel underline attribute only (VT220)
|
||||
* [25m = Cancel fast or slow blink attribute only (VT220)
|
||||
* [27m = Cancel negative image attribute only (VT220)
|
||||
* [30m = Write with black, [40m = Set background to black (GIGI)
|
||||
* [31m = Write with red, [41m = Set background to red
|
||||
* [32m = Write with green, [42m = Set background to green
|
||||
* [33m = Write with yellow, [43m = Set background to yellow
|
||||
* [34m = Write with blue, [44m = Set background to blue
|
||||
* [35m = Write with magenta, [45m = Set background to magenta
|
||||
* [36m = Write with cyan, [46m = Set background to cyan
|
||||
* [37m = Write with white, [47m = Set background to white
|
||||
[38m, [39m, [48m, [49m are reserved
|
||||
156 6E n * DSR - Device Status Report
|
||||
* [0n = Terminal is ready, no malfunctions detected
|
||||
[1n = Terminal is busy, retry later
|
||||
[2n = Terminal is busy, it will send DSR when ready
|
||||
* [3n = Malfunction, please try again
|
||||
[4n = Malfunction, terminal will send DSR when ready
|
||||
* [5n = Command to terminal to report its status
|
||||
* [6n = Command to terminal requesting cursor position (CPR)
|
||||
* [?15n = Command to terminal requesting printer status, returns
|
||||
[?10n = OK, [?11n = not OK, [?13n = no printer.
|
||||
* [?25n = "Are User Defined Keys Locked?" (VT220)
|
||||
157 6F o DAQ - Define Area Qualification starting at current position
|
||||
[0o = Accept all input, transmit on request
|
||||
[1o = Protected and guarded, accept no input, do not transmit
|
||||
[2o = Accept any printing character in this field
|
||||
[3o = Numeric only field
|
||||
[4o = Alphabetic (A-Z and a-z) only
|
||||
[5o = Right justify in area
|
||||
[3;6o = Zero fill in area
|
||||
[7o = Set horizontal tab stop, this is the start of the field
|
||||
[8o = Protected and unguarded, accept no input, do transmit
|
||||
[9o = Space fill in area
|
||||
|
||||
==============================================================================
|
||||
|
||||
Private Control Sequences (allowed by ANSI X3.41-1974).
|
||||
These take parameter strings and terminate with the last half of lowercase.
|
||||
|
||||
Oct Hex * (* marks function used in DEC VT series or LA series terminals)
|
||||
--- -- - - --------------------------------------------------------------------
|
||||
160 70 p * DECSTR - Soft Terminal Reset
|
||||
[!p = Soft Terminal Reset
|
||||
161 71 q * DECLL - Load LEDs
|
||||
[0q = Turn off all, [?1;4q turns on L1 and L4, etc
|
||||
[154;155;157q = VT100 goes bonkers
|
||||
[2;23!q = Partial screen dump from GIGI to graphics printer
|
||||
[0"q = DECSCA Select Character Attributes off
|
||||
[1"q = DECSCA - designate set as non-erasable
|
||||
[2"q = DECSCA - designate set as erasable
|
||||
162 72 r * DECSTBM - Set top and bottom margins (scroll region on VT100)
|
||||
[4;20r = Set top margin at line 4 and bottom at line 20
|
||||
163 73 s * DECSTRM - Set left and right margins on LA100,LA120
|
||||
[5;130s = Set left margin at column 5 and right at column 130
|
||||
164 74 t * DECSLPP - Set physical lines per page
|
||||
[66t = Paper has 66 lines (11 inches at 6 per inch)
|
||||
165 75 u * DECSHTS - Set many horizontal tab stops at once on LA100
|
||||
[9;17;25;33;41;49;57;65;73;81u = Set standard tab stops
|
||||
166 76 v * DECSVTS - Set many vertical tab stops at once on LA100
|
||||
[1;16;31;45v = Set vert tabs every 15 lines
|
||||
167 77 w * DECSHORP - Set horizontal pitch on LAxxx printers
|
||||
[1w = 10 characters per inch, [2w = 12 characters per inch
|
||||
[0w=10, [3w=13.2, [4w=16.5, [5w=5, [6w=6, [7w=6.6, [8w=8.25
|
||||
170 78 x * DECREQTPARM - Request terminal parameters
|
||||
[3;5;2;64;64;1;0x = Report, 7 bit Even, 1200 baud, 1200 baud
|
||||
171 79 y * DECTST - Invoke confidence test
|
||||
[2;1y = Power-up test on VT100 series (and VT100 part of VT125)
|
||||
[3;1y = Power-up test on GIGI (VK100)
|
||||
[4;1y = Power-up test on graphics portion of VT125
|
||||
172 7A z * DECVERP - Set vertical pitch on LA100
|
||||
[1z = 6 lines per inch, [2z = 8 lines per inch
|
||||
[0z=6, [3z=12, [4z=3, [5z=3, [6z=4
|
||||
173 7B { Private
|
||||
174 7C | * DECTTC - Transmit Termination Character
|
||||
[0| = No extra characters, [1| = terminate with FF
|
||||
175 7D } * DECPRO - Define protected field on VT132
|
||||
[0} = No protection, [1;4;5;7} = Any attribute is protected
|
||||
[254} = Characters with no attributes are protected
|
||||
176 7E ~ * DECKEYS - Sent by special function keys
|
||||
[1~=FIND, [2~=INSERT, [3~=REMOVE, [4~=SELECT, [5~=PREV, [6~=NEXT
|
||||
[17~=F6...[34~=F20 ([23~=ESC,[24~=BS,[25~=LF,[28~=HELP,[29~=DO)
|
||||
177 7F DELETE is always ignored
|
||||
|
||||
==============================================================================
|
||||
Control Sequences with intermediate characters (from ANSI X3.64-1979).
|
||||
Note that there is a SPACE character before the terminating alphabetic.
|
||||
|
||||
Oct Hex * (* marks function used in DEC VT series or LA series terminals)
|
||||
--- -- - - --------------------------------------------------------------------
|
||||
100 40 @ SL - Scroll Left
|
||||
[4 @ = Move everything over 4 columns, 4 new columns at right
|
||||
101 41 A SR - Scroll Right
|
||||
[2 A = Move everything over 2 columns, 2 new columns at left
|
||||
102 42 B GSM - Graphic Size Modification
|
||||
[110;50 B = Make 110% high, 50% wide
|
||||
103 43 C GSS - Graphic Size Selection
|
||||
[120 C = Make characters 120 decipoints (1/6 inch) high
|
||||
104 44 D FNT - FoNT selection (used by SGR, [10m thru [19m)
|
||||
[0;23 D = Make primary font be registered font #23
|
||||
105 45 E TSS - Thin Space Specification
|
||||
[36 E = Define a thin space to be 36 decipoints (1/20 inch)
|
||||
106 46 F JFY - JustiFY, done by the terminal/printer
|
||||
[0 E = No justification
|
||||
[1 E = Fill, bringing words up from next line if necessary
|
||||
[2 E = Interword spacing, adjust spaces between words
|
||||
[3 E = Letter spacing, adjust width of each letter
|
||||
[4 E = Use hyphenation
|
||||
[5 E = Flush left margin
|
||||
[6 E = Center following text between margins (until [0 E)
|
||||
[7 E = Flush right margin
|
||||
[8 E = Italian form (underscore instead of hyphen)
|
||||
107 47 G SPI - SPacing Increment (in decipoints)
|
||||
[120;72 G = 6 per inch vertical, 10 per inch horizontal
|
||||
110 48 H QUAD- Do quadding on current line of text (typography)
|
||||
[0 H = Flush left, [1 H = Flush left and fill with leader
|
||||
[2 H = Center, [3 H = Center and fill with leader
|
||||
[4 H = Flush right, [5 H = Flush right and fill with leader
|
||||
111 49 I Reserved for future standardization
|
||||
157 67 o Reserved for future standardization
|
||||
160 70 p Private use
|
||||
... May be defined by the printer manufacturer
|
||||
176 7E ~ Private use
|
||||
177 7F DELETE is always ignored
|
||||
|
||||
==============================================================================
|
||||
Minimum requirements for VT100 emulation:
|
||||
|
||||
1) To act as a passive display, implement the 4 cursor commands, the 2 erase
|
||||
commands, direct cursor addressing, and at least inverse characters.
|
||||
The software should be capable of handling strings with 16 numeric parameters
|
||||
with values in the range of 0 to 255.
|
||||
|
||||
[A Move cursor up one row, stop if a top of screen
|
||||
[B Move cursor down one row, stop if at bottom of screen
|
||||
[C Move cursor forward one column, stop if at right edge of screen
|
||||
[D Move cursor backward one column, stop if at left edge of screen
|
||||
[H Home to row 1 column 1 (also [1;1H)
|
||||
[J Clear from current position to bottom of screen
|
||||
[K Clear from current position to end of line
|
||||
[24;80H Position to line 24 column 80 (any line 1 to 24, any column 1 to 132)
|
||||
[0m Clear attributes to normal characters
|
||||
[7m Add the inverse video attribute to succeeding characters
|
||||
[0;7m Set character attributes to inverse video only
|
||||
|
||||
2) To enter data in VT100 mode, implement the 4 cursor keys and the 4 PF keys.
|
||||
It must be possible to enter ESC, TAB, BS, DEL, and LF from the keyboard.
|
||||
|
||||
[A Sent by the up-cursor key (alternately ESC O A)
|
||||
[B Sent by the down-cursor key (alternately ESC O B)
|
||||
[C Sent by the right-cursor key (alternately ESC O C)
|
||||
[D Sent by the left-cursor key (alternately ESC O D)
|
||||
OP PF1 key sends ESC O P
|
||||
OQ PF2 key sends ESC O Q
|
||||
OR PF3 key sends ESC O R
|
||||
OS PF3 key sends ESC O S
|
||||
[c Request for the terminal to identify itself
|
||||
[?1;0c VT100 with memory for 24 by 80, inverse video character attribute
|
||||
[?1;2c VT100 capable of 132 column mode, with bold+blink+underline+inverse
|
||||
|
||||
3) When doing full-screen editing on a VT100, implement directed erase, the
|
||||
numeric keypad in applications mode, and the limited scrolling region.
|
||||
The latter is needed to do insert/delete line functions without rewriting
|
||||
the screen.
|
||||
|
||||
[0J Erase from current position to bottom of screen inclusive
|
||||
[1J Erase from top of screen to current position inclusive
|
||||
[2J Erase entire screen (without moving the cursor)
|
||||
[0K Erase from current position to end of line inclusive
|
||||
[1K Erase from beginning of line to current position inclusive
|
||||
[2K Erase entire line (without moving cursor)
|
||||
[12;24r Set scrolling region to lines 12 thru 24. If a linefeed or an
|
||||
INDex is received while on line 24, the former line 12 is deleted
|
||||
and rows 13-24 move up. If a RI (reverse Index) is received while
|
||||
on line 12, a blank line is inserted there as rows 12-13 move down.
|
||||
All VT100 compatible terminals (except GIGI) have this feature.
|
||||
ESC = Set numeric keypad to applications mode
|
||||
ESC > Set numeric keypad to numbers mode
|
||||
OA Up-cursor key sends ESC O A after ESC = ESC [ ? 1 h
|
||||
OB Down-cursor key sends ESC O B " " "
|
||||
OC Right-cursor key sends ESC O B " " "
|
||||
OB Left-cursor key sends ESC O B " " "
|
||||
OM ENTER key sends ESC O M after ESC =
|
||||
Ol COMMA on keypad sends ESC O l " " (that's lowercase L)
|
||||
Om MINUS on keypad sends ESC O m " "
|
||||
Op ZERO on keypad sends ESC O p " "
|
||||
Oq ONE on keypad sends ESC O q " "
|
||||
Or TWO on keypad sends ESC O r " "
|
||||
Os THREE on keypad sends ESC O s " "
|
||||
Ot FOUR on keypad sends ESC O t " "
|
||||
Ou FIVE on keypad sends ESC O u " "
|
||||
Ov SIX on keypad sends ESC O v " "
|
||||
Ow SEVEN on keypad sends ESC O w " "
|
||||
Ox EIGHT on keypad sends ESC O x " "
|
||||
Oy NINE on keypad sends ESC O y " "
|
||||
|
||||
4) If the hardware is capable of double width/double height:
|
||||
|
||||
#3 Top half of a double-width double-height line
|
||||
#4 Bottom half of a double-width double-height line
|
||||
#5 Make line single-width (lines are set this way when cleared by ESC [ J)
|
||||
#6 Make line double-width normal height (40 or 66 characters)
|
||||
|
||||
5) If the terminal emulator is capable of insert/delete characters,
|
||||
insert/delete lines, insert/replace mode, and can do a full-screen dump to
|
||||
the printer (in text mode), then it should identify itself as a VT102
|
||||
|
||||
[c Request for the terminal to identify itself
|
||||
[?6c VT102 (printer port, 132 column mode, and ins/del standard)
|
||||
[1@ Insert a blank character position (shift line to the right)
|
||||
[1P Delete a character position (shift line to the left)
|
||||
[1L Insert blank line at current row (shift screen down)
|
||||
[1M Delete the current line (shift screen up)
|
||||
[4h Set insert mode, new characters shove existing ones to the right
|
||||
[4l Reset insert mode, new characters replace existing ones
|
||||
[0i Print screen (all 24 lines) to the printer
|
||||
[4i All received data goes to the printer (nothing to the screen)
|
||||
[5i All received data goes to the screen (nothing to the printer)
|
||||
|
||||
|
||||
[End of ANSICODE.TXT]
|
||||
|
||||
|
||||
BIN
study/Ref-docs/ASCII/ascii-full.gif
Normal file
|
After Width: | Height: | Size: 25 KiB |
392
study/Ref-docs/ASCII/escape sequences.htm
Normal file
@@ -0,0 +1,392 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
||||
<!-- saved from url=(0046)http://enterprise.aacc.cc.md.us/~rhs/ansi.html -->
|
||||
<HTML><HEAD><TITLE>ANSI.SYS -- ansi terminal emulation escape sequences</TITLE>
|
||||
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
|
||||
<META content="MSHTML 5.00.3502.5390" name=GENERATOR></HEAD>
|
||||
<BODY><PRE>
|
||||
ANSI.SYS
|
||||
|
||||
Defines functions that change display graphics, control cursor movement, and
|
||||
reassign keys. The ANSI.SYS device driver supports ANSI terminal emulation
|
||||
of escape sequences to control your system's screen and keyboard. An ANSI
|
||||
escape sequence is a sequence of ASCII characters, the first two of which
|
||||
are the escape character (1Bh) and the left-bracket character (5Bh). The
|
||||
character or characters following the escape and left-bracket characters
|
||||
specify an alphanumeric code that controls a keyboard or display function.
|
||||
ANSI escape sequences distinguish between uppercase and lowercase letters;
|
||||
for example,"A" and "a" have completely different meanings.
|
||||
|
||||
This device driver must be loaded by a < DEVICE > or < DEVICEHIGH > command in
|
||||
your CONFIG.SYS file.
|
||||
|
||||
Note: In this topic bold letters in syntax and ANSI escape sequences
|
||||
indicate text you must type exactly as it appears.
|
||||
|
||||
Syntax
|
||||
|
||||
DEVICE=[drive:][path]ANSI.SYS [/X] [/K] [/R]
|
||||
|
||||
Parameter
|
||||
|
||||
[drive:][path]
|
||||
Specifies the location of the ANSI.SYS file.
|
||||
|
||||
Switches
|
||||
|
||||
/X
|
||||
Remaps extended keys independently on 101-key keyboards.
|
||||
|
||||
/K
|
||||
Causes ANSI.SYS to treat a 101-key keyboard like an 84-key
|
||||
keyboard. This is equivalent to the command SWITCHES=/K.
|
||||
If you usually use the SWITCHES=/K command, you will need
|
||||
to use the /K switch with ANSI.SYS.
|
||||
|
||||
/R
|
||||
Adjusts line scrolling to improve readability when ANSI.SYS
|
||||
is used with screen-reading programs (which make computers
|
||||
more accessible to people with disabilities).
|
||||
|
||||
Parameters used in ANSI escape sequences
|
||||
|
||||
Pn
|
||||
Numeric parameter. Specifies a decimal number.
|
||||
|
||||
Ps
|
||||
Selective parameter. Specifies a decimal number that you use to select
|
||||
a function. You can specify more than one function by separating the
|
||||
parameters with semicolons.
|
||||
|
||||
PL
|
||||
Line parameter. Specifies a decimal number that represents one of the
|
||||
lines on your display or on another device.
|
||||
|
||||
Pc
|
||||
Column parameter. Specifies a decimal number that represents one of the
|
||||
columns on your screen or on another device.
|
||||
|
||||
ANSI escape sequences for cursor movement, graphics, and keyboard settings
|
||||
|
||||
In the following list of ANSI escape sequences, the abbreviation ESC
|
||||
represents the ASCII escape character 27 (1Bh), which appears at the
|
||||
beginning of each escape sequence.
|
||||
|
||||
ESC[PL;PcH
|
||||
Cursor Position: Moves the cursor to the specified position
|
||||
(coordinates). If you do not specify a position, the cursor moves to the
|
||||
home position<6F><6E>the upper-left corner of the screen (line 0, column
|
||||
0). This escape sequence works the same way as the following Cursor
|
||||
Position escape sequence.
|
||||
|
||||
ESC[PL;Pcf
|
||||
Cursor Position: Works the same way as the preceding Cursor Position
|
||||
escape sequence.
|
||||
|
||||
ESC[PnA
|
||||
Cursor Up: Moves the cursor up by the specified number of lines without
|
||||
changing columns. If the cursor is already on the top line, ANSI.SYS
|
||||
ignores this sequence.
|
||||
|
||||
ESC[PnB
|
||||
Cursor Down: Moves the cursor down by the specified number of lines
|
||||
without changing columns. If the cursor is already on the bottom line,
|
||||
ANSI.SYS ignores this sequence.
|
||||
|
||||
ESC[PnC
|
||||
Cursor Forward: Moves the cursor forward by the specified number of
|
||||
columns without changing lines. If the cursor is already in the
|
||||
rightmost column, ANSI.SYS ignores this sequence.
|
||||
|
||||
ESC[PnD
|
||||
Cursor Backward: Moves the cursor back by the specified number of
|
||||
columns without changing lines. If the cursor is already in the leftmost
|
||||
column, ANSI.SYS ignores this sequence.
|
||||
|
||||
ESC[s
|
||||
Save Cursor Position: Saves the current cursor position. You can move
|
||||
the cursor to the saved cursor position by using the Restore Cursor
|
||||
Position sequence.
|
||||
|
||||
ESC[u
|
||||
Restore Cursor Position: Returns the cursor to the position stored
|
||||
by the Save Cursor Position sequence.
|
||||
|
||||
ESC[2J
|
||||
Erase Display: Clears the screen and moves the cursor to the home
|
||||
position (line 0, column 0).
|
||||
|
||||
ESC[K
|
||||
Erase Line: Clears all characters from the cursor position to the
|
||||
end of the line (including the character at the cursor position).
|
||||
|
||||
ESC[Ps;...;Psm
|
||||
Set Graphics Mode: Calls the graphics functions specified by the
|
||||
following values. These specified functions remain active until the next
|
||||
occurrence of this escape sequence. Graphics mode changes the colors and
|
||||
attributes of text (such as bold and underline) displayed on the
|
||||
screen.
|
||||
|
||||
Text attributes
|
||||
0 All attributes off
|
||||
1 Bold on
|
||||
4 Underscore (on monochrome display adapter only)
|
||||
5 Blink on
|
||||
7 Reverse video on
|
||||
8 Concealed on
|
||||
|
||||
Foreground colors
|
||||
30 Black
|
||||
31 Red
|
||||
32 Green
|
||||
33 Yellow
|
||||
34 Blue
|
||||
35 Magenta
|
||||
36 Cyan
|
||||
37 White
|
||||
|
||||
Background colors
|
||||
40 Black
|
||||
41 Red
|
||||
42 Green
|
||||
43 Yellow
|
||||
44 Blue
|
||||
45 Magenta
|
||||
46 Cyan
|
||||
47 White
|
||||
|
||||
Parameters 30 through 47 meet the ISO 6429 standard.
|
||||
|
||||
ESC[=psh
|
||||
Set Mode: Changes the screen width or type to the mode specified
|
||||
by one of the following values:
|
||||
|
||||
0 40 x 148 x 25 monochrome (text)
|
||||
1 40 x 148 x 25 color (text)
|
||||
2 80 x 148 x 25 monochrome (text)
|
||||
3 80 x 148 x 25 color (text)
|
||||
4 320 x 148 x 200 4-color (graphics)
|
||||
5 320 x 148 x 200 monochrome (graphics)
|
||||
6 640 x 148 x 200 monochrome (graphics)
|
||||
7 Enables line wrapping
|
||||
13 320 x 148 x 200 color (graphics)
|
||||
14 640 x 148 x 200 color (16-color graphics)
|
||||
15 640 x 148 x 350 monochrome (2-color graphics)
|
||||
16 640 x 148 x 350 color (16-color graphics)
|
||||
17 640 x 148 x 480 monochrome (2-color graphics)
|
||||
18 640 x 148 x 480 color (16-color graphics)
|
||||
19 320 x 148 x 200 color (256-color graphics)
|
||||
|
||||
ESC[=Psl
|
||||
Reset Mode: Resets the mode by using the same values that Set Mode
|
||||
uses, except for 7, which disables line wrapping. The last character
|
||||
in this escape sequence is a lowercase L.
|
||||
|
||||
ESC[code;string;...p
|
||||
Set Keyboard Strings: Redefines a keyboard key to a specified string.
|
||||
The parameters for this escape sequence are defined as follows:
|
||||
|
||||
Code is one or more of the values listed in the following table.
|
||||
These values represent keyboard keys and key combinations. When using
|
||||
these values in a command, you must type the semicolons shown in this
|
||||
table in addition to the semicolons required by the escape sequence.
|
||||
The codes in parentheses are not available on some keyboards.
|
||||
ANSI.SYS will not interpret the codes in parentheses for those
|
||||
keyboards unless you specify the /X switch in the DEVICE command for
|
||||
ANSI.SYS.
|
||||
|
||||
String is either the ASCII code for a single character or a string
|
||||
contained in quotation marks. For example, both 65 and "A" can be
|
||||
used to represent an uppercase A.
|
||||
|
||||
IMPORTANT: Some of the values in the following table are not valid for all
|
||||
computers. Check your computer's documentation for values that
|
||||
are different.
|
||||
|
||||
Key Code SHIFT+code CTRL+code ALT+code
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>?
|
||||
F1 0;59 0;84 0;94 0;104
|
||||
|
||||
F2 0;60 0;85 0;95 0;105
|
||||
|
||||
F3 0;61 0;86 0;96 0;106
|
||||
|
||||
F4 0;62 0;87 0;97 0;107
|
||||
|
||||
F5 0;63 0;88 0;98 0;108
|
||||
|
||||
F6 0;64 0;89 0;99 0;109
|
||||
|
||||
F7 0;65 0;90 0;100 0;110
|
||||
|
||||
F8 0;66 0;91 0;101 0;111
|
||||
|
||||
F9 0;67 0;92 0;102 0;112
|
||||
|
||||
F10 0;68 0;93 0;103 0;113
|
||||
|
||||
F11 0;133 0;135 0;137 0;139
|
||||
|
||||
F12 0;134 0;136 0;138 0;140
|
||||
|
||||
HOME (num keypad) 0;71 55 0;119 <20><>
|
||||
|
||||
UP ARROW (num keypad) 0;72 56 (0;141) <20><>
|
||||
|
||||
PAGE UP (num keypad) 0;73 57 0;132 <20><>
|
||||
|
||||
LEFT ARROW (num keypad) 0;75 52 0;115 <20><>
|
||||
|
||||
RIGHT ARROW (num 0;77 54 0;116 <20><>
|
||||
keypad)
|
||||
|
||||
END (num keypad) 0;79 49 0;117 <20><>
|
||||
|
||||
DOWN ARROW (num keypad) 0;80 50 (0;145) <20><>
|
||||
|
||||
PAGE DOWN (num keypad) 0;81 51 0;118 <20><>
|
||||
|
||||
INSERT (num keypad) 0;82 48 (0;146) <20><>
|
||||
|
||||
DELETE (num keypad) 0;83 46 (0;147) <20><>
|
||||
|
||||
HOME (224;71) (224;71) (224;119) (224;151)
|
||||
|
||||
UP ARROW (224;72) (224;72) (224;141) (224;152)
|
||||
|
||||
PAGE UP (224;73) (224;73) (224;132) (224;153)
|
||||
|
||||
LEFT ARROW (224;75) (224;75) (224;115) (224;155)
|
||||
|
||||
RIGHT ARROW (224;77) (224;77) (224;116) (224;157)
|
||||
|
||||
END (224;79) (224;79) (224;117) (224;159)
|
||||
|
||||
DOWN ARROW (224;80) (224;80) (224;145) (224;154)
|
||||
|
||||
PAGE DOWN (224;81) (224;81) (224;118) (224;161)
|
||||
|
||||
INSERT (224;82) (224;82) (224;146) (224;162)
|
||||
|
||||
DELETE (224;83) (224;83) (224;147) (224;163)
|
||||
|
||||
PRINT SCREEN <20><> <20><> 0;114 <20><>
|
||||
|
||||
PAUSE/BREAK <20><> <20><> 0;0 <20><>
|
||||
|
||||
BACKSPACE 8 8 127 (0)
|
||||
|
||||
ENTER 13 <20><> 10 (0
|
||||
|
||||
TAB 9 0;15 (0;148) (0;165)
|
||||
|
||||
NULL 0;3 <20><> <20><> <20><>
|
||||
|
||||
A 97 65 1 0;30
|
||||
|
||||
B 98 66 2 0;48
|
||||
|
||||
C 99 66 3 0;46
|
||||
|
||||
D 100 68 4 0;32
|
||||
|
||||
E 101 69 5 0;18
|
||||
|
||||
F 102 70 6 0;33
|
||||
|
||||
G 103 71 7 0;34
|
||||
|
||||
H 104 72 8 0;35
|
||||
|
||||
I 105 73 9 0;23
|
||||
|
||||
J 106 74 10 0;36
|
||||
|
||||
K 107 75 11 0;37
|
||||
|
||||
L 108 76 12 0;38
|
||||
|
||||
M 109 77 13 0;50
|
||||
|
||||
N 110 78 14 0;49
|
||||
|
||||
O 111 79 15 0;24
|
||||
|
||||
P 112 80 16 0;25
|
||||
|
||||
Q 113 81 17 0;16
|
||||
|
||||
R 114 82 18 0;19
|
||||
|
||||
S 115 83 19 0;31
|
||||
|
||||
T 116 84 20 0;20
|
||||
|
||||
U 117 85 21 0;22
|
||||
|
||||
V 118 86 22 0;47
|
||||
|
||||
W 119 87 23 0;17
|
||||
|
||||
X 120 88 24 0;45
|
||||
|
||||
Y 121 89 25 0;21
|
||||
|
||||
Z 122 90 26 0;44
|
||||
|
||||
1 49 33 <20><> 0;120
|
||||
|
||||
2 50 64 0 0;121
|
||||
|
||||
3 51 35 <20><> 0;122
|
||||
|
||||
4 52 36 <20><> 0;123
|
||||
|
||||
5 53 37 <20><> 0;124
|
||||
|
||||
6 54 94 30 0;125
|
||||
|
||||
7 55 38 <20><> 0;126
|
||||
|
||||
8 56 42 <20><> 0;126
|
||||
|
||||
9 57 40 <20><> 0;127
|
||||
|
||||
0 48 41 <20><> 0;129
|
||||
|
||||
- 45 95 31 0;130
|
||||
|
||||
= 61 43 <20><>- 0;131
|
||||
|
||||
[ 91 123 27 0;26
|
||||
|
||||
] 93 125 29 0;27
|
||||
|
||||
92 124 28 0;43
|
||||
|
||||
; 59 58 <20><> 0;39
|
||||
|
||||
' 39 34 <20><> 0;40
|
||||
|
||||
, 44 60 <20><> 0;51
|
||||
|
||||
. 46 62 <20><> 0;52
|
||||
|
||||
/ 47 63 <20><> 0;53
|
||||
|
||||
` 96 126 <20><> (0;41)
|
||||
|
||||
ENTER (keypad) 13 <20><> 10 (0;166)
|
||||
|
||||
/ (keypad) 47 47 (0;142) (0;74)
|
||||
|
||||
* (keypad) 42 (0;144) (0;78) <20><>
|
||||
|
||||
- (keypad) 45 45 (0;149) (0;164)
|
||||
|
||||
+ (keypad) 43 43 (0;150) (0;55)
|
||||
|
||||
5 (keypad) (0;76) 53 (0;143) <20><>
|
||||
|
||||
|
||||
|
||||
</PRE></BODY></HTML>
|
||||
BIN
study/Ref-docs/ASCII/extend.gif
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
study/Ref-docs/ASCII/key-name.doc
Normal file
1034
study/Ref-docs/C/_index.html
Normal file
BIN
study/Ref-docs/C/arr_mod.gif
Normal file
|
After Width: | Height: | Size: 644 B |
68
study/Ref-docs/C/assert.html
Normal file
@@ -0,0 +1,68 @@
|
||||
<HTML><HEAD><TITLE><assert.h></TITLE></HEAD><BODY BGCOLOR="#FFFFFF">
|
||||
|
||||
<H1><A NAME="<assert.h>"><CODE><assert.h></CODE></A></H1><HR>
|
||||
|
||||
<P><CODE>
|
||||
#undef assert<BR>
|
||||
#if defined NDEBUG<BR>
|
||||
#define <B><A HREF="#assert">assert</A></B>(test) (void)0<BR>
|
||||
#else<BR>
|
||||
#define <B><A HREF="#assert">assert</A></B>(test)
|
||||
<I><void expression></I><BR>
|
||||
#endif
|
||||
</CODE></P>
|
||||
|
||||
<P>Include the standard header <B><CODE><assert.h></CODE></B>
|
||||
to define the macro
|
||||
<A HREF="#assert"><CODE>assert</CODE></A>,
|
||||
which is useful for diagnosing logic errors in
|
||||
the program. You can eliminate the testing code produced by the macro
|
||||
<CODE>assert</CODE> without removing the macro references from the program
|
||||
by defining the macro
|
||||
<B><A NAME="NDEBUG"><CODE>NDEBUG</CODE></A></B>
|
||||
in the program before you include
|
||||
<CODE><assert.h></CODE>. Each time the program includes this header,
|
||||
it redetermines the definition of the macro <CODE>assert</CODE>.</P>
|
||||
|
||||
<H2><A NAME="assert"><CODE>assert</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#undef assert<BR>
|
||||
#if defined NDEBUG<BR>
|
||||
#define <B>assert</B>(test) (void)0<BR>
|
||||
#else<BR>
|
||||
#define <B>assert</B>(test) <I><void expression></I><BR>
|
||||
#endif
|
||||
</CODE></P>
|
||||
|
||||
<P>If the <I>int</I> expression <CODE>test</CODE> equals zero,
|
||||
the macro writes to
|
||||
<A HREF="stdio.html#stderr" tppabs="http://ccs.ucsd.edu/c/stdio.html#stderr"><CODE>stderr</CODE></A>
|
||||
a diagnostic message that includes:</P>
|
||||
|
||||
<UL>
|
||||
<LI>the text of <CODE>test</CODE>
|
||||
|
||||
<LI>the source filename (the predefined macro
|
||||
<A HREF="preproc.html#__FILE__" tppabs="http://ccs.ucsd.edu/c/preproc.html#__FILE__"><CODE>__FILE__</CODE>)</A>
|
||||
|
||||
<LI>the source line number (the predefined macro
|
||||
<A HREF="preproc.html#__LINE__" tppabs="http://ccs.ucsd.edu/c/preproc.html#__LINE__"><CODE>__LINE__</CODE>)</A>
|
||||
</UL>
|
||||
|
||||
<P>It then calls
|
||||
<A HREF="stdlib.html#abort" tppabs="http://ccs.ucsd.edu/c/stdlib.html#abort"><CODE>abort</CODE></A>.</P>
|
||||
|
||||
<P>You can write the macro <CODE>assert</CODE> in the program in any
|
||||
<A HREF="function.html#side-effects context" tppabs="http://ccs.ucsd.edu/c/function.html#side-effects context">side-effects context</A>.</P>
|
||||
|
||||
<HR>
|
||||
<P>See also the
|
||||
<B><A HREF="index.html#Table of Contents" tppabs="http://ccs.ucsd.edu/c/index.html#Table of Contents">Table of Contents</A></B> and the
|
||||
<B><A HREF="_index.html" tppabs="http://ccs.ucsd.edu/c/_index.html">Index</A></B>.</P>
|
||||
|
||||
<P><I>
|
||||
<A HREF="crit_pb.html" tppabs="http://ccs.ucsd.edu/c/crit_pb.html">Copyright</A> © 1989-1996
|
||||
by P.J. Plauger and Jim Brodie. All rights reserved.</I></P>
|
||||
|
||||
</BODY></HTML>
|
||||
BIN
study/Ref-docs/C/block.gif
Normal file
|
After Width: | Height: | Size: 908 B |
BIN
study/Ref-docs/C/block_d.gif
Normal file
|
After Width: | Height: | Size: 1.9 KiB |
BIN
study/Ref-docs/C/block_f.gif
Normal file
|
After Width: | Height: | Size: 919 B |
BIN
study/Ref-docs/C/break_f.gif
Normal file
|
After Width: | Height: | Size: 368 B |
BIN
study/Ref-docs/C/casel_f.gif
Normal file
|
After Width: | Height: | Size: 606 B |
BIN
study/Ref-docs/C/casel_s.gif
Normal file
|
After Width: | Height: | Size: 664 B |
BIN
study/Ref-docs/C/char_con.gif
Normal file
|
After Width: | Height: | Size: 1.4 KiB |
445
study/Ref-docs/C/charset.html
Normal file
@@ -0,0 +1,445 @@
|
||||
<HTML><HEAD><TITLE>Characters</TITLE></HEAD><BODY BGCOLOR="#FFFFFF">
|
||||
|
||||
<H1><A NAME="Characters">Characters</A></H1><HR>
|
||||
|
||||
<P><B>
|
||||
<A HREF="#Character Sets">Character Sets</A>
|
||||
· <A HREF="#Character Sets and Locales">Character Sets and Locales</A>
|
||||
· <A HREF="#Escape Sequences">Escape Sequences</A>
|
||||
· <A HREF="#Numeric Escape Sequences">Numeric Escape Sequences</A>
|
||||
· <A HREF="#Trigraphs">Trigraphs</A>
|
||||
· <A HREF="#Multibyte Characters">Multibyte Characters</A>
|
||||
· <A HREF="#Wide-Character Encoding">Wide-Character Encoding</A>
|
||||
</B></P>
|
||||
<HR>
|
||||
|
||||
<P>Characters play a central role in Standard C. You represent
|
||||
a C program as one or more
|
||||
<B><A NAME="source file">source files</A></B>.
|
||||
The translator reads a source file as a
|
||||
<A NAME="text stream">text stream</A>
|
||||
consisting of characters that you can read when you
|
||||
display the stream on a terminal screen or produce hard copy with a
|
||||
printer. You often manipulate text when a C program executes. The
|
||||
program might produce a text stream that people can read, or it might
|
||||
read a text stream entered by someone typing at a keyboard
|
||||
or from a file modified using a text editor.
|
||||
This document describes the characters that you
|
||||
use to write C source files and that you manipulate as streams
|
||||
when executing C programs.</P>
|
||||
|
||||
<H2><A NAME="Character Sets">Character Sets</A></H2>
|
||||
|
||||
<P>When you write a program, you express C source files as
|
||||
<A HREF="lib_file.html#text lines" tppabs="http://ccs.ucsd.edu/c/lib_file.html#text lines">text lines</A>
|
||||
containing characters from the
|
||||
<B><A NAME="source character set">source character set</A></B>.
|
||||
When a program executes in the
|
||||
<B><A NAME="target environment">target environment</A></B>,
|
||||
it uses characters from the
|
||||
<B><A NAME="target character set">target character set</A></B>.
|
||||
These character sets are related, but need not have
|
||||
the same encoding or all the same members.</P>
|
||||
|
||||
<P>Every character set contains a distinct code value for each
|
||||
character in the
|
||||
<B><A NAME="basic C character set">basic C character set</A></B>.
|
||||
A character set can also contain additional characters
|
||||
with other code values. For example:</P>
|
||||
|
||||
<UL>
|
||||
<LI>The
|
||||
<B><A NAME="character constant">character constant</A></B>
|
||||
<CODE>'x'</CODE> becomes the value of
|
||||
the code for the character corresponding to <CODE>x</CODE> in the target
|
||||
character set.
|
||||
|
||||
<LI>The
|
||||
<B><A NAME="string literal">string literal</A></B>
|
||||
<CODE>"xyz"</CODE> becomes a sequence of
|
||||
character constants stored in successive bytes of memory, followed
|
||||
by a byte containing the value zero:<BR>
|
||||
<CODE>{'x', 'y', 'z', '\0'}</CODE>
|
||||
</UL>
|
||||
|
||||
<P>A string literal is one way to specify a
|
||||
<B><A NAME="null-terminated string">null-terminated string</A></B>,
|
||||
an array of zero or more bytes followed by a byte containing the
|
||||
value zero.</P>
|
||||
|
||||
<P><B><A NAME="visible graphic characters">Visible graphic characters</A></B>
|
||||
in the basic C character set:</P>
|
||||
|
||||
<PRE>
|
||||
<B>Form Members</B>
|
||||
<I>letter</I> A B C D E F G H I J K L M
|
||||
N O P Q R S T U V W X Y Z
|
||||
a b c d e f g h i j k l m
|
||||
n o p q r s t u v w x y z
|
||||
|
||||
<I>digit</I> 0 1 2 3 4 5 6 7 8 9
|
||||
|
||||
<I>underscore</I> _
|
||||
|
||||
<I>punctuation</I> ! " # % & ' ( ) * + , - . / :
|
||||
; < = > ? [ \ ] ^ { | } ~</PRE>
|
||||
|
||||
<P><B><A NAME="additional graphic characters">Additional
|
||||
graphic characters</A></B> in the basic C character set:</P>
|
||||
|
||||
<PRE>
|
||||
<B>Character Meaning</B>
|
||||
<A NAME="space"><I>space</I></A> <B>leave blank space</B>
|
||||
<A NAME="BEL"><I>BEL</I></A> <B>signal an alert (BELl)</B>
|
||||
<A NAME="BS"><I>BS</I></A> <B>go back one position (BackSpace)</B>
|
||||
<A NAME="FF"><I>FF</I></A> <B>go to top of page (Form Feed)</B>
|
||||
<A NAME="NL"><I>NL</I></A> <B>go to start of next line (NewLine)</B>
|
||||
<A NAME="CR"><I>CR</I></A> <B>go to start of this line (Carriage Return)</B>
|
||||
<A NAME="HT"><I>HT</I></A> <B>go to next Horizontal Tab stop</B>
|
||||
<A NAME="VT"><I>VT</I></A> <B>go to next Vertical Tab stop</B></PRE>
|
||||
|
||||
<P>The code value zero is reserved for the
|
||||
<B><A NAME="null character">null character</A></B>
|
||||
which is always in the target character set. Code values for the basic
|
||||
C character set are positive when stored in an object of type <I>char.</I>
|
||||
Code values for the digits are contiguous, with increasing value.
|
||||
For example, <CODE>'0' + 5</CODE> equals <CODE>'5'</CODE>.
|
||||
Code values for any
|
||||
two letters are <I>not</I> necessarily contiguous.</P>
|
||||
|
||||
<H3><A NAME="Character Sets and Locales">
|
||||
Character Sets and Locales</A></H3>
|
||||
|
||||
<P>An implementation can support multiple
|
||||
<A HREF="locale.html" tppabs="http://ccs.ucsd.edu/c/locale.html">locales</A>, each
|
||||
with a different character set. A locale summarizes conventions peculiar
|
||||
to a given culture, such as how to format dates or how to sort names.
|
||||
To change locales and, therefore, target character sets while the
|
||||
program is running, use the function
|
||||
<A HREF="locale.html#setlocale" tppabs="http://ccs.ucsd.edu/c/locale.html#setlocale"><CODE>setlocale</CODE></A>.
|
||||
The translator encodes character constants and
|
||||
string literals for the
|
||||
<A HREF="locale.html#C locale" tppabs="http://ccs.ucsd.edu/c/locale.html#C locale"><CODE>"C"</CODE></A> locale,
|
||||
which is the locale in effect at program startup.</P>
|
||||
|
||||
<H2><A NAME="Escape Sequences">Escape Sequences</A></H2>
|
||||
|
||||
<P>Within character constants and string literals, you can write
|
||||
a variety of <B>escape sequences</B>. Each escape sequence determines
|
||||
the code value for a single character. You use escape sequences
|
||||
to represent character codes:</P>
|
||||
|
||||
<UL>
|
||||
<LI>you cannot otherwise write (such as <CODE>\n</CODE>)
|
||||
|
||||
<LI>that can be difficult to read properly (such as <CODE>\t</CODE>)
|
||||
|
||||
<LI>that might change value in different target character sets (such
|
||||
as <CODE>\a</CODE>)
|
||||
|
||||
<LI>that must not change in value among different target environments
|
||||
(such as <CODE>\0</CODE>)
|
||||
</UL>
|
||||
|
||||
<P>An escape sequence takes the form:</P>
|
||||
|
||||
<P><IMG SRC="escape.gif" tppabs="http://ccs.ucsd.edu/c/gif/escape.gif"></P>
|
||||
|
||||
<P><B><A NAME="mnemonic escape sequences">
|
||||
Mnemonic escape sequences</A></B>
|
||||
help you remember the characters they represent:</P>
|
||||
|
||||
<PRE>
|
||||
<B>Character Escape Sequence</B>
|
||||
" \"
|
||||
' \'
|
||||
? \?
|
||||
\ \\
|
||||
<I>BEL</I> \a
|
||||
<I>BS</I> \b
|
||||
<I>FF</I> \f
|
||||
<I>NL</I> \n
|
||||
<I>CR</I> \r
|
||||
<I>HT</I> \t
|
||||
<I>VT</I> \v</PRE>
|
||||
|
||||
<H3><A NAME="Numeric Escape Sequences">
|
||||
Numeric Escape Sequences</A></H3>
|
||||
|
||||
<P>You can also write <B>numeric escape sequences</B> using either
|
||||
octal or hexadecimal digits. An
|
||||
<B><A NAME="octal escape sequence">octal escape sequence</A></B>
|
||||
takes one of the forms:</P>
|
||||
|
||||
<PRE>
|
||||
\<I>d</I> <B>or</B> \<I>dd</I> <B>or</B> \<I>ddd</I></PRE>
|
||||
|
||||
<P>The escape sequence yields a code value that is the numeric
|
||||
value of the 1-, 2-, or 3-digit octal number following the backslash
|
||||
(<CODE>\</CODE>). Each <CODE><I>d</I></CODE> can be
|
||||
any digit in the range <CODE>0-7</CODE>.</P>
|
||||
|
||||
<P>A
|
||||
<B><A NAME="hexadecimal escape sequence">
|
||||
hexadecimal escape sequence</A></B> takes one of the forms:</P>
|
||||
|
||||
<PRE>
|
||||
\x<I>h</I> <B>or</B> \x<I>hh</I> <B>or ...</B></PRE>
|
||||
|
||||
<P>The escape sequence yields a code value that is the numeric
|
||||
value of the arbitrary-length hexadecimal number following the backslash
|
||||
(<CODE>\</CODE>). Each <CODE><I>h</I></CODE> can be any
|
||||
decimal digit <CODE>0-9</CODE>, or
|
||||
any of the letters <CODE>a-f</CODE> or <CODE>A-F</CODE>.
|
||||
The letters represent
|
||||
the digit values 10-15, where either <CODE>a</CODE> or <CODE>A</CODE> has
|
||||
the value 10.</P>
|
||||
|
||||
<P>A numeric escape sequence terminates with the first character
|
||||
that does not fit the digit pattern. Here are some examples:</P>
|
||||
|
||||
<UL>
|
||||
<LI>You can write the
|
||||
<A HREF="#null character">null character</A>
|
||||
as <CODE>'\0'</CODE>.
|
||||
|
||||
<LI>You can write a newline character (<CODE><I>NL</I></CODE>)
|
||||
within a string literal by writing:<BR>
|
||||
<CODE>"hi\n" <B>which becomes the array</B><BR>
|
||||
{'h', 'i', '\n', 0}</CODE>
|
||||
|
||||
<LI>You can write a string literal that begins with a specific numeric
|
||||
value:<BR>
|
||||
<CODE>"\3abc" <B>which becomes the array</B><BR>
|
||||
{3, 'a', 'b', 'c', 0}</CODE>
|
||||
|
||||
<LI>You can write a string literal that contains the hexadecimal
|
||||
escape sequence <CODE>\xF</CODE> followed by
|
||||
the digit <CODE>3</CODE> by writing
|
||||
two string literals:<BR>
|
||||
<CODE>"\xF" "3" <B>which becomes the array</B><BR>
|
||||
{0xF, '3', 0}</CODE>
|
||||
</UL>
|
||||
|
||||
<H2><A NAME="Trigraphs">Trigraphs</A></H2>
|
||||
|
||||
<P>A <B>trigraph</B> is a sequence of three characters that begins
|
||||
with two question marks (<CODE>??</CODE>). You use trigraphs to write C
|
||||
source files with a character set that does not contain convenient
|
||||
graphic representations for some punctuation characters. (The resultant
|
||||
C source file is not necessarily more readable, but it is unambiguous.)</P>
|
||||
|
||||
<P>The list of all
|
||||
<B><A NAME="defined trigraphs">defined trigraphs</A></B> is:</P>
|
||||
|
||||
<PRE>
|
||||
<B>Character Trigraph</B>
|
||||
[ ??(
|
||||
\ ??/
|
||||
] ??)
|
||||
^ ??'
|
||||
{ ??<
|
||||
| ??!
|
||||
} ??>
|
||||
~ ??-
|
||||
# ??=</PRE>
|
||||
|
||||
<P>These are the only trigraphs. The translator does not alter any other
|
||||
sequence that begins with two question marks.</P>
|
||||
|
||||
<P>For example, the expression statements:</P>
|
||||
|
||||
<PRE>
|
||||
printf("Case ??=3 is done??/n");
|
||||
printf("You said what????/n");</PRE>
|
||||
|
||||
<P>are equivalent to:</P>
|
||||
|
||||
<PRE>
|
||||
printf("Case #3 is done\n");
|
||||
printf("You said what??\n");</PRE>
|
||||
|
||||
<P>The translator replaces each trigraph with its equivalent single
|
||||
character representation in an early
|
||||
<A HREF="preproc.html#Phases of Translation" tppabs="http://ccs.ucsd.edu/c/preproc.html#Phases of Translation">phase of translation</A>.
|
||||
You can always treat a trigraph as a single source character.</P>
|
||||
|
||||
<H2><A NAME="Multibyte Characters">Multibyte Characters</A></H2>
|
||||
|
||||
<P>A source character set or target character set can also contain
|
||||
<B>multibyte characters</B> (sequences of one or more bytes). Each
|
||||
sequence represents a single character in the
|
||||
<B><A NAME="extended character set">extended character set</A></B>.
|
||||
You use multibyte characters to represent large sets of characters,
|
||||
such as Kanji. A multibyte character can be a one-byte sequence that
|
||||
is a character from the
|
||||
<A HREF="#basic C character set">basic C character set</A>,
|
||||
an additional one-byte sequence that is
|
||||
<A HREF="portable.html#implementation defined" tppabs="http://ccs.ucsd.edu/c/portable.html#implementation defined">implementation defined</A>,
|
||||
or an additional sequence of two or more bytes that is
|
||||
implementation defined.</P>
|
||||
|
||||
<P>Any multibyte encoding that contains sequences of two or more
|
||||
bytes depends, for its interpretation between bytes, on a
|
||||
<B><A NAME="conversion state">conversion state</A></B> determined
|
||||
by bytes earlier in the sequence of characters. In the
|
||||
<B><A NAME="initial conversion state">initial conversion state</A></B>
|
||||
if the byte immediately following matches one of the characters
|
||||
in the basic C character set, the byte must represent that character.</P>
|
||||
|
||||
<P>For example, the
|
||||
<B><A NAME="EUC encoding">EUC encoding</A></B> is a superset of ASCII.
|
||||
A byte value in the interval [0xA1, 0xFE] is the first of a two-byte
|
||||
sequence (whose second byte value is in the interval [0x80, 0xFF]).
|
||||
All other byte values are one-byte sequences. Since all members of the
|
||||
<A HREF="#basic C character set">basic C character set</A>
|
||||
have byte values in the range [0x00, 0x7F] in ASCII,
|
||||
EUC meets the requirements
|
||||
for a multibyte encoding in Standard C. Such a sequence is <I>not</I>
|
||||
in the initial conversion state immediately after a byte value in
|
||||
the interval [0xA1, 0xFe]. It is ill-formed if a second byte
|
||||
value is not in the interval [0x80, 0xFF].
|
||||
|
||||
<P>Multibyte characters can also have a
|
||||
<B><A NAME="state-dependent encoding">state-dependent encoding</A></B>.
|
||||
How you interpret a byte in such an encoding depends on a
|
||||
conversion state that involves both a
|
||||
<B><A NAME="parse state">parse state</A></B>, as before, and a
|
||||
<B><A NAME="shift state">shift state</A></B>, determined
|
||||
by bytes earlier in the sequence of characters. The
|
||||
<B><A NAME="initial shift state">initial shift state</A></B>,
|
||||
at the beginning of a new multibyte character, is also the
|
||||
initial conversion state. A subsequent
|
||||
<B><A NAME="shift sequence">shift sequence</A></B> can determine an
|
||||
<B><A NAME="alternate shift state">alternate shift state</A></B>,
|
||||
after which all byte sequences (including one-byte sequences) can have
|
||||
a different interpretation. A byte containing the value zero,
|
||||
however, always represents the
|
||||
<A HREF="#null character">null character</A>.
|
||||
It cannot occur as any of the bytes of another multibyte character.</P>
|
||||
|
||||
<P>For example, the
|
||||
<B><A NAME="JIS encoding">JIS encoding</A></B> is another superset of ASCII.
|
||||
In the initial shift state, each byte represents a single character,
|
||||
except for two three-byte shift sequences:</P>
|
||||
|
||||
<UL>
|
||||
<LI>The three-byte sequence <CODE>"\x1B$B"</CODE> shifts to two-byte mode.
|
||||
Subsequently, two successive bytes (both with values
|
||||
in the range [0x21, 0x7E]) constitute a single multibyte character.
|
||||
|
||||
<LI>The three-byte sequence <CODE>"\x1B(B"</CODE> shifts back
|
||||
to the initial shift state.
|
||||
</UL>
|
||||
|
||||
<P>JIS also meets the requirements for a multibyte encoding in Standard C.
|
||||
Such a sequence is <I>not</I> in the initial conversion state
|
||||
when partway through a three-byte shift sequence
|
||||
or when in two-byte mode.</P>
|
||||
|
||||
(<A HREF="lib_over.html#Amendment 1" tppabs="http://ccs.ucsd.edu/c/lib_over.html#Amendment 1">Amendment 1</A> adds the type
|
||||
<A HREF="wchar.html#mbstate_t" tppabs="http://ccs.ucsd.edu/c/wchar.html#mbstate_t"><CODE>mbstate_t</CODE></A>,
|
||||
which describes an object that can store a conversion state.
|
||||
It also relaxes the above rules for
|
||||
<A HREF="lib_file.html#generalized multibyte characters" tppabs="http://ccs.ucsd.edu/c/lib_file.html#generalized multibyte characters">
|
||||
generalized multibyte characters</A>, which describe the encoding
|
||||
rules for a broad range of
|
||||
<A HREF="lib_file.html#wide stream" tppabs="http://ccs.ucsd.edu/c/lib_file.html#wide stream">wide streams</A>.)
|
||||
|
||||
<P>You can write multibyte characters in C source text as part
|
||||
of a comment, a character constant, a string literal, or a filename in an
|
||||
<A HREF="preproc.html#include directive" tppabs="http://ccs.ucsd.edu/c/preproc.html#include directive"><I>include</I> directive</A>.
|
||||
How such characters print is
|
||||
<A HREF="portable.html#implementation defined" tppabs="http://ccs.ucsd.edu/c/portable.html#implementation defined">implementation defined</A>.
|
||||
Each sequence of multibyte characters that you write must
|
||||
begin and end in the initial shift state.
|
||||
The program can also include multibyte characters in
|
||||
<A HREF="#null-terminated string">null-terminated</A>
|
||||
<A HREF="lib_over.html#C string" tppabs="http://ccs.ucsd.edu/c/lib_over.html#C string">C strings</A>
|
||||
used by several library functions, including the
|
||||
<A HREF="lib_prin.html#format string" tppabs="http://ccs.ucsd.edu/c/lib_prin.html#format string">format strings</A> for
|
||||
<A HREF="stdio.html#printf" tppabs="http://ccs.ucsd.edu/c/stdio.html#printf"><CODE>printf</CODE></A> and
|
||||
<A HREF="stdio.html#scanf" tppabs="http://ccs.ucsd.edu/c/stdio.html#scanf"><CODE>scanf</CODE></A>.
|
||||
Each such character string must begin and end
|
||||
in the initial shift state.</P>
|
||||
|
||||
<H3><A NAME="Wide-Character Encoding">
|
||||
Wide-Character Encoding</A></H3>
|
||||
|
||||
<P>Each character in the extended character set also has an integer
|
||||
representation, called a <B>wide-character encoding</B>.
|
||||
Each extended character has a unique wide-character value.
|
||||
The value zero always corresponds to the
|
||||
<B><A NAME="null wide character">null wide character</A></B>.
|
||||
The type definition
|
||||
<A HREF="stddef.html#wchar_t" tppabs="http://ccs.ucsd.edu/c/stddef.html#wchar_t"><CODE>wchar_t</CODE></A>
|
||||
specifies the integer type that represents wide characters.</P>
|
||||
|
||||
<P>You write a
|
||||
<B><A NAME="wide-character constant">wide-character constant</A></B>
|
||||
as <CODE>L'mbc'</CODE>, where <CODE>mbc</CODE> represents
|
||||
a single multibyte character.
|
||||
You write a
|
||||
<B><A NAME="wide-character string literal">
|
||||
wide-character string literal</A></B> as <CODE>L"mbs"</CODE>,
|
||||
where <CODE>mbs</CODE> represents
|
||||
a sequence of zero or more multibyte characters.
|
||||
The wide-character string literal
|
||||
<CODE>L"xyz"</CODE> becomes a sequence of
|
||||
wide-character constants stored in successive bytes of memory, followed
|
||||
by a null wide character:<BR>
|
||||
<CODE>{L'x', L'y', L'z', L'\0'}</CODE>
|
||||
|
||||
<P>The following library functions
|
||||
help you convert between the multibyte
|
||||
and wide-character representations of extended characters:
|
||||
<A HREF="wchar.html#btowc" tppabs="http://ccs.ucsd.edu/c/wchar.html#btowc"><CODE>btowc</CODE></A>,
|
||||
<A HREF="stdlib.html#mblen" tppabs="http://ccs.ucsd.edu/c/stdlib.html#mblen"><CODE>mblen</CODE></A>,
|
||||
<A HREF="wchar.html#mbrlen" tppabs="http://ccs.ucsd.edu/c/wchar.html#mbrlen"><CODE>mbrlen</CODE></A>,
|
||||
<A HREF="wchar.html#mbrtowc" tppabs="http://ccs.ucsd.edu/c/wchar.html#mbrtowc"><CODE>mbrtowc</CODE></A>,
|
||||
<A HREF="wchar.html#mbsrtowcs" tppabs="http://ccs.ucsd.edu/c/wchar.html#mbsrtowcs"><CODE>mbsrtowcs</CODE></A>,
|
||||
<A HREF="stdlib.html#mbstowcs" tppabs="http://ccs.ucsd.edu/c/stdlib.html#mbstowcs"><CODE>mbstowcs</CODE></A>,
|
||||
<A HREF="stdlib.html#mbtowc" tppabs="http://ccs.ucsd.edu/c/stdlib.html#mbtowc"><CODE>mbtowc</CODE></A>,
|
||||
<A HREF="wchar.html#wcrtomb" tppabs="http://ccs.ucsd.edu/c/wchar.html#wcrtomb"><CODE>wcrtomb</CODE></A>,
|
||||
<A HREF="wchar.html#wcsrtombs" tppabs="http://ccs.ucsd.edu/c/wchar.html#wcsrtombs"><CODE>wcsrtombs</CODE></A>,
|
||||
<A HREF="stdlib.html#wcstombs" tppabs="http://ccs.ucsd.edu/c/stdlib.html#wcstombs"><CODE>wcstombs</CODE></A>,
|
||||
<A HREF="wchar.html#wctob" tppabs="http://ccs.ucsd.edu/c/wchar.html#wctob"><CODE>wctob</CODE></A>, and
|
||||
<A HREF="stdlib.html#wctomb" tppabs="http://ccs.ucsd.edu/c/stdlib.html#wctomb"><CODE>wctomb</CODE></A>.
|
||||
</P>
|
||||
|
||||
<P>The macro
|
||||
<A HREF="limits.html#MB_LEN_MAX" tppabs="http://ccs.ucsd.edu/c/limits.html#MB_LEN_MAX"><CODE>MB_LEN_MAX</CODE></A>
|
||||
specifies the length of the longest possible multibyte sequence required
|
||||
to represent a single character
|
||||
<A HREF="portable.html#implementation defined" tppabs="http://ccs.ucsd.edu/c/portable.html#implementation defined">defined</A>
|
||||
by the implementation across supported locales. And the macro
|
||||
<A HREF="stdlib.html#MB_CUR_MAX" tppabs="http://ccs.ucsd.edu/c/stdlib.html#MB_CUR_MAX"><CODE>MB_CUR_MAX</CODE></A>
|
||||
specifies the length of the longest possible multibyte sequence required
|
||||
to represent a single character defined for the current
|
||||
<A HREF="locale.html#locale" tppabs="http://ccs.ucsd.edu/c/locale.html#locale">locale</A>.</P>
|
||||
|
||||
<P>For example, the
|
||||
<A HREF="#string literal">string literal</A>
|
||||
<CODE>"hello"</CODE> becomes an array of six <I>char</I>:</P>
|
||||
|
||||
<PRE>
|
||||
{'h', 'e', 'l', 'l', 'o', 0}</PRE>
|
||||
|
||||
<P>while the wide-character string literal
|
||||
<CODE>L"hello"</CODE> becomes
|
||||
an array of six integers of type
|
||||
<A HREF="stddef.html#wchar_t" tppabs="http://ccs.ucsd.edu/c/stddef.html#wchar_t"><CODE>wchar_t</CODE></A>:</P>
|
||||
|
||||
<PRE>
|
||||
{L'h', L'e', L'l', L'l', L'o', 0}</PRE>
|
||||
|
||||
<HR>
|
||||
<P>See also the
|
||||
<B><A HREF="index.html#Table of Contents" tppabs="http://ccs.ucsd.edu/c/index.html#Table of Contents">Table of Contents</A></B> and the
|
||||
<B><A HREF="_index.html" tppabs="http://ccs.ucsd.edu/c/_index.html">Index</A></B>.</P>
|
||||
|
||||
<P><I>
|
||||
<A HREF="crit_pb.html" tppabs="http://ccs.ucsd.edu/c/crit_pb.html">Copyright</A> © 1989-1996
|
||||
by P.J. Plauger and Jim Brodie. All rights reserved.</I></P>
|
||||
|
||||
</BODY></HTML>
|
||||
BIN
study/Ref-docs/C/cont_f.gif
Normal file
|
After Width: | Height: | Size: 385 B |
BIN
study/Ref-docs/C/cont_s.gif
Normal file
|
After Width: | Height: | Size: 523 B |
102
study/Ref-docs/C/crit_pb.html
Normal file
@@ -0,0 +1,102 @@
|
||||
<HTML><HEAD><TITLE>Copyright Notice</TITLE></HEAD><BODY BGCOLOR="#FFFFFF">
|
||||
|
||||
<H1><A NAME="Copyright Notice">Copyright Notice</A></H1><HR>
|
||||
|
||||
<P>This material is derived from books copyright ©
|
||||
1989-1996 by P.J. Plauger and Jim Brodie, marked with a * in the
|
||||
<A HREF="#References">References</A> below.
|
||||
Each copy of this material is sold or licensed for use
|
||||
<B>just like a book</B>:</P>
|
||||
|
||||
<UL>
|
||||
<LI>You are entitled to use a single copy, but not make multiple
|
||||
copies for use by others.
|
||||
|
||||
<LI>You can transfer ownership of the copy, but not keep a copy
|
||||
once you've done so.
|
||||
|
||||
<LI>You must preserve this and other copyright notices in any
|
||||
copies you make.
|
||||
|
||||
<LI>You have a moral responsibility not to aid or abet illegal
|
||||
copying by others.
|
||||
</UL>
|
||||
|
||||
<P>The authors recognize that this format is particularly
|
||||
conducive to sharing within multiuser systems and across
|
||||
networks. Such use is specifically permitted, provided the
|
||||
letter and the spirit of the above restrictions are honored.
|
||||
In particular, please note that the ability to <I>access</I>
|
||||
this document does not imply permission to <I>copy</I> it.</P>
|
||||
|
||||
<P>Finally, please note that the authors have expended considerable
|
||||
professional effort in the production of this material, and
|
||||
continue to do so to keep it current.</P>
|
||||
|
||||
<H2><A NAME="References">References</A></H2>
|
||||
|
||||
<UL>
|
||||
<LI><B>ANSI Standard X3.159-1989</B>
|
||||
(New York NY: American National Standards Institute, 1989).
|
||||
The original C Standard, developed by
|
||||
the ANSI-authorized committee X3J11. The Rationale that accompanies
|
||||
the C Standard explains many of the decisions that went into it, if
|
||||
you can get your hands on a copy.
|
||||
|
||||
<LI><B>ISO/IEC Standard 9899:1990</B>
|
||||
(Geneva: International Standards Organization, 1990).
|
||||
The official C Standard around the world. Aside
|
||||
from formatting details and section numbering, the ISO C Standard
|
||||
is identical to the ANSI C Standard.
|
||||
|
||||
<LI><B>ISO/IEC Amendment 1 to Standard 9899:1990</B>
|
||||
(Geneva: International Standards Organization, 1995).
|
||||
The first (and only) amendment to the C Standard.
|
||||
It provides substantial support for manipulating large character sets.
|
||||
|
||||
<LI>P.J. Plauger, <B>The Standard C Library</B> (Englewood Cliffs
|
||||
NJ: Prentice Hall, 1992). Contains a complete implementation of the
|
||||
Standard C library, as well as text from the library portion of the
|
||||
C Standard and guidance in using the Standard C library.
|
||||
|
||||
<LI>* P.J. Plauger and Jim Brodie, <B>Standard C: A Programmer's
|
||||
Reference</B> (Redmond WA: Microsoft Press, 1989).
|
||||
The first complete but succinct reference to the entire C Standard.
|
||||
It covers both the language and the library.
|
||||
|
||||
<LI>* P.J. Plauger and Jim Brodie, <B>ANSI and ISO Standard C:
|
||||
Programmer's Reference</B> (Redmond WA: Microsoft Press, 1992).
|
||||
An update to the above book.
|
||||
|
||||
<LI>* P.J. Plauger and Jim Brodie, <B>Standard C</B> (Englewood Cliffs NJ:
|
||||
PTR Prentice Hall, 1996). An update to the above two books and
|
||||
the principal source book for this material. It includes a
|
||||
complete description of Amendment 1.
|
||||
</UL>
|
||||
|
||||
<H2><A NAME="Bug Reports">Bug Reports</A></H2>
|
||||
|
||||
<P>The authors welcome reports of any errors or omissions.
|
||||
Please send them to:</P>
|
||||
|
||||
<PRE>
|
||||
P.J. Plauger
|
||||
398 Main Street
|
||||
Concord MA 01742-2321
|
||||
USA
|
||||
|
||||
+1-508-369-8489
|
||||
+1-508-371-9014 fax
|
||||
|
||||
<B><A HREF="mailto:pjp@plauger.com">pjp@plauger.com</B></PRE>
|
||||
|
||||
<HR>
|
||||
<P>See also the
|
||||
<B><A HREF="index.html#Table of Contents" tppabs="http://ccs.ucsd.edu/c/index.html#Table of Contents">Table of Contents</A></B> and the
|
||||
<B><A HREF="_index.html" tppabs="http://ccs.ucsd.edu/c/_index.html">Index</A></B>.</P>
|
||||
|
||||
<P><I>
|
||||
Copyright © 1989-1996
|
||||
by P.J. Plauger and Jim Brodie. All rights reserved.</I></P>
|
||||
|
||||
</BODY></HTML>
|
||||
BIN
study/Ref-docs/C/ctype.gif
Normal file
|
After Width: | Height: | Size: 3.0 KiB |
290
study/Ref-docs/C/ctype.html
Normal file
@@ -0,0 +1,290 @@
|
||||
<HTML><HEAD><TITLE><ctype.h></TITLE></HEAD><BODY BGCOLOR="#FFFFFF">
|
||||
|
||||
<H1><A NAME="<ctype.h>"><CODE><ctype.h></CODE></A></H1><HR>
|
||||
|
||||
<P><CODE>
|
||||
int <A HREF="#isalnum"><B>isalnum</B></A>(int c);<BR>
|
||||
int <A HREF="#isalpha"><B>isalpha</B></A>(int c);<BR>
|
||||
int <A HREF="#iscntrl"><B>iscntrl</B></A>(int c);<BR>
|
||||
int <A HREF="#isdigit"><B>isdigit</B></A>(int c);<BR>
|
||||
int <A HREF="#isgraph"><B>isgraph</B></A>(int c);<BR>
|
||||
int <A HREF="#islower"><B>islower</B></A>(int c);<BR>
|
||||
int <A HREF="#isprint"><B>isprint</B></A>(int c);<BR>
|
||||
int <A HREF="#ispunct"><B>ispunct</B></A>(int c);<BR>
|
||||
int <A HREF="#isspace"><B>isspace</B></A>(int c);<BR>
|
||||
int <A HREF="#isupper"><B>isupper</B></A>(int c);<BR>
|
||||
int <A HREF="#isxdigit"><B>isxdigit</B></A>(int c);<BR>
|
||||
int <A HREF="#tolower"><B>tolower</B></A>(int c);<BR>
|
||||
int <A HREF="#toupper"><B>toupper</B></A>(int c);
|
||||
</CODE></P>
|
||||
|
||||
<P>Include the standard header <B><CODE><ctype.h></CODE></B>
|
||||
to declare several functions that are useful
|
||||
for classifying and mapping codes from the
|
||||
target character set. Every function that has a parameter of type
|
||||
<I>int</I> can accept the value of the macro
|
||||
<A HREF="stdio.html#EOF" tppabs="http://ccs.ucsd.edu/c/stdio.html#EOF"><CODE>EOF</CODE></A> or any value
|
||||
representable as type <I>unsigned char.</I> Thus, the argument can
|
||||
be the value returned by any of the functions
|
||||
<A HREF="stdio.html#fgetc" tppabs="http://ccs.ucsd.edu/c/stdio.html#fgetc"><CODE>fgetc</CODE></A>,
|
||||
<A HREF="stdio.html#fputc" tppabs="http://ccs.ucsd.edu/c/stdio.html#fputc"><CODE>fputc</CODE></A>,
|
||||
<A HREF="stdio.html#getc" tppabs="http://ccs.ucsd.edu/c/stdio.html#getc"><CODE>getc</CODE></A>,
|
||||
<A HREF="stdio.html#getchar" tppabs="http://ccs.ucsd.edu/c/stdio.html#getchar"><CODE>getchar</CODE></A>,
|
||||
<A HREF="stdio.html#putc" tppabs="http://ccs.ucsd.edu/c/stdio.html#putc"><CODE>putc</CODE></A>,
|
||||
<A HREF="stdio.html#putchar" tppabs="http://ccs.ucsd.edu/c/stdio.html#putchar"><CODE>putchar</CODE></A>,
|
||||
<A HREF="#tolower"><CODE>tolower</CODE></A>,
|
||||
<A HREF="#toupper"><CODE>toupper</CODE></A>, and
|
||||
<A HREF="stdio.html#ungetc" tppabs="http://ccs.ucsd.edu/c/stdio.html#ungetc"><CODE>ungetc</CODE></A>.
|
||||
You must not call these functions
|
||||
with other argument values.</P>
|
||||
|
||||
<P>Other library functions use these functions. The function
|
||||
<A HREF="stdio.html#scanf" tppabs="http://ccs.ucsd.edu/c/stdio.html#scanf"><CODE>scanf</CODE></A>,
|
||||
for example, uses the function
|
||||
<A HREF="#isspace"><CODE>isspace</CODE></A>
|
||||
to determine valid white space within an input field.</P>
|
||||
|
||||
<P>The
|
||||
<B><A NAME="character classification">character classification</A></B>
|
||||
functions are strongly interrelated.
|
||||
Many are defined in terms of other functions. For characters in the
|
||||
<A HREF="charset.html#basic C character set" tppabs="http://ccs.ucsd.edu/c/charset.html#basic C character set">
|
||||
basic C character set</A>, here are
|
||||
the dependencies between these functions:</P>
|
||||
|
||||
<P><IMG SRC="ctype.gif" tppabs="http://ccs.ucsd.edu/c/gif/ctype.gif"></P>
|
||||
|
||||
<P>The diagram tells you that the function
|
||||
<A HREF="#isprint"><CODE>isprint</CODE></A>
|
||||
returns nonzero for <CODE><I>space</I></CODE> or for
|
||||
any character for which the function
|
||||
<A HREF="#isgraph"><CODE>isgraph</CODE></A> returns nonzero.
|
||||
The function
|
||||
<A HREF="#isgraph"><CODE>isgraph</CODE></A>, in turn,
|
||||
returns nonzero for any character for which either the function
|
||||
<A HREF="#isalnum"><CODE>isalnum</CODE></A> or the function
|
||||
<A HREF="#ispunct"><CODE>ispunct</CODE></A>
|
||||
returns nonzero. The function
|
||||
<A HREF="#isdigit"><CODE>isdigit</CODE></A>,
|
||||
on the other hand, returns nonzero only for the digits
|
||||
<CODE>0-9</CODE>.</P>
|
||||
|
||||
<P>An implementation can define additional characters that return
|
||||
nonzero for some of these functions. Any character set can contain
|
||||
additional characters that return nonzero for:</P>
|
||||
|
||||
<UL>
|
||||
<LI><A HREF="#ispunct"><CODE>ispunct</CODE></A>
|
||||
(provided the characters cause
|
||||
<A HREF="#isalnum"><CODE>isalnum</CODE></A> to return zero)
|
||||
|
||||
<LI><A HREF="#iscntrl"><CODE>iscntrl</CODE></A>
|
||||
(provided the characters cause
|
||||
<A HREF="#isprint"><CODE>isprint</CODE></A> to return zero)
|
||||
</UL>
|
||||
|
||||
<P>The diagram indicates with <CODE>++</CODE> those functions that can
|
||||
define additional characters in any character set.
|
||||
Moreover, locales other than the
|
||||
<A HREF="locale.html#C locale" tppabs="http://ccs.ucsd.edu/c/locale.html#C locale"><CODE>"C"</CODE></A> locale
|
||||
can define additional characters that return nonzero for:
|
||||
|
||||
<UL>
|
||||
<LI><A HREF="#isalpha"><CODE>isalpha</CODE></A>,
|
||||
<A HREF="#isupper"><CODE>isupper</CODE></A>, and
|
||||
<A HREF="#islower"><CODE>islower</CODE></A>
|
||||
(provided the characters cause
|
||||
<A HREF="#iscntrl"><CODE>iscntrl</CODE></A>,
|
||||
<A HREF="#isdigit"><CODE>isdigit</CODE></A>,
|
||||
<A HREF="#ispunct"><CODE>ispunct</CODE></A>, and
|
||||
<A HREF="#isspace"><CODE>isspace</CODE></A> to return zero)
|
||||
|
||||
<LI><A HREF="#isspace"><CODE>isspace</CODE></A>
|
||||
(provided the characters cause
|
||||
<A HREF="#isprint"><CODE>isprint</CODE></A> to return zero)
|
||||
</UL>
|
||||
|
||||
<P>The diagram indicates with <CODE>+</CODE> those functions that can
|
||||
define additional characters in locales other than the
|
||||
<A HREF="locale.html#C locale" tppabs="http://ccs.ucsd.edu/c/locale.html#C locale"><CODE>"C"</CODE></A> locale.</P>
|
||||
|
||||
<P>Note that an implementation can define locales other than the
|
||||
<A HREF="locale.html#C locale" tppabs="http://ccs.ucsd.edu/c/locale.html#C locale"><CODE>"C"</CODE></A> locale
|
||||
in which a character can cause
|
||||
<A HREF="#isalpha"><CODE>isalpha</CODE></A> (and hence
|
||||
<A HREF="#isalnum"><CODE>isalnum</CODE>)</A>
|
||||
to return nonzero, yet still cause
|
||||
<A HREF="#isupper"><CODE>isupper</CODE></A> and
|
||||
<A HREF="#islower"><CODE>islower</CODE></A> to return zero.
|
||||
|
||||
<H2><A NAME="isalnum"><CODE>isalnum</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
int <B>isalnum</B>(int c);
|
||||
</CODE></P>
|
||||
|
||||
<P>The function returns nonzero if <CODE>c</CODE> is any of:</P>
|
||||
|
||||
<PRE>
|
||||
a b c d e f g h i j k l m n o p q r s t u v w x y z
|
||||
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
|
||||
o 1 2 3 4 5 6 7 8 9</PRE>
|
||||
|
||||
<P>or any other locale-specific alphabetic character.</P>
|
||||
|
||||
<H2><A NAME="isalpha"><CODE>isalpha</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
int <B>isalpha</B>(int c);
|
||||
</CODE></P>
|
||||
|
||||
<P>The function returns nonzero if <CODE>c</CODE> is any of:</P>
|
||||
|
||||
<PRE>
|
||||
a b c d e f g h i j k l m n o p q r s t u v w x y z
|
||||
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z</PRE>
|
||||
|
||||
<P>or any other locale-specific alphabetic character.</P>
|
||||
|
||||
<H2><A NAME="iscntrl"><CODE>iscntrl</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
int <B>iscntrl</B>(int c);
|
||||
</CODE></P>
|
||||
|
||||
<P>The function returns nonzero if <CODE>c</CODE> is any of:</P>
|
||||
|
||||
<PRE>
|
||||
<I>BEL BS CR FF HT NL VT</I></PRE>
|
||||
|
||||
<P>or any other implementation-defined control character.</P>
|
||||
|
||||
<H2><A NAME="isdigit"><CODE>isdigit</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
int <B>isdigit</B>(int c);
|
||||
</CODE></P>
|
||||
|
||||
<P>The function returns nonzero if <CODE>c</CODE> is any of:</P>
|
||||
|
||||
<PRE>
|
||||
0 1 2 3 4 5 6 7 8 9</PRE>
|
||||
|
||||
<H2><A NAME="isgraph"><CODE>isgraph</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
int <B>isgraph</B>(int c);
|
||||
</CODE></P>
|
||||
|
||||
<P>The function returns nonzero if <CODE>c</CODE>
|
||||
is any character for which either
|
||||
<A HREF="#isalnum"><CODE>isalnum</CODE></A> or
|
||||
<A HREF="#ispunct"><CODE>ispunct</CODE></A> returns nonzero.</P>
|
||||
|
||||
<H2><A NAME="islower"><CODE>islower</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
int <B>islower</B>(int c);
|
||||
</CODE></P>
|
||||
|
||||
<P>The function returns nonzero if <CODE>c</CODE> is any of:</P>
|
||||
|
||||
<PRE>
|
||||
a b c d e f g h i j k l m n o p q r s t u v w x y z</PRE>
|
||||
|
||||
<P>or any other locale-specific lowercase character.</P>
|
||||
|
||||
<H2><A NAME="isprint"><CODE>isprint</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
int <B>isprint</B>(int c);
|
||||
</CODE></P>
|
||||
|
||||
<P>The function returns nonzero if <CODE>c</CODE> is
|
||||
<CODE><I>space</I></CODE> or a character for which
|
||||
<A HREF="#isgraph"><CODE>isgraph</CODE></A> returns nonzero.</P>
|
||||
|
||||
<H2><A NAME="ispunct"><CODE>ispunct</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
int <B>ispunct</B>(int c);
|
||||
</CODE></P>
|
||||
|
||||
<P>The function returns nonzero if <CODE>c</CODE> is any of:</P>
|
||||
|
||||
<PRE>
|
||||
! " # % & ' ( ) ; <
|
||||
= > ? [ \ ] * + , -
|
||||
. / : ^ _ { | } ~</PRE>
|
||||
|
||||
<P>or any other implementation-defined punctuation character.</P>
|
||||
|
||||
<H2><A NAME="isspace"><CODE>isspace</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
int <B>isspace</B>(int c);
|
||||
</CODE></P>
|
||||
|
||||
<P>The function returns nonzero if <CODE>c</CODE> is any of:</P>
|
||||
|
||||
<PRE>
|
||||
<I>CR FF HT NL VT space</I></PRE>
|
||||
|
||||
<P>or any other locale-specific space character.</P>
|
||||
|
||||
<H2><A NAME="isupper"><CODE>isupper</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
int <B>isupper</B>(int c);
|
||||
</CODE></P>
|
||||
|
||||
<P>The function returns nonzero if <CODE>c</CODE> is any of:</P>
|
||||
|
||||
<PRE>
|
||||
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z</PRE>
|
||||
|
||||
<P>or any other locale-specific uppercase character.</P>
|
||||
|
||||
<H2><A NAME="isxdigit"><CODE>isxdigit</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
int <B>isxdigit</B>(int c);
|
||||
</CODE></P>
|
||||
|
||||
<P>The function returns nonzero if <CODE>c</CODE> is any of:</P>
|
||||
|
||||
<PRE>
|
||||
0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F</PRE>
|
||||
|
||||
<H2><A NAME="tolower"><CODE>tolower</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
int <B>tolower</B>(int c);
|
||||
</CODE></P>
|
||||
|
||||
<P>The function returns the corresponding lowercase letter if one
|
||||
exists and if
|
||||
<CODE><A HREF="#isupper">isupper</A>(c)</CODE>;
|
||||
otherwise, it returns <CODE>c</CODE>.</P>
|
||||
|
||||
<H2><A NAME="toupper"><CODE>toupper</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
int <B>toupper</B>(int c);
|
||||
</CODE></P>
|
||||
|
||||
<P>The function returns the corresponding uppercase letter if one
|
||||
exists and if
|
||||
<CODE><A HREF="#islower">islower</A>(c)</CODE>;
|
||||
otherwise, it returns <CODE>c</CODE>.</P>
|
||||
|
||||
<HR>
|
||||
<P>See also the
|
||||
<B><A HREF="index.html#Table of Contents" tppabs="http://ccs.ucsd.edu/c/index.html#Table of Contents">Table of Contents</A></B> and the
|
||||
<B><A HREF="_index.html" tppabs="http://ccs.ucsd.edu/c/_index.html">Index</A></B>.</P>
|
||||
|
||||
<P><I>
|
||||
<A HREF="crit_pb.html" tppabs="http://ccs.ucsd.edu/c/crit_pb.html">Copyright</A> © 1989-1996
|
||||
by P.J. Plauger and Jim Brodie. All rights reserved.</I></P>
|
||||
|
||||
</BODY></HTML>
|
||||
BIN
study/Ref-docs/C/decl.gif
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
study/Ref-docs/C/decl_tor.gif
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
1045
study/Ref-docs/C/declare.html
Normal file
BIN
study/Ref-docs/C/def_f.gif
Normal file
|
After Width: | Height: | Size: 629 B |
BIN
study/Ref-docs/C/def_s.gif
Normal file
|
After Width: | Height: | Size: 608 B |
BIN
study/Ref-docs/C/define.gif
Normal file
|
After Width: | Height: | Size: 1.4 KiB |
BIN
study/Ref-docs/C/do_f.gif
Normal file
|
After Width: | Height: | Size: 988 B |
BIN
study/Ref-docs/C/do_s.gif
Normal file
|
After Width: | Height: | Size: 868 B |
BIN
study/Ref-docs/C/elif.gif
Normal file
|
After Width: | Height: | Size: 682 B |
BIN
study/Ref-docs/C/else.gif
Normal file
|
After Width: | Height: | Size: 554 B |
BIN
study/Ref-docs/C/end_line.gif
Normal file
|
After Width: | Height: | Size: 400 B |
BIN
study/Ref-docs/C/endif.gif
Normal file
|
After Width: | Height: | Size: 583 B |
79
study/Ref-docs/C/errno.html
Normal file
@@ -0,0 +1,79 @@
|
||||
<HTML><HEAD><TITLE><errno.h></TITLE></HEAD><BODY BGCOLOR="#FFFFFF">
|
||||
|
||||
<H1><A NAME="<errno.h>"><CODE><errno.h></CODE></A></H1><HR>
|
||||
|
||||
<P><CODE>
|
||||
#define <A HREF="#EDOM"><B>EDOM</B></A>
|
||||
<I><#if expression></I><BR>
|
||||
#define <A HREF="#EILSEQ"><B>EILSEQ</B></A>
|
||||
<I><#if expression></I><BR>
|
||||
#define <A HREF="#ERANGE"><B>ERANGE</B></A>
|
||||
<I><#if expression></I><BR>
|
||||
#define <A HREF="#errno"><B>errno</B></A>
|
||||
<I><int modifiable lvalue></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>Include the standard header <B><CODE><errno.h></CODE></B>
|
||||
to test the value stored in
|
||||
<A HREF="#errno"><CODE>errno</CODE></A>
|
||||
by certain library functions. At program startup, the value stored
|
||||
is zero. Library functions store only values greater than zero.
|
||||
Any library function can alter the value stored, but
|
||||
only those cases where a library function is explicitly
|
||||
required to store a value are documented here.</P>
|
||||
|
||||
<P>To test whether a library function stores a value in
|
||||
<A HREF="#errno"><CODE>errno</CODE></A>,
|
||||
the program should store the value zero there immediately before
|
||||
it calls the library function. An implementation can define additional
|
||||
macros in this standard header that you can test for equality with
|
||||
the value stored. All these additional macros have
|
||||
names that begin with <CODE>E</CODE>.</P>
|
||||
|
||||
<H2><A NAME="EDOM"><CODE>EDOM</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>EDOM</B> <I><#if expression></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the value stored in
|
||||
<A HREF="#errno"><CODE>errno</CODE></A> on a domain error.</P>
|
||||
|
||||
<H2><A NAME="EILSEQ"><CODE>EILSEQ</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>EILSEQ</B> <I><#if expression></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the value stored in
|
||||
<A HREF="#errno"><CODE>errno</CODE></A> on an invalid
|
||||
multibyte sequence.</P>
|
||||
|
||||
<H2><A NAME="ERANGE"><CODE>ERANGE</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>ERANGE</B> <I><#if expression></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the value stored in
|
||||
<A HREF="#errno"><CODE>errno</CODE></A> on a range error.</P>
|
||||
|
||||
<H2><A NAME="errno"><CODE>errno</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>errno</B> <I><int modifiable lvalue></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro designates an object that is assigned a value greater
|
||||
than zero on certain library errors.</P>
|
||||
|
||||
<HR>
|
||||
<P>See also the
|
||||
<B><A HREF="index.html#Table of Contents" tppabs="http://ccs.ucsd.edu/c/index.html#Table of Contents">Table of Contents</A></B> and the
|
||||
<B><A HREF="_index.html" tppabs="http://ccs.ucsd.edu/c/_index.html">Index</A></B>.</P>
|
||||
|
||||
<P><I>
|
||||
<A HREF="crit_pb.html" tppabs="http://ccs.ucsd.edu/c/crit_pb.html">Copyright</A> © 1989-1996
|
||||
by P.J. Plauger and Jim Brodie. All rights reserved.</I></P>
|
||||
|
||||
</BODY></HTML>
|
||||
BIN
study/Ref-docs/C/error.gif
Normal file
|
After Width: | Height: | Size: 761 B |
BIN
study/Ref-docs/C/escape.gif
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
BIN
study/Ref-docs/C/expr.gif
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
study/Ref-docs/C/expr_cl.gif
Normal file
|
After Width: | Height: | Size: 4.3 KiB |
BIN
study/Ref-docs/C/expr_f.gif
Normal file
|
After Width: | Height: | Size: 466 B |
BIN
study/Ref-docs/C/expr_s.gif
Normal file
|
After Width: | Height: | Size: 549 B |
2193
study/Ref-docs/C/express.html
Normal file
380
study/Ref-docs/C/float.html
Normal file
@@ -0,0 +1,380 @@
|
||||
<HTML><HEAD><TITLE><float.h></TITLE></HEAD><BODY BGCOLOR="#FFFFFF">
|
||||
|
||||
<H1><A NAME="<float.h>"><CODE><float.h></CODE></A></H1><HR>
|
||||
|
||||
<P><CODE>
|
||||
#define <A HREF="#DBL_DIG"><B>DBL_DIG</B></A>
|
||||
<I><integer rvalue >= 10></I><BR>
|
||||
#define <A HREF="#DBL_EPSILON"><B>DBL_EPSILON</B></A>
|
||||
<I><double rvalue <= 10^(-9)></I><BR>
|
||||
#define <A HREF="#DBL_MANT_DIG"><B>DBL_MANT_DIG</B></A>
|
||||
<I><integer rvalue></I><BR>
|
||||
#define <A HREF="#DBL_MAX"><B>DBL_MAX</B></A>
|
||||
<I><double rvalue >= 10^37></I><BR>
|
||||
#define <A HREF="#DBL_MAX_10_EXP"><B>DBL_MAX_10_EXP</B></A>
|
||||
<I><integer rvalue >= 37></I><BR>
|
||||
#define <A HREF="#DBL_MAX_EXP"><B>DBL_MAX_EXP</B></A>
|
||||
<I><integer rvalue></I><BR>
|
||||
#define <A HREF="#DBL_MIN"><B>DBL_MIN</B></A>
|
||||
<I><double rvalue <= 10^(-37)></I><BR>
|
||||
#define <A HREF="#DBL_MIN_10_EXP"><B>DBL_MIN_10_EXP</B></A>
|
||||
<I><integer rvalue <= -37></I><BR>
|
||||
#define <A HREF="#DBL_MIN_EXP"><B>DBL_MIN_EXP</B></A>
|
||||
<I><integer rvalue></I><BR>
|
||||
#define <A HREF="#FLT_DIG"><B>FLT_DIG</B></A>
|
||||
<I><integer rvalue >= 6></I><BR>
|
||||
#define <A HREF="#FLT_EPSILON"><B>FLT_EPSILON</B></A>
|
||||
<I><float rvalue <= 10^(-5)></I><BR>
|
||||
#define <A HREF="#FLT_MANT_DIG"><B>FLT_MANT_DIG</B></A>
|
||||
<I><integer rvalue></I><BR>
|
||||
#define <A HREF="#FLT_MAX"><B>FLT_MAX</B></A>
|
||||
<I><float rvalue >= 10^37></I><BR>
|
||||
#define <A HREF="#FLT_MAX_10_EXP"><B>FLT_MAX_10_EXP</B></A>
|
||||
<I><integer rvalue >= 37></I><BR>
|
||||
#define <A HREF="#FLT_MAX_EXP"><B>FLT_MAX_EXP</B></A>
|
||||
<I><integer rvalue></I><BR>
|
||||
#define <A HREF="#FLT_MIN"><B>FLT_MIN</B></A>
|
||||
<I><float rvalue <= 10^(-37)></I><BR>
|
||||
#define <A HREF="#FLT_MIN_10_EXP"><B>FLT_MIN_10_EXP</B></A>
|
||||
<I><integer rvalue <= -37></I><BR>
|
||||
#define <A HREF="#FLT_MIN_EXP"><B>FLT_MIN_EXP</B></A>
|
||||
<I><integer rvalue></I><BR>
|
||||
#define <A HREF="#FLT_RADIX"><B>FLT_RADIX</B></A>
|
||||
<I><#if expression >= 2></I><BR>
|
||||
#define <A HREF="#FLT_ROUNDS"><B>FLT_ROUNDS</B></A>
|
||||
<I><integer rvalue></I><BR>
|
||||
#define <A HREF="#LDBL_DIG"><B>LDBL_DIG</B></A>
|
||||
<I><integer rvalue >= 10></I><BR>
|
||||
#define <A HREF="#LDBL_EPSILON"><B>LDBL_EPSILON</B></A>
|
||||
<I><long double rvalue <= 10^(-9)></I><BR>
|
||||
#define <A HREF="#LDBL_MANT_DIG"><B>LDBL_MANT_DIG</B></A>
|
||||
<I><integer rvalue></I><BR>
|
||||
#define <A HREF="#LDBL_MAX"><B>LDBL_MAX</B></A>
|
||||
<I><long double rvalue >= 10^37></I><BR>
|
||||
#define <A HREF="#LDBL_MAX_10_EXP"><B>LDBL_MAX_10_EXP</B></A>
|
||||
<I><integer rvalue >= 37></I><BR>
|
||||
#define <A HREF="#LDBL_MAX_EXP"><B>LDBL_MAX_EXP</B></A>
|
||||
<I><integer rvalue></I><BR>
|
||||
#define <A HREF="#LDBL_MIN"><B>LDBL_MIN</B></A>
|
||||
<I><long double rvalue <= 10^(-37)></I><BR>
|
||||
#define <A HREF="#LDBL_MIN_10_EXP"><B>LDBL_MIN_10_EXP</B></A>
|
||||
<I><integer rvalue <= -37></I><BR>
|
||||
#define <A HREF="#LDBL_MIN_EXP"><B>LDBL_MIN_EXP</B></A>
|
||||
<I><integer rvalue></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>Include the standard header <B><CODE><float.h></CODE></B>
|
||||
to determine various properties of floating-point type representations.
|
||||
The standard header <CODE><float.h></CODE> is available even in a
|
||||
<A HREF="lib_over.html#freestanding implementation" tppabs="http://ccs.ucsd.edu/c/lib_over.html#freestanding implementation">
|
||||
freestanding implementation</A>.</P>
|
||||
|
||||
<P>You can test only the value of the macro
|
||||
<A HREF="#FLT_RADIX"><CODE>FLT_RADIX</CODE></A> in an
|
||||
<A HREF="preproc.html#if directive" tppabs="http://ccs.ucsd.edu/c/preproc.html#if directive"><I>if</I> directive</A>.
|
||||
(The macro expands to a
|
||||
<A HREF="preproc.html#if expression" tppabs="http://ccs.ucsd.edu/c/preproc.html#if expression"><I><I>#if</I> expression</A>.)
|
||||
All other macros defined in this header expand to expressions whose
|
||||
values can be determined only when the program executes. (These macros are
|
||||
<A HREF="express.html#rvalue expression" tppabs="http://ccs.ucsd.edu/c/express.html#rvalue expression">rvalue expressions</A>.)
|
||||
Some target environments can change
|
||||
the rounding and error-reporting properties of floating-point type
|
||||
representations while the program is running.</P>
|
||||
|
||||
<H2><A NAME="DBL_DIG"><CODE>DBL_DIG</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>DBL_DIG</B> <I><integer rvalue >= 10></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the precision in decimal digits for
|
||||
type <I>double.</I></P>
|
||||
|
||||
<H2><A NAME="DBL_EPSILON"><CODE>DBL_EPSILON</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>DBL_EPSILON</B> <I><double rvalue <= 10^(-9)></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the smallest <I>X</I> of type <I>double</I>
|
||||
such that 1.0 + <I>X</I> != 1.0.</P>
|
||||
|
||||
<H2><A NAME="DBL_MANT_DIG"><CODE>DBL_MANT_DIG</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>DBL_MANT_DIG</B> <I><integer rvalue></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the number of mantissa digits, base
|
||||
<A HREF="#FLT_RADIX"><CODE>FLT_RADIX</CODE></A>,
|
||||
for type <I>double.</I></P>
|
||||
|
||||
<H2><A NAME="DBL_MAX"><CODE>DBL_MAX</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>DBL_MAX</B> <I><double rvalue >= 10^37></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the largest finite representable value
|
||||
of type <I>double.</I></P>
|
||||
|
||||
<H2><A NAME="DBL_MAX_10_EXP"><CODE>DBL_MAX_10_EXP</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>DBL_MAX_10_EXP</B> <I><integer rvalue >= 37></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the maximum integer <I>X,</I> such that
|
||||
10^<I>X</I> is a finite representable value of type <I>double.</I></P>
|
||||
|
||||
<H2><A NAME="DBL_MAX_EXP"><CODE>DBL_MAX_EXP</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>DBL_MAX_EXP</B> <I><integer rvalue></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the maximum integer <I>X,</I> such that
|
||||
<A HREF="#FLT_RADIX"><CODE>FLT_RADIX</CODE></A>^(<I>X</I> - 1)
|
||||
is a finite representable value of type <I>double.</I></P>
|
||||
|
||||
<H2><A NAME="DBL_MIN"><CODE>DBL_MIN</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>DBL_MIN</B> <I><double rvalue <= 10^(-37)></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the smallest normalized, finite representable
|
||||
value of type <I>double.</I></P>
|
||||
|
||||
<H2><A NAME="DBL_MIN_10_EXP"><CODE>DBL_MIN_10_EXP</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>DBL_MIN_10_EXP</B> <I><integer rvalue <= -37></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the minimum integer <I>X</I> such that
|
||||
10^<I>X</I> is a normalized, finite representable value
|
||||
of type <I>double.</I></P>
|
||||
|
||||
<H2><A NAME="DBL_MIN_EXP"><CODE>DBL_MIN_EXP</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>DBL_MIN_EXP</B> <I><integer rvalue></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the minimum integer <I>X</I> such that
|
||||
<A HREF="#FLT_RADIX"><CODE>FLT_RADIX</CODE></A>^(<I>X</I> - 1)
|
||||
is a normalized, finite representable value of type <I>double.</I></P>
|
||||
|
||||
<H2><A NAME="FLT_DIG"><CODE>FLT_DIG</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>FLT_DIG</B> <I><integer rvalue >= 6></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the precision in decimal digits
|
||||
for type <I>float.</I></P>
|
||||
|
||||
<H2><A NAME="FLT_EPSILON"><CODE>FLT_EPSILON</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>FLT_EPSILON</B> <I><float rvalue <= 10^(-5)></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the smallest <I>X</I> of type <I>float</I>
|
||||
such that 1.0 + <I>X</I> != 1.0.</P>
|
||||
|
||||
<H2><A NAME="FLT_MANT_DIG"><CODE>FLT_MANT_DIG</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>FLT_MANT_DIG</B> <I><integer rvalue></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the number of mantissa digits, base
|
||||
<A HREF="#FLT_RADIX"><CODE>FLT_RADIX</CODE></A>,
|
||||
for type <I>float.</I></P>
|
||||
|
||||
<H2><A NAME="FLT_MAX"><CODE>FLT_MAX</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>FLT_MAX</B> <I><float rvalue >= 10^37></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the largest finite representable value
|
||||
of type <I>float.</I></P>
|
||||
|
||||
<H2><A NAME="FLT_MAX_10_EXP"><CODE>FLT_MAX_10_EXP</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>FLT_MAX_10_EXP</B> <I><integer rvalue >= 37></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the maximum integer <I>X,</I> such that 10^<I>X</I>
|
||||
is a finite representable value of type <I>float.</I></P>
|
||||
|
||||
<H2><A NAME="FLT_MAX_EXP"><CODE>FLT_MAX_EXP</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>FLT_MAX_EXP</B> <I><integer rvalue></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the maximum integer <I>X,</I> such that
|
||||
<A HREF="#FLT_RADIX"><CODE>FLT_RADIX</CODE></A>^(<I>X</I> - 1)
|
||||
is a finite representable value of type <I>float.</I></P>
|
||||
|
||||
<H2><A NAME="FLT_MIN"><CODE>FLT_MIN</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>FLT_MIN</B> <I><float rvalue <= 10^(-37)></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the smallest normalized, finite representable
|
||||
value of type <I>float.</I></P>
|
||||
|
||||
<H2><A NAME="FLT_MIN_10_EXP"><CODE>FLT_MIN_10_EXP</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>FLT_MIN_10_EXP</B> <I><integer rvalue <= -37></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the minimum integer <I>X,</I> such that 10^<I>X</I>
|
||||
is a normalized, finite representable value of type <I>float.</I></P>
|
||||
|
||||
<H2><A NAME="FLT_MIN_EXP"><CODE>FLT_MIN_EXP</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>FLT_MIN_EXP</B> <I><integer rvalue></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the minimum integer <I>X,</I> such that
|
||||
<A HREF="#FLT_RADIX"><CODE>FLT_RADIX</CODE></A>^(<I>X</I> - 1)
|
||||
is a normalized, finite representable value of type <I>float.</I></P>
|
||||
|
||||
<H2><A NAME="FLT_RADIX"><CODE>FLT_RADIX</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>FLT_RADIX</B> <I><#if expression >= 2></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the radix of all floating-point representations.</P>
|
||||
|
||||
<H2><A NAME="FLT_ROUNDS"><CODE>FLT_ROUNDS</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>FLT_ROUNDS</B> <I><integer rvalue></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields a value that describes the current rounding
|
||||
mode for floating-point operations. Note that the target environment
|
||||
can change the rounding mode while the program executes. How it does
|
||||
so, however, is not specified. The values are:</P>
|
||||
|
||||
<UL>
|
||||
<LI>-1 if the mode is indeterminate
|
||||
|
||||
<LI>0 if rounding is toward zero
|
||||
|
||||
<LI>1 if rounding is to nearest representable value
|
||||
|
||||
<LI>2 if rounding is toward +infinity
|
||||
|
||||
<LI>3 if rounding is toward -infinity
|
||||
</UL>
|
||||
|
||||
<P>An implementation can define additional values for this macro.</P>
|
||||
|
||||
<H2><A NAME="LDBL_DIG"><CODE>LDBL_DIG</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>LDBL_DIG</B> <I><integer rvalue >= 10></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the precision in decimal digits for type <I>long
|
||||
double.</I></P>
|
||||
|
||||
<H2><A NAME="LDBL_EPSILON"><CODE>LDBL_EPSILON</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>LDBL_EPSILON</B> <I><long double rvalue <= 10^(-9)></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the smallest <I>X</I> of type <I>long double</I>
|
||||
such that 1.0 + <I>X</I> != 1.0.</P>
|
||||
|
||||
<H2><A NAME="LDBL_MANT_DIG"><CODE>LDBL_MANT_DIG</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>LDBL_MANT_DIG</B> <I><integer rvalue></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the number of mantissa digits, base
|
||||
<A HREF="#FLT_RADIX"><CODE>FLT_RADIX</CODE></A>,
|
||||
for type <I>long double.</I></P>
|
||||
|
||||
<H2><A NAME="LDBL_MAX"><CODE>LDBL_MAX</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>LDBL_MAX</B> <I><long double rvalue >= 10^37></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the largest finite representable value of type
|
||||
<I>long double.</I></P>
|
||||
|
||||
<H2><A NAME="LDBL_MAX_10_EXP"><CODE>LDBL_MAX_10_EXP</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>LDBL_MAX_10_EXP</B> <I><integer rvalue >= 37></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the maximum integer <I>X,</I> such that
|
||||
10^<I>X</I> is a finite representable value of type <I>long double.</I></P>
|
||||
|
||||
<H2><A NAME="LDBL_MAX_EXP"><CODE>LDBL_MAX_EXP</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>LDBL_MAX_EXP</B> <I><integer rvalue></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the maximum integer <I>X,</I> such that
|
||||
<A HREF="#FLT_RADIX"><CODE>FLT_RADIX</CODE></A>^(<I>X</I> - 1)
|
||||
is a finite representable value of type <I>long double.</I></P>
|
||||
|
||||
<H2><A NAME="LDBL_MIN"><CODE>LDBL_MIN</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>LDBL_MIN</B> <I><long double rvalue <= 10^(-37)></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the smallest normalized, finite representable
|
||||
value of type <I>long double.</I></P>
|
||||
|
||||
<H2><A NAME="LDBL_MIN_10_EXP"><CODE>LDBL_MIN_10_EXP</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>LDBL_MIN_10_EXP</B> <I><integer rvalue <= -37></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the minimum integer <I>X,</I> such that
|
||||
10^<I>X</I> is a normalized, finite representable value
|
||||
of type <I>long double.</I></P>
|
||||
|
||||
<H2><A NAME="LDBL_MIN_EXP"><CODE>LDBL_MIN_EXP</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>LDBL_MIN_EXP</B> <I><integer rvalue></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the minimum integer <I>X,</I> such that
|
||||
<A HREF="#FLT_RADIX"><CODE>FLT_RADIX</CODE></A>^(<I>X</I> - 1)
|
||||
is a normalized, finite representable value of type <I>long double.</I></P>
|
||||
|
||||
<HR>
|
||||
<P>See also the
|
||||
<B><A HREF="index.html#Table of Contents" tppabs="http://ccs.ucsd.edu/c/index.html#Table of Contents">Table of Contents</A></B> and the
|
||||
<B><A HREF="_index.html" tppabs="http://ccs.ucsd.edu/c/_index.html">Index</A></B>.</P>
|
||||
|
||||
<P><I>
|
||||
<A HREF="crit_pb.html" tppabs="http://ccs.ucsd.edu/c/crit_pb.html">Copyright</A> © 1989-1996
|
||||
by P.J. Plauger and Jim Brodie. All rights reserved.</I></P>
|
||||
|
||||
</BODY></HTML>
|
||||
BIN
study/Ref-docs/C/flt_con.gif
Normal file
|
After Width: | Height: | Size: 1.9 KiB |
BIN
study/Ref-docs/C/for_f.gif
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
study/Ref-docs/C/for_s.gif
Normal file
|
After Width: | Height: | Size: 959 B |
BIN
study/Ref-docs/C/format.gif
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
study/Ref-docs/C/fun_def.gif
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
BIN
study/Ref-docs/C/fun_mod.gif
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
1029
study/Ref-docs/C/function.html
Normal file
BIN
study/Ref-docs/C/goto_f.gif
Normal file
|
After Width: | Height: | Size: 439 B |
BIN
study/Ref-docs/C/goto_s.gif
Normal file
|
After Width: | Height: | Size: 563 B |
BIN
study/Ref-docs/C/gotol_f.gif
Normal file
|
After Width: | Height: | Size: 589 B |
BIN
study/Ref-docs/C/gotol_s.gif
Normal file
|
After Width: | Height: | Size: 564 B |
BIN
study/Ref-docs/C/horiz_ws.gif
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
BIN
study/Ref-docs/C/if.gif
Normal file
|
After Width: | Height: | Size: 652 B |
BIN
study/Ref-docs/C/if_f.gif
Normal file
|
After Width: | Height: | Size: 758 B |
BIN
study/Ref-docs/C/if_grp.gif
Normal file
|
After Width: | Height: | Size: 2.4 KiB |
BIN
study/Ref-docs/C/if_s.gif
Normal file
|
After Width: | Height: | Size: 731 B |
BIN
study/Ref-docs/C/ifdef.gif
Normal file
|
After Width: | Height: | Size: 652 B |
BIN
study/Ref-docs/C/ifelse_f.gif
Normal file
|
After Width: | Height: | Size: 930 B |
BIN
study/Ref-docs/C/ifelse_s.gif
Normal file
|
After Width: | Height: | Size: 953 B |
BIN
study/Ref-docs/C/ifndef.gif
Normal file
|
After Width: | Height: | Size: 668 B |
BIN
study/Ref-docs/C/include.gif
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
199
study/Ref-docs/C/index.htm
Normal file
@@ -0,0 +1,199 @@
|
||||
<HTML><HEAD><TITLE>Standard C</TITLE></HEAD><BODY BGCOLOR="#FFFFFF">
|
||||
|
||||
<H1><A NAME="Standard C">Standard C</A></H1><HR>
|
||||
|
||||
<P>This document provides all the information you need to read and
|
||||
write programs in the Standard C programming language. It describes
|
||||
all aspects of Standard C that are the same on all implementations
|
||||
that conform to the standard for C. Whenever your goal is to produce
|
||||
code that is as portable as possible, this document tells you what you
|
||||
can count on. And by omission, it lets you know what you <I>cannot</I>
|
||||
count on -- nothing in this document is peculiar to any nonstandard
|
||||
dialect of C.</P>
|
||||
|
||||
<P>This document is intended as a comprehensive <B>reference</B>
|
||||
for the Standard C programming language, including its support
|
||||
<B><A HREF="lib_over.html" tppabs="http://ccs.ucsd.edu/c/lib_over.html">library</A></B>. In many ways, this
|
||||
material is best described by what it is <I>not</I>.
|
||||
It is not a history
|
||||
of the development of the language, nor is it a rationale for
|
||||
the current state of the language. Equally, this document
|
||||
is not a tutorial on Standard C, nor is it a lesson on
|
||||
how to write computer programs. It does not describe how to use any
|
||||
particular implementation of Standard C. Consult the documentation
|
||||
that comes with the particular
|
||||
<B><A NAME="translator">translator</A></B> (compiler or interpreter)
|
||||
that you are using for specific instructions on translating and executing
|
||||
programs.</P>
|
||||
|
||||
<H2><A NAME="Table of Contents">Table of Contents</A></H2>
|
||||
|
||||
<P><B><CODE><A HREF="intro.html" tppabs="http://ccs.ucsd.edu/c/intro.html">Introduction</A>
|
||||
· <A HREF="charset.html" tppabs="http://ccs.ucsd.edu/c/charset.html">Characters</A>
|
||||
· <A HREF="preproc.html" tppabs="http://ccs.ucsd.edu/c/preproc.html">Preprocessing</A>
|
||||
· <A HREF="syntax.html" tppabs="http://ccs.ucsd.edu/c/syntax.html">Syntax</A>
|
||||
· <A HREF="types.html" tppabs="http://ccs.ucsd.edu/c/types.html">Types</A>
|
||||
· <A HREF="declare.html" tppabs="http://ccs.ucsd.edu/c/declare.html">Declarations</A>
|
||||
· <A HREF="function.html" tppabs="http://ccs.ucsd.edu/c/function.html">Functions</A>
|
||||
· <A HREF="express.html" tppabs="http://ccs.ucsd.edu/c/express.html">Expressions</A>
|
||||
· <A HREF="portable.html" tppabs="http://ccs.ucsd.edu/c/portable.html">Portability</A>
|
||||
</CODE></B></P>
|
||||
|
||||
<P><B><CODE><A HREF="assert.html" tppabs="http://ccs.ucsd.edu/c/assert.html"><assert.h></A>
|
||||
· <A HREF="ctype.html" tppabs="http://ccs.ucsd.edu/c/ctype.html"><ctype.h></A>
|
||||
· <A HREF="errno.html" tppabs="http://ccs.ucsd.edu/c/errno.html"><errno.h></A>
|
||||
· <A HREF="float.html" tppabs="http://ccs.ucsd.edu/c/float.html"><float.h></A>
|
||||
· <A HREF="iso646.html" tppabs="http://ccs.ucsd.edu/c/iso646.html"><iso646.h></A>
|
||||
· <A HREF="limits.html" tppabs="http://ccs.ucsd.edu/c/limits.html"><limits.h></A>
|
||||
· <A HREF="locale.html" tppabs="http://ccs.ucsd.edu/c/locale.html"><locale.h></A>
|
||||
· <A HREF="math.html" tppabs="http://ccs.ucsd.edu/c/math.html"><math.h></A>
|
||||
· <A HREF="setjmp.html" tppabs="http://ccs.ucsd.edu/c/setjmp.html"><setjmp.h></A>
|
||||
· <A HREF="signal.html" tppabs="http://ccs.ucsd.edu/c/signal.html"><signal.h></A>
|
||||
· <A HREF="stdarg.html" tppabs="http://ccs.ucsd.edu/c/stdarg.html"><stdarg.h></A>
|
||||
· <A HREF="stddef.html" tppabs="http://ccs.ucsd.edu/c/stddef.html"><stddef.h></A>
|
||||
· <A HREF="stdio.html" tppabs="http://ccs.ucsd.edu/c/stdio.html"><stdio.h></A>
|
||||
· <A HREF="stdlib.html" tppabs="http://ccs.ucsd.edu/c/stdlib.html"><stdlib.h></A>
|
||||
· <A HREF="string.html" tppabs="http://ccs.ucsd.edu/c/string.html"><string.h></A>
|
||||
· <A HREF="time.html" tppabs="http://ccs.ucsd.edu/c/time.html"><time.h></A>
|
||||
· <A HREF="wchar.html" tppabs="http://ccs.ucsd.edu/c/wchar.html"><wchar.h></A>
|
||||
· <A HREF="wctype.html" tppabs="http://ccs.ucsd.edu/c/wctype.html"><wctype.h></A>
|
||||
</CODE></B></P>
|
||||
|
||||
<P><B><CODE><A HREF="lib_over.html" tppabs="http://ccs.ucsd.edu/c/lib_over.html">C Library Overview</A>
|
||||
· <A HREF="lib_file.html" tppabs="http://ccs.ucsd.edu/c/lib_file.html">Files and Streams</A>
|
||||
· <A HREF="lib_prin.html" tppabs="http://ccs.ucsd.edu/c/lib_prin.html">Formatted Output</A>
|
||||
· <A HREF="lib_scan.html" tppabs="http://ccs.ucsd.edu/c/lib_scan.html">Formatted Input</A>
|
||||
</CODE></B></P>
|
||||
<HR>
|
||||
|
||||
<P>The Standard C language proper is what you write in C
|
||||
<A HREF="charset.html#source file" tppabs="http://ccs.ucsd.edu/c/charset.html#source file">source files</A>. It is
|
||||
best described at several levels of abstraction:</P>
|
||||
|
||||
<P><CODE><B><A HREF="intro.html" tppabs="http://ccs.ucsd.edu/c/intro.html">Introduction</A></B></CODE>
|
||||
-- an overview of this document<BR>
|
||||
<CODE><B><A HREF="charset.html" tppabs="http://ccs.ucsd.edu/c/charset.html">Characters</A></B></CODE>
|
||||
-- how to interpret
|
||||
<A HREF="charset.html#character constant" tppabs="http://ccs.ucsd.edu/c/charset.html#character constant">character constants</A> and
|
||||
<A HREF="charset.html#string literal" tppabs="http://ccs.ucsd.edu/c/charset.html#string literal">string literals</A>, and how to
|
||||
convert between
|
||||
<A HREF="charset.html#Multibyte Characters" tppabs="http://ccs.ucsd.edu/c/charset.html#Multibyte Characters">multibyte characters</A> and
|
||||
<A HREF="charset.html#Wide-Character Encoding" tppabs="http://ccs.ucsd.edu/c/charset.html#Wide-Character Encoding">wide characters</A>
|
||||
<BR>
|
||||
<CODE><B><A HREF="preproc.html" tppabs="http://ccs.ucsd.edu/c/preproc.html">Preprocessing</A></B></CODE>
|
||||
-- how the translator processes directives and
|
||||
<A HREF="preproc.html#Expanding Macros" tppabs="http://ccs.ucsd.edu/c/preproc.html#Expanding Macros">expands macros</A>
|
||||
to produce the
|
||||
<A HREF="syntax.html#C Tokens" tppabs="http://ccs.ucsd.edu/c/syntax.html#C Tokens">C tokens</A> that constitute a
|
||||
<A HREF="preproc.html#translation unit" tppabs="http://ccs.ucsd.edu/c/preproc.html#translation unit">translation unit</A>
|
||||
<BR>
|
||||
<CODE><B><A HREF="syntax.html" tppabs="http://ccs.ucsd.edu/c/syntax.html">Syntax</A></B></CODE>
|
||||
-- how the translator parses C tokens into one or more
|
||||
<A HREF="syntax.html#Declaration Syntax" tppabs="http://ccs.ucsd.edu/c/syntax.html#Declaration Syntax">declarations</A>
|
||||
<BR>
|
||||
<CODE><B><A HREF="types.html" tppabs="http://ccs.ucsd.edu/c/types.html">Types</A></B></CODE>
|
||||
-- how the translator determines the properties of the
|
||||
types you specify within declarations,
|
||||
and how the program represents objects of various types
|
||||
<BR>
|
||||
<CODE><B><A HREF="declare.html" tppabs="http://ccs.ucsd.edu/c/declare.html">Declarations</A></B></CODE>
|
||||
-- how the translator interprets the declarations you write
|
||||
to specify types and objects that the program manipulates
|
||||
<BR>
|
||||
<CODE><B><A HREF="function.html" tppabs="http://ccs.ucsd.edu/c/function.html">Functions</A></B></CODE>
|
||||
-- how the translator interprets the declarations you write
|
||||
to specify the functions that encapsulate all executable
|
||||
code within a C program
|
||||
<BR>
|
||||
<CODE><B><A HREF="express.html" tppabs="http://ccs.ucsd.edu/c/express.html">Expressions</A></B></CODE>
|
||||
-- how the translator interprets expressions to determine
|
||||
what computations to perform, either at translation time
|
||||
or when the program executes
|
||||
<BR>
|
||||
<CODE><B><A HREF="portable.html" tppabs="http://ccs.ucsd.edu/c/portable.html">Portability</A></B></CODE>
|
||||
-- how to write code that is maximally portable across
|
||||
different implementations of Standard C
|
||||
</P>
|
||||
|
||||
<P>A C program can call on a large number of functions from the
|
||||
<B><A NAME="Standard C Library">Standard C library</A></B>.
|
||||
These functions perform essential services
|
||||
such as input and output. They also provide efficient implementations
|
||||
of frequently used operations. Numerous macro and type definitions
|
||||
accompany these functions to help you to make better use of the library.
|
||||
Most of the information about the Standard C library can be
|
||||
found in the descriptions of the
|
||||
<B><A HREF="lib_over.html#standard headers" tppabs="http://ccs.ucsd.edu/c/lib_over.html#standard headers">standard headers</A></B>
|
||||
that declare or define library entities for the program.</P>
|
||||
|
||||
<P>The 18 standard headers are:</P>
|
||||
|
||||
<P><CODE><B><A HREF="assert.html" tppabs="http://ccs.ucsd.edu/c/assert.html"><assert.h></A></B></CODE>
|
||||
-- for enforcing assertions when functions execute<BR>
|
||||
<CODE><B><A HREF="ctype.html" tppabs="http://ccs.ucsd.edu/c/ctype.html"><ctype.h></A></B></CODE>
|
||||
-- for classifying characters<BR>
|
||||
<CODE><B><A HREF="errno.html" tppabs="http://ccs.ucsd.edu/c/errno.html"><errno.h></A></B></CODE>
|
||||
-- for testing error codes reported by library functions<BR>
|
||||
<CODE><B><A HREF="float.html" tppabs="http://ccs.ucsd.edu/c/float.html"><float.h></A></B></CODE>
|
||||
-- for testing floating-point type properties<BR>
|
||||
<CODE><B><A HREF="iso646.html" tppabs="http://ccs.ucsd.edu/c/iso646.html"><iso646.h></A></B></CODE>
|
||||
-- for programming in ISO 646 variant character sets<BR>
|
||||
<CODE><B><A HREF="limits.html" tppabs="http://ccs.ucsd.edu/c/limits.html"><limits.h></A></B></CODE>
|
||||
-- for testing integer type properties<BR>
|
||||
<CODE><B><A HREF="locale.html" tppabs="http://ccs.ucsd.edu/c/locale.html"><locale.h></A></B></CODE>
|
||||
-- for adapting to different cultural conventions<BR>
|
||||
<CODE><B><A HREF="math.html" tppabs="http://ccs.ucsd.edu/c/math.html"><math.h></A></B></CODE>
|
||||
-- for computing common mathematical functions<BR>
|
||||
<CODE><B><A HREF="setjmp.html" tppabs="http://ccs.ucsd.edu/c/setjmp.html"><setjmp.h></A></B></CODE>
|
||||
-- for executing nonlocal <I>goto</I> statements<BR>
|
||||
<CODE><B><A HREF="signal.html" tppabs="http://ccs.ucsd.edu/c/signal.html"><signal.h></A></B></CODE>
|
||||
-- for controlling various exceptional conditions<BR>
|
||||
<CODE><B><A HREF="stdarg.html" tppabs="http://ccs.ucsd.edu/c/stdarg.html"><stdarg.h></A></B></CODE>
|
||||
-- for accessing a varying number of arguments<BR>
|
||||
<CODE><B><A HREF="stddef.html" tppabs="http://ccs.ucsd.edu/c/stddef.html"><stddef.h></A></B></CODE>
|
||||
-- for defining several useful types and macros<BR>
|
||||
<CODE><B><A HREF="stdio.html" tppabs="http://ccs.ucsd.edu/c/stdio.html"><stdio.h></A></B></CODE>
|
||||
-- for performing input and output<BR>
|
||||
<CODE><B><A HREF="stdlib.html" tppabs="http://ccs.ucsd.edu/c/stdlib.html"><stdlib.h></A></B></CODE>
|
||||
-- for performing a variety of operations<BR>
|
||||
<CODE><B><A HREF="string.html" tppabs="http://ccs.ucsd.edu/c/string.html"><string.h></A></B></CODE>
|
||||
-- for manipulating several kinds of strings<BR>
|
||||
<CODE><B><A HREF="time.html" tppabs="http://ccs.ucsd.edu/c/time.html"><time.h></A></B></CODE>
|
||||
-- for converting between various time and date formats<BR>
|
||||
<CODE><B><A HREF="wchar.html" tppabs="http://ccs.ucsd.edu/c/wchar.html"><wchar.h></A></B></CODE>
|
||||
-- for manipulating
|
||||
<A HREF="lib_file.html#wide stream" tppabs="http://ccs.ucsd.edu/c/lib_file.html#wide stream">wide streams</A> and
|
||||
several kinds of strings<BR>
|
||||
<CODE><B><A HREF="wctype.html" tppabs="http://ccs.ucsd.edu/c/wctype.html"><wctype.h></A></B></CODE>
|
||||
-- for classifying
|
||||
<A HREF="charset.html#Wide-Character Encoding" tppabs="http://ccs.ucsd.edu/c/charset.html#Wide-Character Encoding">wide characters</A></P>
|
||||
|
||||
<P>Other information on the Standard C library includes:</P>
|
||||
|
||||
<P><B><A HREF="lib_over.html" tppabs="http://ccs.ucsd.edu/c/lib_over.html">C Library Overview</A></B> --
|
||||
how to use the library, including what happens at
|
||||
<A HREF="lib_over.html#program startup" tppabs="http://ccs.ucsd.edu/c/lib_over.html#program startup">program startup</A> and at
|
||||
<A HREF="lib_over.html#program termination" tppabs="http://ccs.ucsd.edu/c/lib_over.html#program termination">program termination</A>
|
||||
<BR>
|
||||
<B><A HREF="lib_file.html" tppabs="http://ccs.ucsd.edu/c/lib_file.html">Files and Streams</A></B> --
|
||||
how to read and write data between the program and
|
||||
<A HREF="lib_file.html#files" tppabs="http://ccs.ucsd.edu/c/lib_file.html#files">files</A>
|
||||
<BR>
|
||||
<B><A HREF="lib_prin.html" tppabs="http://ccs.ucsd.edu/c/lib_prin.html">Formatted Output</A></B> --
|
||||
how to generate text under control of a
|
||||
<A HREF="lib_prin.html#format string" tppabs="http://ccs.ucsd.edu/c/lib_prin.html#format string">format string</A>
|
||||
<BR>
|
||||
<B><A HREF="lib_scan.html" tppabs="http://ccs.ucsd.edu/c/lib_scan.html">Formatted Input</A></B> --
|
||||
how to scan and parse text under control of a
|
||||
<A HREF="lib_prin.html#format string" tppabs="http://ccs.ucsd.edu/c/lib_prin.html#format string">format string</A>
|
||||
</P>
|
||||
|
||||
<HR>
|
||||
<P>See also the
|
||||
<B><A HREF="_index.html" tppabs="http://ccs.ucsd.edu/c/_index.html">Index</A></B>.</P>
|
||||
|
||||
<P><I>
|
||||
<A HREF="crit_pb.html" tppabs="http://ccs.ucsd.edu/c/crit_pb.html">Copyright</A> © 1989-1996
|
||||
by P.J. Plauger and Jim Brodie. All rights reserved.</I></P>
|
||||
|
||||
</BODY></HTML>
|
||||
199
study/Ref-docs/C/index.html
Normal file
@@ -0,0 +1,199 @@
|
||||
<HTML><HEAD><TITLE>Standard C</TITLE></HEAD><BODY BGCOLOR="#FFFFFF">
|
||||
|
||||
<H1><A NAME="Standard C">Standard C</A></H1><HR>
|
||||
|
||||
<P>This document provides all the information you need to read and
|
||||
write programs in the Standard C programming language. It describes
|
||||
all aspects of Standard C that are the same on all implementations
|
||||
that conform to the standard for C. Whenever your goal is to produce
|
||||
code that is as portable as possible, this document tells you what you
|
||||
can count on. And by omission, it lets you know what you <I>cannot</I>
|
||||
count on -- nothing in this document is peculiar to any nonstandard
|
||||
dialect of C.</P>
|
||||
|
||||
<P>This document is intended as a comprehensive <B>reference</B>
|
||||
for the Standard C programming language, including its support
|
||||
<B><A HREF="lib_over.html" tppabs="http://ccs.ucsd.edu/c/lib_over.html">library</A></B>. In many ways, this
|
||||
material is best described by what it is <I>not</I>.
|
||||
It is not a history
|
||||
of the development of the language, nor is it a rationale for
|
||||
the current state of the language. Equally, this document
|
||||
is not a tutorial on Standard C, nor is it a lesson on
|
||||
how to write computer programs. It does not describe how to use any
|
||||
particular implementation of Standard C. Consult the documentation
|
||||
that comes with the particular
|
||||
<B><A NAME="translator">translator</A></B> (compiler or interpreter)
|
||||
that you are using for specific instructions on translating and executing
|
||||
programs.</P>
|
||||
|
||||
<H2><A NAME="Table of Contents">Table of Contents</A></H2>
|
||||
|
||||
<P><B><CODE><A HREF="intro.html" tppabs="http://ccs.ucsd.edu/c/intro.html">Introduction</A>
|
||||
· <A HREF="charset.html" tppabs="http://ccs.ucsd.edu/c/charset.html">Characters</A>
|
||||
· <A HREF="preproc.html" tppabs="http://ccs.ucsd.edu/c/preproc.html">Preprocessing</A>
|
||||
· <A HREF="syntax.html" tppabs="http://ccs.ucsd.edu/c/syntax.html">Syntax</A>
|
||||
· <A HREF="types.html" tppabs="http://ccs.ucsd.edu/c/types.html">Types</A>
|
||||
· <A HREF="declare.html" tppabs="http://ccs.ucsd.edu/c/declare.html">Declarations</A>
|
||||
· <A HREF="function.html" tppabs="http://ccs.ucsd.edu/c/function.html">Functions</A>
|
||||
· <A HREF="express.html" tppabs="http://ccs.ucsd.edu/c/express.html">Expressions</A>
|
||||
· <A HREF="portable.html" tppabs="http://ccs.ucsd.edu/c/portable.html">Portability</A>
|
||||
</CODE></B></P>
|
||||
|
||||
<P><B><CODE><A HREF="assert.html" tppabs="http://ccs.ucsd.edu/c/assert.html"><assert.h></A>
|
||||
· <A HREF="ctype.html" tppabs="http://ccs.ucsd.edu/c/ctype.html"><ctype.h></A>
|
||||
· <A HREF="errno.html" tppabs="http://ccs.ucsd.edu/c/errno.html"><errno.h></A>
|
||||
· <A HREF="float.html" tppabs="http://ccs.ucsd.edu/c/float.html"><float.h></A>
|
||||
· <A HREF="iso646.html" tppabs="http://ccs.ucsd.edu/c/iso646.html"><iso646.h></A>
|
||||
· <A HREF="limits.html" tppabs="http://ccs.ucsd.edu/c/limits.html"><limits.h></A>
|
||||
· <A HREF="locale.html" tppabs="http://ccs.ucsd.edu/c/locale.html"><locale.h></A>
|
||||
· <A HREF="math.html" tppabs="http://ccs.ucsd.edu/c/math.html"><math.h></A>
|
||||
· <A HREF="setjmp.html" tppabs="http://ccs.ucsd.edu/c/setjmp.html"><setjmp.h></A>
|
||||
· <A HREF="signal.html" tppabs="http://ccs.ucsd.edu/c/signal.html"><signal.h></A>
|
||||
· <A HREF="stdarg.html" tppabs="http://ccs.ucsd.edu/c/stdarg.html"><stdarg.h></A>
|
||||
· <A HREF="stddef.html" tppabs="http://ccs.ucsd.edu/c/stddef.html"><stddef.h></A>
|
||||
· <A HREF="stdio.html" tppabs="http://ccs.ucsd.edu/c/stdio.html"><stdio.h></A>
|
||||
· <A HREF="stdlib.html" tppabs="http://ccs.ucsd.edu/c/stdlib.html"><stdlib.h></A>
|
||||
· <A HREF="string.html" tppabs="http://ccs.ucsd.edu/c/string.html"><string.h></A>
|
||||
· <A HREF="time.html" tppabs="http://ccs.ucsd.edu/c/time.html"><time.h></A>
|
||||
· <A HREF="wchar.html" tppabs="http://ccs.ucsd.edu/c/wchar.html"><wchar.h></A>
|
||||
· <A HREF="wctype.html" tppabs="http://ccs.ucsd.edu/c/wctype.html"><wctype.h></A>
|
||||
</CODE></B></P>
|
||||
|
||||
<P><B><CODE><A HREF="lib_over.html" tppabs="http://ccs.ucsd.edu/c/lib_over.html">C Library Overview</A>
|
||||
· <A HREF="lib_file.html" tppabs="http://ccs.ucsd.edu/c/lib_file.html">Files and Streams</A>
|
||||
· <A HREF="lib_prin.html" tppabs="http://ccs.ucsd.edu/c/lib_prin.html">Formatted Output</A>
|
||||
· <A HREF="lib_scan.html" tppabs="http://ccs.ucsd.edu/c/lib_scan.html">Formatted Input</A>
|
||||
</CODE></B></P>
|
||||
<HR>
|
||||
|
||||
<P>The Standard C language proper is what you write in C
|
||||
<A HREF="charset.html#source file" tppabs="http://ccs.ucsd.edu/c/charset.html#source file">source files</A>. It is
|
||||
best described at several levels of abstraction:</P>
|
||||
|
||||
<P><CODE><B><A HREF="intro.html" tppabs="http://ccs.ucsd.edu/c/intro.html">Introduction</A></B></CODE>
|
||||
-- an overview of this document<BR>
|
||||
<CODE><B><A HREF="charset.html" tppabs="http://ccs.ucsd.edu/c/charset.html">Characters</A></B></CODE>
|
||||
-- how to interpret
|
||||
<A HREF="charset.html#character constant" tppabs="http://ccs.ucsd.edu/c/charset.html#character constant">character constants</A> and
|
||||
<A HREF="charset.html#string literal" tppabs="http://ccs.ucsd.edu/c/charset.html#string literal">string literals</A>, and how to
|
||||
convert between
|
||||
<A HREF="charset.html#Multibyte Characters" tppabs="http://ccs.ucsd.edu/c/charset.html#Multibyte Characters">multibyte characters</A> and
|
||||
<A HREF="charset.html#Wide-Character Encoding" tppabs="http://ccs.ucsd.edu/c/charset.html#Wide-Character Encoding">wide characters</A>
|
||||
<BR>
|
||||
<CODE><B><A HREF="preproc.html" tppabs="http://ccs.ucsd.edu/c/preproc.html">Preprocessing</A></B></CODE>
|
||||
-- how the translator processes directives and
|
||||
<A HREF="preproc.html#Expanding Macros" tppabs="http://ccs.ucsd.edu/c/preproc.html#Expanding Macros">expands macros</A>
|
||||
to produce the
|
||||
<A HREF="syntax.html#C Tokens" tppabs="http://ccs.ucsd.edu/c/syntax.html#C Tokens">C tokens</A> that constitute a
|
||||
<A HREF="preproc.html#translation unit" tppabs="http://ccs.ucsd.edu/c/preproc.html#translation unit">translation unit</A>
|
||||
<BR>
|
||||
<CODE><B><A HREF="syntax.html" tppabs="http://ccs.ucsd.edu/c/syntax.html">Syntax</A></B></CODE>
|
||||
-- how the translator parses C tokens into one or more
|
||||
<A HREF="syntax.html#Declaration Syntax" tppabs="http://ccs.ucsd.edu/c/syntax.html#Declaration Syntax">declarations</A>
|
||||
<BR>
|
||||
<CODE><B><A HREF="types.html" tppabs="http://ccs.ucsd.edu/c/types.html">Types</A></B></CODE>
|
||||
-- how the translator determines the properties of the
|
||||
types you specify within declarations,
|
||||
and how the program represents objects of various types
|
||||
<BR>
|
||||
<CODE><B><A HREF="declare.html" tppabs="http://ccs.ucsd.edu/c/declare.html">Declarations</A></B></CODE>
|
||||
-- how the translator interprets the declarations you write
|
||||
to specify types and objects that the program manipulates
|
||||
<BR>
|
||||
<CODE><B><A HREF="function.html" tppabs="http://ccs.ucsd.edu/c/function.html">Functions</A></B></CODE>
|
||||
-- how the translator interprets the declarations you write
|
||||
to specify the functions that encapsulate all executable
|
||||
code within a C program
|
||||
<BR>
|
||||
<CODE><B><A HREF="express.html" tppabs="http://ccs.ucsd.edu/c/express.html">Expressions</A></B></CODE>
|
||||
-- how the translator interprets expressions to determine
|
||||
what computations to perform, either at translation time
|
||||
or when the program executes
|
||||
<BR>
|
||||
<CODE><B><A HREF="portable.html" tppabs="http://ccs.ucsd.edu/c/portable.html">Portability</A></B></CODE>
|
||||
-- how to write code that is maximally portable across
|
||||
different implementations of Standard C
|
||||
</P>
|
||||
|
||||
<P>A C program can call on a large number of functions from the
|
||||
<B><A NAME="Standard C Library">Standard C library</A></B>.
|
||||
These functions perform essential services
|
||||
such as input and output. They also provide efficient implementations
|
||||
of frequently used operations. Numerous macro and type definitions
|
||||
accompany these functions to help you to make better use of the library.
|
||||
Most of the information about the Standard C library can be
|
||||
found in the descriptions of the
|
||||
<B><A HREF="lib_over.html#standard headers" tppabs="http://ccs.ucsd.edu/c/lib_over.html#standard headers">standard headers</A></B>
|
||||
that declare or define library entities for the program.</P>
|
||||
|
||||
<P>The 18 standard headers are:</P>
|
||||
|
||||
<P><CODE><B><A HREF="assert.html" tppabs="http://ccs.ucsd.edu/c/assert.html"><assert.h></A></B></CODE>
|
||||
-- for enforcing assertions when functions execute<BR>
|
||||
<CODE><B><A HREF="ctype.html" tppabs="http://ccs.ucsd.edu/c/ctype.html"><ctype.h></A></B></CODE>
|
||||
-- for classifying characters<BR>
|
||||
<CODE><B><A HREF="errno.html" tppabs="http://ccs.ucsd.edu/c/errno.html"><errno.h></A></B></CODE>
|
||||
-- for testing error codes reported by library functions<BR>
|
||||
<CODE><B><A HREF="float.html" tppabs="http://ccs.ucsd.edu/c/float.html"><float.h></A></B></CODE>
|
||||
-- for testing floating-point type properties<BR>
|
||||
<CODE><B><A HREF="iso646.html" tppabs="http://ccs.ucsd.edu/c/iso646.html"><iso646.h></A></B></CODE>
|
||||
-- for programming in ISO 646 variant character sets<BR>
|
||||
<CODE><B><A HREF="limits.html" tppabs="http://ccs.ucsd.edu/c/limits.html"><limits.h></A></B></CODE>
|
||||
-- for testing integer type properties<BR>
|
||||
<CODE><B><A HREF="locale.html" tppabs="http://ccs.ucsd.edu/c/locale.html"><locale.h></A></B></CODE>
|
||||
-- for adapting to different cultural conventions<BR>
|
||||
<CODE><B><A HREF="math.html" tppabs="http://ccs.ucsd.edu/c/math.html"><math.h></A></B></CODE>
|
||||
-- for computing common mathematical functions<BR>
|
||||
<CODE><B><A HREF="setjmp.html" tppabs="http://ccs.ucsd.edu/c/setjmp.html"><setjmp.h></A></B></CODE>
|
||||
-- for executing nonlocal <I>goto</I> statements<BR>
|
||||
<CODE><B><A HREF="signal.html" tppabs="http://ccs.ucsd.edu/c/signal.html"><signal.h></A></B></CODE>
|
||||
-- for controlling various exceptional conditions<BR>
|
||||
<CODE><B><A HREF="stdarg.html" tppabs="http://ccs.ucsd.edu/c/stdarg.html"><stdarg.h></A></B></CODE>
|
||||
-- for accessing a varying number of arguments<BR>
|
||||
<CODE><B><A HREF="stddef.html" tppabs="http://ccs.ucsd.edu/c/stddef.html"><stddef.h></A></B></CODE>
|
||||
-- for defining several useful types and macros<BR>
|
||||
<CODE><B><A HREF="stdio.html" tppabs="http://ccs.ucsd.edu/c/stdio.html"><stdio.h></A></B></CODE>
|
||||
-- for performing input and output<BR>
|
||||
<CODE><B><A HREF="stdlib.html" tppabs="http://ccs.ucsd.edu/c/stdlib.html"><stdlib.h></A></B></CODE>
|
||||
-- for performing a variety of operations<BR>
|
||||
<CODE><B><A HREF="string.html" tppabs="http://ccs.ucsd.edu/c/string.html"><string.h></A></B></CODE>
|
||||
-- for manipulating several kinds of strings<BR>
|
||||
<CODE><B><A HREF="time.html" tppabs="http://ccs.ucsd.edu/c/time.html"><time.h></A></B></CODE>
|
||||
-- for converting between various time and date formats<BR>
|
||||
<CODE><B><A HREF="wchar.html" tppabs="http://ccs.ucsd.edu/c/wchar.html"><wchar.h></A></B></CODE>
|
||||
-- for manipulating
|
||||
<A HREF="lib_file.html#wide stream" tppabs="http://ccs.ucsd.edu/c/lib_file.html#wide stream">wide streams</A> and
|
||||
several kinds of strings<BR>
|
||||
<CODE><B><A HREF="wctype.html" tppabs="http://ccs.ucsd.edu/c/wctype.html"><wctype.h></A></B></CODE>
|
||||
-- for classifying
|
||||
<A HREF="charset.html#Wide-Character Encoding" tppabs="http://ccs.ucsd.edu/c/charset.html#Wide-Character Encoding">wide characters</A></P>
|
||||
|
||||
<P>Other information on the Standard C library includes:</P>
|
||||
|
||||
<P><B><A HREF="lib_over.html" tppabs="http://ccs.ucsd.edu/c/lib_over.html">C Library Overview</A></B> --
|
||||
how to use the library, including what happens at
|
||||
<A HREF="lib_over.html#program startup" tppabs="http://ccs.ucsd.edu/c/lib_over.html#program startup">program startup</A> and at
|
||||
<A HREF="lib_over.html#program termination" tppabs="http://ccs.ucsd.edu/c/lib_over.html#program termination">program termination</A>
|
||||
<BR>
|
||||
<B><A HREF="lib_file.html" tppabs="http://ccs.ucsd.edu/c/lib_file.html">Files and Streams</A></B> --
|
||||
how to read and write data between the program and
|
||||
<A HREF="lib_file.html#files" tppabs="http://ccs.ucsd.edu/c/lib_file.html#files">files</A>
|
||||
<BR>
|
||||
<B><A HREF="lib_prin.html" tppabs="http://ccs.ucsd.edu/c/lib_prin.html">Formatted Output</A></B> --
|
||||
how to generate text under control of a
|
||||
<A HREF="lib_prin.html#format string" tppabs="http://ccs.ucsd.edu/c/lib_prin.html#format string">format string</A>
|
||||
<BR>
|
||||
<B><A HREF="lib_scan.html" tppabs="http://ccs.ucsd.edu/c/lib_scan.html">Formatted Input</A></B> --
|
||||
how to scan and parse text under control of a
|
||||
<A HREF="lib_prin.html#format string" tppabs="http://ccs.ucsd.edu/c/lib_prin.html#format string">format string</A>
|
||||
</P>
|
||||
|
||||
<HR>
|
||||
<P>See also the
|
||||
<B><A HREF="_index.html" tppabs="http://ccs.ucsd.edu/c/_index.html">Index</A></B>.</P>
|
||||
|
||||
<P><I>
|
||||
<A HREF="crit_pb.html" tppabs="http://ccs.ucsd.edu/c/crit_pb.html">Copyright</A> © 1989-1996
|
||||
by P.J. Plauger and Jim Brodie. All rights reserved.</I></P>
|
||||
|
||||
</BODY></HTML>
|
||||
BIN
study/Ref-docs/C/infix.gif
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
study/Ref-docs/C/int_con.gif
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
199
study/Ref-docs/C/intro.html
Normal file
@@ -0,0 +1,199 @@
|
||||
<HTML><HEAD><TITLE>Introduction</TITLE></HEAD><BODY BGCOLOR="#FFFFFF">
|
||||
|
||||
<H1><A NAME="Introduction">Introduction</A></H1><HR>
|
||||
|
||||
<P><B>
|
||||
<A HREF="#C Standard">C Standard</A>
|
||||
· <A HREF="#Amendments">Amendments</A>
|
||||
· <A HREF="#Railroad-Track Diagrams">Railroad-Track Diagrams</A>
|
||||
· <A HREF="#Notation">Notation</A>
|
||||
</B></P>
|
||||
<HR>
|
||||
|
||||
<P>``Standard C'' is a term with a fairly precise definition.
|
||||
This document supplies that definition. It also describes the
|
||||
notation used throughout this description of Standard C.</P>
|
||||
|
||||
<H2><A NAME="C Standard">C Standard</A></H2>
|
||||
|
||||
<P>The Standard C programming language described in this document corresponds
|
||||
to the American National Standards Institute (ANSI) standard for the
|
||||
C language -- ANSI X3.159-1989. An identical standard was approved
|
||||
by the International Organization for Standardization (ISO) --
|
||||
ISO/IEC 9899:1990. This common standard was developed through the
|
||||
joint efforts of the ANSI-authorized C Programming Language Committee
|
||||
X3J11 and the ISO authorized Committee JTC1 SC22 WG14.</P>
|
||||
|
||||
<P>Standard C is designed to ``codify existing practice.''
|
||||
Most of the C code written before the advent of Standard C is still
|
||||
acceptable to one or more Standard C translators. Nevertheless, Standard
|
||||
C is a new language:</P>
|
||||
|
||||
<UL>
|
||||
<LI>It adds features, such as function prototypes, to correct some
|
||||
known deficiencies in the C language.</LI>
|
||||
|
||||
<LI>It resolves conflicting practices, such as ones found among
|
||||
the differing rules for redeclaring objects.</LI>
|
||||
|
||||
<LI>It clarifies ambiguities, such as whether the objects manipulated
|
||||
by library functions are permitted to overlap.</LI>
|
||||
</UL>
|
||||
|
||||
<P>This document presents Standard C as a distinct language, not as
|
||||
a historical outgrowth of any particular earlier dialect of C. If
|
||||
you are new to C or are familiar with just a specific dialect, you
|
||||
have a new language to learn.</P>
|
||||
|
||||
<H2><A NAME="Amendments">Amendments</A></H2>
|
||||
|
||||
<P>The C Standard has more recently been amended and clarified.
|
||||
<B><A HREF="lib_over.html#Amendment 1" tppabs="http://ccs.ucsd.edu/c/lib_over.html#Amendment 1">Amendment 1</A></B>
|
||||
(approved in 1994) adds extensive support for manipulating
|
||||
<A HREF="charset.html#Wide-Character Encoding" tppabs="http://ccs.ucsd.edu/c/charset.html#Wide-Character Encoding">wide characters</A>,
|
||||
which represent large character sets, and
|
||||
some additional support for writing source code in national variants of the
|
||||
ISO 646 character set.
|
||||
Most of these new features are additions to the
|
||||
<A HREF="lib_over.html" tppabs="http://ccs.ucsd.edu/c/lib_over.html">library</A>,
|
||||
and most library additions are defined or declared
|
||||
in three new headers --
|
||||
<CODE><A HREF="iso646.html#<iso646.h>" tppabs="http://ccs.ucsd.edu/c/iso646.html#<iso646.h>"><iso646.h></A></CODE>,
|
||||
<CODE><A HREF="wchar.html#<wchar.h>" tppabs="http://ccs.ucsd.edu/c/wchar.html#<wchar.h>"><wchar.h></A></CODE>, and
|
||||
<CODE><A HREF="wctype.html#<wctype.h>" tppabs="http://ccs.ucsd.edu/c/wctype.html#<wctype.h>"><wctype.h></A></CODE>.
|
||||
Many Standard C translators have yet to add these new features,
|
||||
so this document labels such additions as new with Amendment 1.
|
||||
For maximum near-term portability, you may wish to avoid them.</P>
|
||||
|
||||
<P><B><A NAME="Technical Corrigendum 1">Technical Corrigendum 1</A></B>
|
||||
(also approved in 1994) supplies a number
|
||||
of clarifications and corrections to the C Standard. These are in
|
||||
response to ANSI Requests for Interpretation or ISO Defect Reports
|
||||
received and processed by X3J11 and WG14 since the C Standard was
|
||||
first issued. None are intended to alter the original definition of
|
||||
Standard C, merely to make its definition more unambiguous and precise.
|
||||
This document reflects the effect of Technical Corrigendum 1, but does
|
||||
not identify any specific changes.</P>
|
||||
|
||||
<H2><A NAME="Railroad-Track Diagrams">Railroad-Track Diagrams</A></H2>
|
||||
|
||||
<P>Syntax rules appear in the form of <B>railroad-track diagrams</B>.
|
||||
The diagrams summarize all valid ways that you can form explicit computer
|
||||
text for a given form. Not all forms that you can generate from a
|
||||
railroad-track diagram are necessarily valid. Often semantic restrictions
|
||||
also apply. These are described in separate tables or in running text.</P>
|
||||
|
||||
<P>A railroad-track diagram contains boxes that indicate the components
|
||||
you use to create a form. Arrows connect the boxes to indicate the
|
||||
ways that you can combine the components. You can create different
|
||||
text for a form by taking different paths between the boxes. The name
|
||||
of the form appears next to the arrow leading out to the right from
|
||||
the diagram.</P>
|
||||
|
||||
<P>Here, for example, is the syntax rule for writing a
|
||||
<CODE><I>name</I></CODE> in Standard C:</P>
|
||||
|
||||
<P><IMG SRC="name.gif" tppabs="http://ccs.ucsd.edu/c/gif/name.gif"></P>
|
||||
|
||||
<P>You generate a valid <CODE><I>name</I></CODE> by following the arrows.
|
||||
Begin with the arrow leading in from the left and continue until you
|
||||
follow the arrow leading out to the right. In a complex diagram, an
|
||||
arrow followed by an ellipsis (<CODE>...</CODE>)
|
||||
connects to the arrow preceded
|
||||
by an ellipsis immediately below.</P>
|
||||
|
||||
<P>Each time you come to a box, you must add the text in the box
|
||||
to the item being created. If the box contains a form, you must add
|
||||
text that matches the form. If the box contains more than one entry,
|
||||
you must add one of the choices. If you come to an intersection with
|
||||
two arrows leading away from it, you can follow either arrow. You
|
||||
cannot follow an arrow in the direction opposite to the way it points.</P>
|
||||
|
||||
<P>The railroad-track diagram above tells you:</P>
|
||||
|
||||
<UL>
|
||||
<LI>Every name in Standard C begins with either an uppercase or
|
||||
lowercase <CODE><I>letter</I></CODE>
|
||||
(such as <CODE>A</CODE> or <CODE>x</CODE>)
|
||||
or an <CODE><I>underscore</I></CODE> (<CODE>_</CODE>).</LI>
|
||||
|
||||
<LI>A name need not contain more than one character.</LI>
|
||||
|
||||
<LI>The initial character might be followed by a <CODE><I>digit</I></CODE>
|
||||
(such as <CODE>3</CODE>), a <CODE><I>letter</I></CODE>,
|
||||
or an <CODE><I>underscore</I></CODE>.</LI>
|
||||
|
||||
<LI>The initial character might be followed by an indefinite number
|
||||
of these characters.</LI>
|
||||
</UL>
|
||||
|
||||
<P>A name can therefore be any of the following:</P>
|
||||
|
||||
<PRE>A A3 _x
|
||||
timer box_2 z173ab
|
||||
an_extremely_long_name_that_also_contains_1_digit</PRE>
|
||||
|
||||
<P>The syntax rule does <I>not</I> tell you about the following
|
||||
semantic limitations:</P>
|
||||
|
||||
<UL>
|
||||
<LI>Some implementations can limit the length of the name. (The
|
||||
limit cannot be less than
|
||||
<A HREF="portable.html#Translation-Time Issues" tppabs="http://ccs.ucsd.edu/c/portable.html#Translation-Time Issues">509 characters</A>.)</LI>
|
||||
|
||||
<LI>An implementation might use only the first
|
||||
<A HREF="preproc.html#distinct names" tppabs="http://ccs.ucsd.edu/c/preproc.html#distinct names">31 characters</A> when
|
||||
comparing names.</LI>
|
||||
|
||||
<LI>An implementation might use only the first
|
||||
<A HREF="syntax.html#name" tppabs="http://ccs.ucsd.edu/c/syntax.html#name">six characters</A> and
|
||||
ignore the difference in case between <CODE>a</CODE> and <CODE>A</CODE>
|
||||
when comparing names with
|
||||
<A HREF="declare.html#external linkage" tppabs="http://ccs.ucsd.edu/c/declare.html#external linkage">external linkage</A> from
|
||||
separate translation units.</LI>
|
||||
|
||||
<LI>Names beginning with an <CODE><I>underscore</I></CODE> are generally
|
||||
<A HREF="lib_over.html#reserved names" tppabs="http://ccs.ucsd.edu/c/lib_over.html#reserved names">reserved</A>
|
||||
for use by an implementation.</LI>
|
||||
</UL>
|
||||
|
||||
<P>Some diagrams require boxes that permit anything <I>except</I>
|
||||
one or a few items. In these cases, <CODE><B>bold text</B></CODE>
|
||||
describes the matching rule. For example, <CODE><B>not</B> NL</CODE>
|
||||
matches any character except a newline character.</P>
|
||||
|
||||
<H2><A NAME="Notation">Notation</A></H2>
|
||||
|
||||
<P>A type face that differs from the running text has a special
|
||||
meaning:</P>
|
||||
|
||||
<UL>
|
||||
<LI><B>definition</B> -- a term that has a special definition
|
||||
in Standard C.</LI>
|
||||
|
||||
<LI><CODE>computer text</CODE> -- any item that can appear explicitly
|
||||
in a text file, such as C source text, input to a program, or output
|
||||
from a program.</LI>
|
||||
|
||||
<LI><CODE><B>comments</B></CODE> -- remarks that are not an actual part of
|
||||
the computer text being presented.</LI>
|
||||
|
||||
<LI><CODE><I>form</I></CODE> -- a name that stands for one or more explicit
|
||||
computer text patterns. For example, the following defines
|
||||
<CODE><I>digit</I></CODE> as a form that you can replace with any of the
|
||||
explicit characters <CODE>0</CODE>, <CODE>1</CODE>, <CODE>2</CODE>,
|
||||
and so on:</LI>
|
||||
</UL>
|
||||
|
||||
<PRE><I>digit</I> 0 1 2 3 4 5 6 7 8 9</PRE>
|
||||
|
||||
<HR>
|
||||
<P>See also the
|
||||
<B><A HREF="index.html#Table of Contents" tppabs="http://ccs.ucsd.edu/c/index.html#Table of Contents">Table of Contents</A></B> and the
|
||||
<B><A HREF="_index.html" tppabs="http://ccs.ucsd.edu/c/_index.html">Index</A></B>.</P>
|
||||
|
||||
<P><I>
|
||||
<A HREF="crit_pb.html" tppabs="http://ccs.ucsd.edu/c/crit_pb.html">Copyright</A> © 1989-1996
|
||||
by P.J. Plauger and Jim Brodie. All rights reserved.</I></P>
|
||||
|
||||
</BODY></HTML>
|
||||
135
study/Ref-docs/C/iso646.html
Normal file
@@ -0,0 +1,135 @@
|
||||
<HTML><HEAD><TITLE><iso646.h></TITLE></HEAD><BODY BGCOLOR="#FFFFFF">
|
||||
|
||||
<H1><A NAME="<iso646.h>"><CODE><iso646.h></CODE></A>
|
||||
[Added with
|
||||
<A HREF="lib_over.html#Amendment 1" tppabs="http://ccs.ucsd.edu/c/lib_over.html#Amendment 1">Amendment 1</A>]</H1><HR>
|
||||
|
||||
<P><CODE>
|
||||
#define <A HREF="#and"><B>and</B></A>
|
||||
&& <B>[keyword in C++]</B><BR>
|
||||
#define <A HREF="#and_eq"><B>and_eq</B></A>
|
||||
&= <B>[keyword in C++]</B><BR>
|
||||
#define <A HREF="#bitand"><B>bitand</B></A>
|
||||
& <B>[keyword in C++]</B><BR>
|
||||
#define <A HREF="#bitor"><B>bitor</B></A>
|
||||
| <B>[keyword in C++]</B><BR>
|
||||
#define <A HREF="#compl"><B>compl</B></A>
|
||||
~ <B>[keyword in C++]</B><BR>
|
||||
#define <A HREF="#not"><B>not</B></A>
|
||||
! <B>[keyword in C++]</B><BR>
|
||||
#define <A HREF="#not_eq"><B>not_eq</B></A>
|
||||
!= <B>[keyword in C++]</B><BR>
|
||||
#define <A HREF="#or"><B>or</B></A>
|
||||
|| <B>[keyword in C++]</B><BR>
|
||||
#define <A HREF="#or_eq"><B>or_eq</B></A>
|
||||
|= <B>[keyword in C++]</B><BR>
|
||||
#define <A HREF="#xor"><B>xor</B></A>
|
||||
^ <B>[keyword in C++]</B><BR>
|
||||
#define <A HREF="#xor_eq"><B>xor_eq</B></A>
|
||||
^= <B>[keyword in C++]</B>
|
||||
</CODE></P>
|
||||
|
||||
<P>Include the standard header <B><CODE><iso646.h></CODE></B>
|
||||
to provide readable alternatives to certain operators or punctuators.
|
||||
The standard header <CODE><iso646.h></CODE> is available even in a
|
||||
<A HREF="lib_over.html#freestanding implementation" tppabs="http://ccs.ucsd.edu/c/lib_over.html#freestanding implementation">
|
||||
freestanding implementation</A>.</P>
|
||||
|
||||
<H2><A NAME="and"><CODE>and</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>and</B> && <B>[keyword in C++]</B>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the operator <CODE>&&</CODE>.</P>
|
||||
|
||||
<H2><A NAME="and_eq"><CODE>and_eq</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>and_eq</B> &= <B>[keyword in C++]</B>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the operator <CODE>&=</CODE>.</P>
|
||||
|
||||
<H2><A NAME="bitand"><CODE>bitand</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>bitand</B> & <B>[keyword in C++]</B>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the operator <CODE>&</CODE>.</P>
|
||||
|
||||
<H2><A NAME="bitor"><CODE>bitor</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>bitor</B> | <B>[keyword in C++]</B>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the operator <CODE>|</CODE>.</P>
|
||||
|
||||
<H2><A NAME="compl"><CODE>compl</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>compl</B> ~ <B>[keyword in C++]</B>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the operator <CODE>~</CODE>.</P>
|
||||
|
||||
<H2><A NAME="not"><CODE>not</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>not</B> ! <B>[keyword in C++]</B>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the operator <CODE>!</CODE>.</P>
|
||||
|
||||
<H2><A NAME="not_eq"><CODE>not_eq</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>not_eq</B> != <B>[keyword in C++]</B>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the operator <CODE>!=</CODE>.</P>
|
||||
|
||||
<H2><A NAME="or"><CODE>or</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>or</B> || <B>[keyword in C++]</B>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the operator <CODE>||</CODE>.</P>
|
||||
|
||||
<H2><A NAME="or_eq"><CODE>or_eq</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>or_eq</B> |= <B>[keyword in C++]</B>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the operator <CODE>|=</CODE>.</P>
|
||||
|
||||
<H2><A NAME="xor"><CODE>xor</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>xor</B> ^ <B>[keyword in C++]</B>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the operator <CODE>^</CODE>.</P>
|
||||
|
||||
<H2><A NAME="xor_eq"><CODE>xor_eq</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>xor_eq</B> ^= <B>[keyword in C++]</B>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the operator <CODE>^=</CODE>.</P>
|
||||
|
||||
<HR>
|
||||
<P>See also the
|
||||
<B><A HREF="index.html#Table of Contents" tppabs="http://ccs.ucsd.edu/c/index.html#Table of Contents">Table of Contents</A></B> and the
|
||||
<B><A HREF="_index.html" tppabs="http://ccs.ucsd.edu/c/_index.html">Index</A></B>.</P>
|
||||
|
||||
<P><I>
|
||||
<A HREF="crit_pb.html" tppabs="http://ccs.ucsd.edu/c/crit_pb.html">Copyright</A> © 1989-1996
|
||||
by P.J. Plauger and Jim Brodie. All rights reserved.</I></P>
|
||||
|
||||
</BODY></HTML>
|
||||
372
study/Ref-docs/C/lib_file.html
Normal file
@@ -0,0 +1,372 @@
|
||||
<HTML><HEAD><TITLE>Files and Streams</TITLE></HEAD><BODY BGCOLOR="#FFFFFF">
|
||||
|
||||
<H1><A NAME="Files and Streams">Files and Streams</A></H1><HR>
|
||||
|
||||
<P><B><A HREF="#Text and Binary Streams">Text and Binary Streams</A>
|
||||
· <A HREF="#Byte and Wide Streams">Byte and Wide Streams</A>
|
||||
· <A HREF="#Controlling Streams">Controlling Streams</A>
|
||||
· <A HREF="#Stream States">Stream States</A>
|
||||
</B></P>
|
||||
<HR>
|
||||
|
||||
<P>A program communicates with the target environment by reading
|
||||
and writing
|
||||
<B><A NAME="files">files</A></B> (ordered sequences of bytes). A file can
|
||||
be, for example, a data set that you can read and write repeatedly
|
||||
(such as a disk file), a stream of bytes generated by a program (such
|
||||
as a pipeline), or a stream of bytes received from or sent to a peripheral
|
||||
device (such as the keyboard or display). The latter two are
|
||||
<B><A NAME="interactive files">interactive files</A></B>.
|
||||
Files are typically the principal means by which to interact with a
|
||||
program.</P>
|
||||
|
||||
<P>You manipulate all these kinds of files in much the same way
|
||||
-- by calling library functions. You include the standard header
|
||||
<CODE><stdio.h></CODE> to declare most of these functions.</P>
|
||||
|
||||
<P>Before you can perform many of the operations on a file, the
|
||||
file must be
|
||||
<B><A NAME="file open">opened</A></B>.
|
||||
Opening a file associates it with a
|
||||
<B><A NAME="stream">stream</A></B>, a data structure within
|
||||
the Standard C library that glosses over many differences
|
||||
among files of various kinds.
|
||||
The library maintains the state of each stream in an object of type
|
||||
<B><A HREF="stdio.html#FILE" tppabs="http://ccs.ucsd.edu/c/stdio.html#FILE"><CODE>FILE</CODE></A></B>.</P>
|
||||
|
||||
<P>The target environment opens three files prior to
|
||||
<A HREF="lib_over.html#program startup" tppabs="http://ccs.ucsd.edu/c/lib_over.html#program startup">program startup</A>.
|
||||
You can open a file by calling the library function
|
||||
<A HREF="stdio.html#fopen" tppabs="http://ccs.ucsd.edu/c/stdio.html#fopen"><CODE>fopen</CODE></A> with
|
||||
two arguments. The first argument is a
|
||||
<A HREF="lib_over.html#filename" tppabs="http://ccs.ucsd.edu/c/lib_over.html#filename">filename</A>, a
|
||||
<A HREF="lib_over.html#multibyte string" tppabs="http://ccs.ucsd.edu/c/lib_over.html#multibyte string">multibyte string</A>
|
||||
that the target environment uses to identify which file you
|
||||
want to read or write. The second argument is a
|
||||
<A HREF="lib_over.html#C string" tppabs="http://ccs.ucsd.edu/c/lib_over.html#C string">C string</A> that specifies:</P>
|
||||
|
||||
<UL>
|
||||
<LI>whether you intend to read data from the file or write data
|
||||
to it or both
|
||||
|
||||
<LI>whether you intend to generate new contents for the file (or
|
||||
create a file if it did not previously exist) or leave the existing
|
||||
contents in place
|
||||
|
||||
<LI>whether writes to a file can alter existing contents or should
|
||||
only append bytes at the end of the file
|
||||
|
||||
<LI>whether you want to manipulate a
|
||||
<A HREF="#text stream">text stream</A> or a
|
||||
<A HREF="#binary stream">binary stream</A>
|
||||
</UL>
|
||||
|
||||
<P>Once the file is successfully opened, you can then determine
|
||||
whether the stream is
|
||||
<B><A NAME="byte oriented">byte oriented</A></B> (a
|
||||
<B><A HREF="#byte stream">byte stream</A></B>) or
|
||||
<B><A NAME="wide oriented">wide oriented</A></B> (a
|
||||
<B><A HREF="#wide stream">wide stream</A></B>).
|
||||
Wide-oriented streams are supported only with
|
||||
<A HREF="lib_over.html#Amendment 1" tppabs="http://ccs.ucsd.edu/c/lib_over.html#Amendment 1">Amendment 1</A>.
|
||||
A stream is initially
|
||||
<B><A NAME="unbound stream">unbound</A></B>.
|
||||
Calling certain functions to operate on the stream makes it byte oriented,
|
||||
while certain other functions make it wide oriented. Once established,
|
||||
a stream maintains its orientation until it is closed by a call to
|
||||
<A HREF="stdio.html#fclose" tppabs="http://ccs.ucsd.edu/c/stdio.html#fclose"><CODE>fclose</CODE></A> or
|
||||
<A HREF="stdio.html#freopen" tppabs="http://ccs.ucsd.edu/c/stdio.html#freopen"><CODE>freopen</CODE></A>.</P>
|
||||
|
||||
<H2><A NAME="Text and Binary Streams">Text and Binary Streams</A></H2>
|
||||
|
||||
<P>A
|
||||
<B><A NAME="text stream">text stream</A></B> consists of one or more
|
||||
<B><A NAME="text lines">lines</A></B> of text
|
||||
that can be written to a text-oriented display so that they can
|
||||
be read. When reading from a text stream, the program reads an
|
||||
<CODE><I>NL</I></CODE> (newline) at the end of each line.
|
||||
When writing to a text stream, the program writes an
|
||||
<CODE><I>NL</I></CODE> to signal the end of a line. To match
|
||||
differing conventions among target environments for representing text
|
||||
in files, the library functions can alter the number and representations
|
||||
of characters transmitted between the program and a text stream.</P>
|
||||
|
||||
<P>Thus, positioning within a text stream is limited.
|
||||
You can obtain the current
|
||||
<A HREF="#file-position indicator">file-position indicator</A>
|
||||
by calling <CODE><A HREF="stdio.html#fgetpos" tppabs="http://ccs.ucsd.edu/c/stdio.html#fgetpos">fgetpos</A></CODE> or
|
||||
<CODE><A HREF="stdio.html#ftell" tppabs="http://ccs.ucsd.edu/c/stdio.html#ftell">ftell</A></CODE>.
|
||||
You can position a text stream at a position obtained this way,
|
||||
or at the beginning or end of the stream, by calling
|
||||
<CODE><A HREF="stdio.html#fsetpos" tppabs="http://ccs.ucsd.edu/c/stdio.html#fsetpos">fsetpos</A></CODE> or
|
||||
<CODE><A HREF="stdio.html#fseek" tppabs="http://ccs.ucsd.edu/c/stdio.html#fseek">fseek</A></CODE>.
|
||||
Any other change of position might well be not supported.</P>
|
||||
|
||||
<P>For maximum portability, the program should not write:</P>
|
||||
|
||||
<UL>
|
||||
<LI>empty files
|
||||
|
||||
<LI><CODE><I>space</I></CODE> characters at the end of a line
|
||||
|
||||
<LI>partial lines (by omitting the <CODE><I>NL</I></CODE>
|
||||
at the end of a file)
|
||||
|
||||
<LI>characters other than the printable characters,
|
||||
<CODE><I>NL</I></CODE>, and <CODE><I>HT</I></CODE> (horizontal tab)
|
||||
</UL>
|
||||
|
||||
<P>If you follow these rules, the sequence of characters you read
|
||||
from a text stream (either as byte or multibyte characters)
|
||||
will match the sequence of characters you wrote to the text stream
|
||||
when you created the file. Otherwise, the library functions can remove
|
||||
a file you create if the file is empty when you close it. Or they
|
||||
can alter or delete characters you write to the file.</P>
|
||||
|
||||
<P>A
|
||||
<B><A NAME="binary stream">binary stream</A></B> consists of
|
||||
one or more bytes of arbitrary information.
|
||||
You can write the value stored in an arbitrary object
|
||||
to a (byte-oriented) binary stream and read exactly what was stored
|
||||
in the object when you wrote it. The library functions do not alter
|
||||
the bytes you transmit between the program and a binary stream. They
|
||||
can, however, append an arbitrary number of null bytes to the file
|
||||
that you write with a binary stream. The program must deal with these
|
||||
additional null bytes at the end of any binary stream.</P>
|
||||
|
||||
<P>Thus, positioning within a binary stream is well defined,
|
||||
except for positioning relative to the end of the stream.
|
||||
You can obtain and alter the current
|
||||
<A HREF="#file-position indicator">file-position indicator</A>
|
||||
the same as for a <A HREF="#text stream">text stream</A>.
|
||||
Moreover, the offsets used by
|
||||
<CODE><A HREF="stdio.html#ftell" tppabs="http://ccs.ucsd.edu/c/stdio.html#ftell">ftell</A></CODE> and
|
||||
<CODE><A HREF="stdio.html#fseek" tppabs="http://ccs.ucsd.edu/c/stdio.html#fseek">fseek</A></CODE>
|
||||
count bytes from the beginning of the stream (which is byte zero),
|
||||
so integer arithmetic on these offsets yields predictable results.</P>
|
||||
|
||||
<H2><A NAME="Byte and Wide Streams">Byte and Wide Streams</A></H2>
|
||||
|
||||
<P>A
|
||||
<B><A NAME="byte stream">byte stream</A></B>
|
||||
treats a file as a sequence of bytes. Within the program,
|
||||
the stream looks like the same sequence of bytes, except
|
||||
for the possible alterations described above.</P>
|
||||
|
||||
<P>By contrast, a
|
||||
<B><A NAME="wide stream">wide stream</A></B> treats a file as a sequence of
|
||||
<B><A NAME="generalized multibyte characters">
|
||||
generalized multibyte characters</A></B>,
|
||||
which can have a broad range of encoding rules.
|
||||
(Text and binary files are still read and written as described above.)
|
||||
Within the program, the stream looks like the corresponding sequence of
|
||||
<A HREF="charset.html#Wide-Character Encoding" tppabs="http://ccs.ucsd.edu/c/charset.html#Wide-Character Encoding">wide characters</A>.
|
||||
Conversions between the two representations occur
|
||||
within the Standard C library. The conversion rules can, in principle,
|
||||
be altered by a call to
|
||||
<A HREF="locale.html#setlocale" tppabs="http://ccs.ucsd.edu/c/locale.html#setlocale"><CODE>setlocale</CODE></A>
|
||||
that alters the category
|
||||
<A HREF="locale.html#LC_CTYPE" tppabs="http://ccs.ucsd.edu/c/locale.html#LC_CTYPE"><CODE>LC_CTYPE</CODE></A>.
|
||||
Each wide stream determines its conversion rules
|
||||
at the time it becomes wide oriented, and retains
|
||||
these rules even if the category
|
||||
<A HREF="locale.html#LC_CTYPE" tppabs="http://ccs.ucsd.edu/c/locale.html#LC_CTYPE"><CODE>LC_CTYPE</CODE></A>
|
||||
subsequently changes.</P>
|
||||
|
||||
<P>Positioning within a wide stream suffers the same limitations as for
|
||||
<A HREF="#text stream">text streams</A>. Moreover, the
|
||||
<A HREF="#file-position indicator">file-position indicator</A>
|
||||
may well have to deal with a
|
||||
<A HREF="charset.html#state-dependent encoding" tppabs="http://ccs.ucsd.edu/c/charset.html#state-dependent encoding">state-dependent encoding</A>.
|
||||
Typically, it includes both a byte offset within the stream
|
||||
and an object of type
|
||||
<CODE><A HREF="wchar.html#mbstate_t" tppabs="http://ccs.ucsd.edu/c/wchar.html#mbstate_t"></CODE>. Thus, the only
|
||||
reliable way to obtain a file position within a wide stream is by calling
|
||||
<CODE><A HREF="stdio.html#fgetpos" tppabs="http://ccs.ucsd.edu/c/stdio.html#fgetpos">fgetpos</A></CODE>,
|
||||
and the only reliable way to restore a position
|
||||
obtained this way is by calling
|
||||
<CODE><A HREF="stdio.html#fsetpos" tppabs="http://ccs.ucsd.edu/c/stdio.html#fsetpos">fsetpos</A></CODE>.
|
||||
|
||||
<H2><A NAME="Controlling Streams">Controlling Streams</A></H2>
|
||||
|
||||
<P><A HREF="stdio.html#fopen" tppabs="http://ccs.ucsd.edu/c/stdio.html#fopen"><CODE>fopen</CODE>
|
||||
returns the address of an object of type
|
||||
<A HREF="stdio.html#FILE" tppabs="http://ccs.ucsd.edu/c/stdio.html#FILE"><CODE>FILE</CODE></A>.
|
||||
You use this address as the <CODE>stream</CODE> argument to several library
|
||||
functions to perform various operations on an open file. For a byte
|
||||
stream, all input takes place as if each character is read by calling
|
||||
<A HREF="stdio.html#fgetc" tppabs="http://ccs.ucsd.edu/c/stdio.html#fgetc"><CODE>fgetc</CODE></A>,
|
||||
and all output takes place as if each character is written by calling
|
||||
<A HREF="stdio.html#fputc" tppabs="http://ccs.ucsd.edu/c/stdio.html#fputc"><CODE>fputc</CODE></A>. For a wide stream (with
|
||||
<A HREF="lib_over.html#Amendment 1" tppabs="http://ccs.ucsd.edu/c/lib_over.html#Amendment 1">Amendment 1</A>),
|
||||
all input takes place as if each character is read by calling
|
||||
<A HREF="wchar.html#fgetwc" tppabs="http://ccs.ucsd.edu/c/wchar.html#fgetwc"><CODE>fgetwc</CODE></A>,
|
||||
and all output takes place as if each character is written by calling
|
||||
<A HREF="wchar.html#fputwc" tppabs="http://ccs.ucsd.edu/c/wchar.html#fputwc"><CODE>fputwc</CODE></A>.</P>
|
||||
|
||||
<P>You can
|
||||
<B><A NAME="file close">close</A></B> a file by calling
|
||||
<A HREF="stdio.html#fclose" tppabs="http://ccs.ucsd.edu/c/stdio.html#fclose"><CODE>fclose</CODE></A>,
|
||||
after which the address of the
|
||||
<A HREF="stdio.html#FILE" tppabs="http://ccs.ucsd.edu/c/stdio.html#FILE"><CODE>FILE</CODE></A> object is invalid.</P>
|
||||
|
||||
<P>A <A HREF="stdio.html#FILE" tppabs="http://ccs.ucsd.edu/c/stdio.html#FILE"><CODE>FILE</CODE></A>
|
||||
object stores the state of a stream, including:</P>
|
||||
|
||||
<UL>
|
||||
<LI>an <B><A NAME="error indicator">error indicator</A></B> --
|
||||
set nonzero by a function that encounters a read or write error
|
||||
|
||||
<LI>an <B><A NAME="end-of-file indicator">end-of-file indicator</A></B> --
|
||||
set nonzero by a function that
|
||||
encounters the end of the file while reading
|
||||
|
||||
<LI>a <B><A NAME="file-position indicator">file-position indicator</A></B> --
|
||||
specifies the next byte in the stream to read or write,
|
||||
if the file can support positioning requests
|
||||
|
||||
<LI>a <B><A HREF="#Stream States">stream state</A></B> --
|
||||
specifies whether the stream will accept reads and/or writes and, with
|
||||
<A HREF="lib_over.html#Amendment 1" tppabs="http://ccs.ucsd.edu/c/lib_over.html#Amendment 1">Amendment 1</A>, whether the stream is
|
||||
<A HREF="#unbound stream">unbound</A>,
|
||||
<A HREF="#byte oriented">byte oriented</A>, or
|
||||
<A HREF="#wide oriented">wide oriented</A>
|
||||
|
||||
<LI>a <B><A HREF="charset.html#conversion state" tppabs="http://ccs.ucsd.edu/c/charset.html#conversion state">conversion state</A></B> --
|
||||
remembers the state of any partly assembled or generated
|
||||
<A HREF="#generalized multibyte characters">
|
||||
generalized multibyte character</A>, as well as
|
||||
any shift state for the sequence of bytes in the file)
|
||||
|
||||
<LI>a <B><A NAME="file buffer">file buffer</A></B> --
|
||||
specifies the address and size of an array object
|
||||
that library functions can use to improve the performance
|
||||
of read and write operations to the stream
|
||||
</UL>
|
||||
|
||||
<P>Do not alter any value stored in a
|
||||
<A HREF="stdio.html#FILE" tppabs="http://ccs.ucsd.edu/c/stdio.html#FILE"><CODE>FILE</CODE></A> object or in
|
||||
a file buffer that you specify for use with that object.
|
||||
You cannot copy a
|
||||
<A HREF="stdio.html#FILE" tppabs="http://ccs.ucsd.edu/c/stdio.html#FILE"><CODE>FILE</CODE></A> object
|
||||
and portably use the address of the copy
|
||||
as a <CODE>stream</CODE> argument to a library function.</P>
|
||||
|
||||
<H2><A NAME="Stream States">Stream States</A></H2>
|
||||
|
||||
<P>The valid states, and state transitions, for a stream are:</P>
|
||||
|
||||
<P><IMG SRC="stream.gif" tppabs="http://ccs.ucsd.edu/c/gif/stream.gif"></P>
|
||||
|
||||
<P>Each of the circles denotes a stable
|
||||
state. Each of the lines denotes a transition that can occur as the
|
||||
result of a function call that operates on the stream. Five groups
|
||||
of functions can cause state transitions.</P>
|
||||
|
||||
<P>Functions in the first three groups are declared in
|
||||
<A HREF="stdio.html" tppabs="http://ccs.ucsd.edu/c/stdio.html"><CODE><stdio.h></CODE></A>:</P>
|
||||
|
||||
<UL>
|
||||
<LI>the <B><A NAME="byte read functions">byte read functions</A></B> --
|
||||
<A HREF="stdio.html#fgetc" tppabs="http://ccs.ucsd.edu/c/stdio.html#fgetc"><CODE>fgetc</CODE></A>,
|
||||
<A HREF="stdio.html#fgets" tppabs="http://ccs.ucsd.edu/c/stdio.html#fgets"><CODE>fgets</CODE></A>,
|
||||
<A HREF="stdio.html#fread" tppabs="http://ccs.ucsd.edu/c/stdio.html#fread"><CODE>fread</CODE></A>,
|
||||
<A HREF="stdio.html#fscanf" tppabs="http://ccs.ucsd.edu/c/stdio.html#fscanf"><CODE>fscanf</CODE></A>,
|
||||
<A HREF="stdio.html#getc" tppabs="http://ccs.ucsd.edu/c/stdio.html#getc"><CODE>getc</CODE></A>,
|
||||
<A HREF="stdio.html#getchar" tppabs="http://ccs.ucsd.edu/c/stdio.html#getchar"><CODE>getchar</CODE></A>,
|
||||
<A HREF="stdio.html#gets" tppabs="http://ccs.ucsd.edu/c/stdio.html#gets"><CODE>gets</CODE></A>,
|
||||
<A HREF="stdio.html#scanf" tppabs="http://ccs.ucsd.edu/c/stdio.html#scanf"><CODE>scanf</CODE></A>, and
|
||||
<A HREF="stdio.html#ungetc" tppabs="http://ccs.ucsd.edu/c/stdio.html#ungetc"><CODE>ungetc</CODE></A>
|
||||
|
||||
<LI>the <B><A NAME="byte write functions">byte write functions</A></B> --
|
||||
<A HREF="stdio.html#fprintf" tppabs="http://ccs.ucsd.edu/c/stdio.html#fprintf"><CODE>fprintf</CODE></A>,
|
||||
<A HREF="stdio.html#fputc" tppabs="http://ccs.ucsd.edu/c/stdio.html#fputc"><CODE>fputc</CODE></A>,
|
||||
<A HREF="stdio.html#fputs" tppabs="http://ccs.ucsd.edu/c/stdio.html#fputs"><CODE>fputs</CODE></A>,
|
||||
<A HREF="stdio.html#fwrite" tppabs="http://ccs.ucsd.edu/c/stdio.html#fwrite"><CODE>fwrite</CODE></A>,
|
||||
<A HREF="stdio.html#printf" tppabs="http://ccs.ucsd.edu/c/stdio.html#printf"><CODE>printf</CODE></A>,
|
||||
<A HREF="stdio.html#putc" tppabs="http://ccs.ucsd.edu/c/stdio.html#putc"><CODE>putc</CODE></A>,
|
||||
<A HREF="stdio.html#putchar" tppabs="http://ccs.ucsd.edu/c/stdio.html#putchar"><CODE>putchar</CODE></A>,
|
||||
<A HREF="stdio.html#puts" tppabs="http://ccs.ucsd.edu/c/stdio.html#puts"><CODE>puts</CODE></A>,
|
||||
<A HREF="stdio.html#vfprintf" tppabs="http://ccs.ucsd.edu/c/stdio.html#vfprintf"><CODE>vfprintf</CODE></A>, and
|
||||
<A HREF="stdio.html#vprintf" tppabs="http://ccs.ucsd.edu/c/stdio.html#vprintf"><CODE>vprintf</CODE></A>
|
||||
|
||||
<LI>the <B><A NAME="position functions">position functions</A></B> --
|
||||
<A HREF="stdio.html#fflush" tppabs="http://ccs.ucsd.edu/c/stdio.html#fflush"><CODE>fflush</CODE></A>,
|
||||
<A HREF="stdio.html#fseek" tppabs="http://ccs.ucsd.edu/c/stdio.html#fseek"><CODE>fseek</CODE></A>,
|
||||
<A HREF="stdio.html#fsetpos" tppabs="http://ccs.ucsd.edu/c/stdio.html#fsetpos"><CODE>fsetpos</CODE></A>, and
|
||||
<A HREF="stdio.html#rewind" tppabs="http://ccs.ucsd.edu/c/stdio.html#rewind"><CODE>rewind</CODE></A>
|
||||
</UL>
|
||||
|
||||
<P>Functions in the remaining two groups are declared
|
||||
in <CODE><wchar.h></CODE>:</P>
|
||||
|
||||
<UL>
|
||||
<LI>the <B><A NAME="wide read functions">wide read functions</A></B> --
|
||||
<A HREF="wchar.html#fgetwc" tppabs="http://ccs.ucsd.edu/c/wchar.html#fgetwc"><CODE>fgetwc</CODE></A>,
|
||||
<A HREF="wchar.html#fgetws" tppabs="http://ccs.ucsd.edu/c/wchar.html#fgetws"><CODE>fgetws</CODE></A>,
|
||||
<A HREF="wchar.html#fwscanf" tppabs="http://ccs.ucsd.edu/c/wchar.html#fwscanf"><CODE>fwscanf</CODE></A>,
|
||||
<A HREF="wchar.html#getwc" tppabs="http://ccs.ucsd.edu/c/wchar.html#getwc"><CODE>getwc</CODE></A>,
|
||||
<A HREF="wchar.html#getwchar" tppabs="http://ccs.ucsd.edu/c/wchar.html#getwchar"><CODE>getwchar</CODE></A>,
|
||||
<A HREF="wchar.html#ungetwc" tppabs="http://ccs.ucsd.edu/c/wchar.html#ungetwc"><CODE>ungetwc</CODE></A>, and
|
||||
<A HREF="wchar.html#wscanf" tppabs="http://ccs.ucsd.edu/c/wchar.html#wscanf"><CODE>wscanf</CODE></A>,
|
||||
|
||||
<LI>the <B><A NAME="wide write functions">wide write functions</A></B> --
|
||||
<A HREF="wchar.html#fwprintf" tppabs="http://ccs.ucsd.edu/c/wchar.html#fwprintf"><CODE>fwprintf</CODE></A>,
|
||||
<A HREF="wchar.html#fputwc" tppabs="http://ccs.ucsd.edu/c/wchar.html#fputwc"><CODE>fputwc</CODE></A>,
|
||||
<A HREF="wchar.html#fputws" tppabs="http://ccs.ucsd.edu/c/wchar.html#fputws"><CODE>fputws</CODE></A>,
|
||||
<A HREF="wchar.html#putwc" tppabs="http://ccs.ucsd.edu/c/wchar.html#putwc"><CODE>putwc</CODE></A>,
|
||||
<A HREF="wchar.html#putwchar" tppabs="http://ccs.ucsd.edu/c/wchar.html#putwchar"><CODE>putwchar</CODE></A>,
|
||||
<A HREF="wchar.html#vfwprintf" tppabs="http://ccs.ucsd.edu/c/wchar.html#vfwprintf"><CODE>vfwprintf</CODE></A>,
|
||||
<A HREF="wchar.html#vwprintf" tppabs="http://ccs.ucsd.edu/c/wchar.html#vwprintf"><CODE>vwprintf</CODE></A>, and
|
||||
<A HREF="wchar.html#wprintf" tppabs="http://ccs.ucsd.edu/c/wchar.html#wprintf"><CODE>wprintf</CODE></A>,
|
||||
</UL>
|
||||
|
||||
<P>For the stream <CODE>s</CODE>, the call
|
||||
<CODE><A HREF="wchar.html#fwide" tppabs="http://ccs.ucsd.edu/c/wchar.html#fwide">fwide</A>(s, 0)</CODE>
|
||||
is always valid and never causes a change of state. Any other call to
|
||||
<A HREF="wchar.html#fwide" tppabs="http://ccs.ucsd.edu/c/wchar.html#fwide"><CODE>fwide</CODE></A>, or to any of the five
|
||||
groups of functions described above, causes the state transition shown
|
||||
in the state diagram. If no such transition is shown, the function
|
||||
call is invalid.</P>
|
||||
|
||||
<P>The state diagram shows how to establish the orientation of
|
||||
a stream:</P>
|
||||
|
||||
<UL>
|
||||
<LI>The call
|
||||
<CODE><A HREF="wchar.html#fwide" tppabs="http://ccs.ucsd.edu/c/wchar.html#fwide">fwide</A>(s, -1)</CODE>,
|
||||
or to a byte read or byte write function, establishes the stream as
|
||||
<A HREF="#byte oriented">byte oriented</A>.
|
||||
|
||||
<LI>The call
|
||||
<CODE><A HREF="wchar.html#fwide" tppabs="http://ccs.ucsd.edu/c/wchar.html#fwide">fwide</A>(s, 1)</CODE>,
|
||||
or to a wide read or wide write function, establishes the stream as
|
||||
<A HREF="#wide oriented">wide oriented</A>.
|
||||
</UL>
|
||||
|
||||
<P>The state diagram also shows that you must call one of the position
|
||||
functions between most write and read operations:</P>
|
||||
|
||||
<UL>
|
||||
<LI>You cannot call a read function if the last operation on the
|
||||
stream was a write.
|
||||
|
||||
<LI>You cannot call a write function if the last operation on the
|
||||
stream was a read, unless that read operation set the
|
||||
<A HREF="#end-of-file indicator">end-of-file indicator</A>.
|
||||
</UL>
|
||||
|
||||
<P>Finally, the state diagram shows that a position operation never
|
||||
<I>decreases</I> the number of valid function calls that can follow.</P>
|
||||
|
||||
<HR>
|
||||
<P>See also the
|
||||
<B><A HREF="index.html#Table of Contents" tppabs="http://ccs.ucsd.edu/c/index.html#Table of Contents">Table of Contents</A></B> and the
|
||||
<B><A HREF="_index.html" tppabs="http://ccs.ucsd.edu/c/_index.html">Index</A></B>.</P>
|
||||
|
||||
<P><I>
|
||||
<A HREF="crit_pb.html" tppabs="http://ccs.ucsd.edu/c/crit_pb.html">Copyright</A> © 1989-1996
|
||||
by P.J. Plauger and Jim Brodie. All rights reserved.</I></P>
|
||||
|
||||
</BODY></HTML>
|
||||
|
||||
369
study/Ref-docs/C/lib_over.html
Normal file
@@ -0,0 +1,369 @@
|
||||
<HTML><HEAD><TITLE>C Library Overview</TITLE></HEAD><BODY BGCOLOR="#FFFFFF">
|
||||
|
||||
<H1><A NAME="C Library Overview">C Library Overview</A></H1><HR>
|
||||
|
||||
<P><B><A HREF="#Using Standard C Headers">Using Standard C Headers</A>
|
||||
· <A HREF="#C Library Conventions">C Library Conventions</A>
|
||||
· <A HREF="#C Program Startup and Termination">
|
||||
· Program Startup and Termination</A>
|
||||
</B></P>
|
||||
<HR>
|
||||
|
||||
<P>All Standard C library entities are declared or defined in one or more
|
||||
<B><A NAME="standard headers">standard headers</A></B>.
|
||||
To make use of a library entity in a program, write an
|
||||
<A HREF="preproc.html#include directive" tppabs="http://ccs.ucsd.edu/c/preproc.html#include directive"><I>include</I> directive</A>
|
||||
that names the relevant
|
||||
<B><A NAME="standard header">standard header</A></B>.
|
||||
The full set of 18 Standard C headers constitutes a
|
||||
<B><A NAME="hosted implementation">hosted implementation</A></B>:
|
||||
<CODE><A HREF="assert.html" tppabs="http://ccs.ucsd.edu/c/assert.html"><assert.h></A></CODE>,
|
||||
<CODE><A HREF="ctype.html" tppabs="http://ccs.ucsd.edu/c/ctype.html"><ctype.h></A></CODE>,
|
||||
<CODE><A HREF="errno.html" tppabs="http://ccs.ucsd.edu/c/errno.html"><errno.h></A></CODE>,
|
||||
<CODE><A HREF="float.html" tppabs="http://ccs.ucsd.edu/c/float.html"><float.h></A></CODE>,
|
||||
<CODE><A HREF="iso646.html" tppabs="http://ccs.ucsd.edu/c/iso646.html"><iso646.h></A></CODE>,
|
||||
<CODE><A HREF="limits.html" tppabs="http://ccs.ucsd.edu/c/limits.html"><limits.h></A></CODE>,
|
||||
<CODE><A HREF="locale.html" tppabs="http://ccs.ucsd.edu/c/locale.html"><locale.h></A></CODE>,
|
||||
<CODE><A HREF="math.html" tppabs="http://ccs.ucsd.edu/c/math.html"><math.h></A></CODE>,
|
||||
<CODE><A HREF="setjmp.html" tppabs="http://ccs.ucsd.edu/c/setjmp.html"><setjmp.h></A></CODE>,
|
||||
<CODE><A HREF="signal.html" tppabs="http://ccs.ucsd.edu/c/signal.html"><signal.h></A></CODE>,
|
||||
<CODE><A HREF="stdarg.html" tppabs="http://ccs.ucsd.edu/c/stdarg.html"><stdarg.h></A></CODE>,
|
||||
<CODE><A HREF="stddef.html" tppabs="http://ccs.ucsd.edu/c/stddef.html"><stddef.h></A></CODE>,
|
||||
<CODE><A HREF="stdio.html" tppabs="http://ccs.ucsd.edu/c/stdio.html"><stdio.h></A></CODE>,
|
||||
<CODE><A HREF="stdlib.html" tppabs="http://ccs.ucsd.edu/c/stdlib.html"><stdlib.h></A></CODE>,
|
||||
<CODE><A HREF="string.html" tppabs="http://ccs.ucsd.edu/c/string.html"><string.h></A></CODE>,
|
||||
<CODE><A HREF="time.html" tppabs="http://ccs.ucsd.edu/c/time.html"><time.h></A></CODE>,
|
||||
<CODE><A HREF="wchar.html" tppabs="http://ccs.ucsd.edu/c/wchar.html"><wchar.h></A></CODE>, and
|
||||
<CODE><A HREF="wctype.html" tppabs="http://ccs.ucsd.edu/c/wctype.html"><wctype.h></A></CODE>.</P>
|
||||
|
||||
<P>(The headers
|
||||
<CODE><A HREF="iso646.html" tppabs="http://ccs.ucsd.edu/c/iso646.html"><iso646.h></A></CODE>,
|
||||
<CODE><A HREF="wchar.html" tppabs="http://ccs.ucsd.edu/c/wchar.html"><wchar.h></A></CODE>, and
|
||||
<CODE><A HREF="wctype.html" tppabs="http://ccs.ucsd.edu/c/wctype.html"><wctype.h></A></CODE> are added with
|
||||
<B><A NAME="Amendment 1">Amendment 1</A></B>, an addition
|
||||
to the C Standard published in 1995.)</P>
|
||||
|
||||
<P>A <B><A NAME="freestanding implementation">freestanding implementation</B>
|
||||
of Standard C provides only a subset of these standard headers:
|
||||
<CODE><A HREF="float.html" tppabs="http://ccs.ucsd.edu/c/float.html"><float.h></A></CODE>,
|
||||
<CODE><A HREF="limits.html" tppabs="http://ccs.ucsd.edu/c/limits.html"><limits.h></A></CODE>,
|
||||
<CODE><A HREF="stdarg.html" tppabs="http://ccs.ucsd.edu/c/stdarg.html"><stdarg.h></A></CODE>, and
|
||||
<CODE><A HREF="stddef.html" tppabs="http://ccs.ucsd.edu/c/stddef.html"><stddef.h></A></CODE>.
|
||||
Each freestanding implementation defines:</P>
|
||||
|
||||
<UL>
|
||||
<LI>how it starts the program
|
||||
|
||||
<LI>what happens when the program terminates
|
||||
|
||||
<LI>what library functions (if any) it provides
|
||||
</UL>
|
||||
|
||||
<H2><A NAME="Using Standard C Headers">Using Standard C Headers</A></H2>
|
||||
|
||||
<P>You include the contents of a standard header by naming it in an
|
||||
<A HREF="preproc.html#include directive" tppabs="http://ccs.ucsd.edu/c/preproc.html#include directive"><I>include</I> directive</A>,
|
||||
as in:</P>
|
||||
|
||||
<PRE>
|
||||
#include <stdio.h> /* include I/O facilities */</PRE>
|
||||
|
||||
<P>You can include the standard headers in any order, a standard
|
||||
header more than once, or two or more standard headers that define
|
||||
the same macro or the same type.
|
||||
Do not include a standard header within a declaration. Do not
|
||||
define macros that have the same names as keywords before you include
|
||||
a standard header.</P>
|
||||
|
||||
<P>A standard header never includes another standard header. A
|
||||
standard header declares or defines only the entities described for
|
||||
it in this document.</P>
|
||||
|
||||
<P>Every function in the library is declared in a standard header.
|
||||
The standard header can also provide a
|
||||
<B><A NAME="masking macro">masking macro</A></B>, with the same name as
|
||||
the function, that masks the function declaration and achieves the
|
||||
same effect. The macro typically expands to an expression that executes
|
||||
faster than a call to the function of the same name. The macro can,
|
||||
however, cause confusion when you are tracing or debugging the program.
|
||||
So you can use a standard header in two ways to declare or define
|
||||
a library function. To take advantage of any macro version, include
|
||||
the standard header so that each apparent call to the function can
|
||||
be replaced by a macro expansion.</P>
|
||||
|
||||
<P>For example:</P>
|
||||
|
||||
<PRE>
|
||||
#include <ctype.h>
|
||||
char *skip_space(char *p)
|
||||
{
|
||||
while (isspace(*p)) <B>can be a macro</B>
|
||||
++p;
|
||||
return (p);
|
||||
}</PRE>
|
||||
|
||||
<P>To ensure that the program calls the actual library function,
|
||||
include the standard header and remove any macro definition with an
|
||||
<A HREF="preproc.html#undef directive" tppabs="http://ccs.ucsd.edu/c/preproc.html#undef directive"><I>undef</I> directive</A>.</P>
|
||||
|
||||
<P>For example:</P>
|
||||
|
||||
<PRE>
|
||||
#include <ctype.h>
|
||||
#undef isspace <B>remove any macro definition</B>
|
||||
int f(char *p) {
|
||||
while (isspace(*p)) <B>must be a function</B>
|
||||
++p;</PRE>
|
||||
|
||||
<P>You can use many functions in the library without including
|
||||
a standard header (although this practice is not recommended). If
|
||||
you do not need defined macros or types to declare and call the function,
|
||||
you can simply declare the function as it appears in this chapter.
|
||||
Again, you have two choices. You can declare the function explicitly.</P>
|
||||
|
||||
<P>For example:</P>
|
||||
|
||||
<PRE>
|
||||
double sin(double x); <B>declared in <math.h></B>
|
||||
y = rho * sin(theta);</PRE>
|
||||
|
||||
<P>Or you can declare the function implicitly if it is a function
|
||||
returning <I>int</I> with a fixed number of arguments, as in:</P>
|
||||
|
||||
<PRE>
|
||||
n = atoi(str); <B>declared in <stdlib.h></B></PRE>
|
||||
|
||||
<P>If the function has a
|
||||
<A HREF="stdarg.html#varying number of arguments" tppabs="http://ccs.ucsd.edu/c/stdarg.html#varying number of arguments">varying number
|
||||
of arguments</A>, such as
|
||||
<A HREF="stdio.html#printf" tppabs="http://ccs.ucsd.edu/c/stdio.html#printf"><CODE>printf</CODE></A>,
|
||||
you must declare it explicitly: Either include the standard header
|
||||
that declares it or write an explicit declaration.</P>
|
||||
|
||||
<P>Note also that you cannot define a macro or type definition
|
||||
without including its standard header
|
||||
because each of these varies among implementations.
|
||||
</P>
|
||||
|
||||
<H2><A NAME="C Library Conventions">C Library Conventions</A></H2>
|
||||
|
||||
<P>A library macro that
|
||||
<A HREF="#masking macro">masks</A>
|
||||
a function declaration expands to
|
||||
an expression that evaluates each of its arguments once (and only
|
||||
once). Arguments that have
|
||||
<A HREF="function.html#side-effects context" tppabs="http://ccs.ucsd.edu/c/function.html#side-effects context">side effects</A>
|
||||
evaluate the same way whether the expression executes
|
||||
the macro expansion or calls the function.
|
||||
Macros for the functions
|
||||
<A HREF="stdio.html#getc" tppabs="http://ccs.ucsd.edu/c/stdio.html#getc"><CODE>getc</CODE></A> and
|
||||
<A HREF="stdio.html#putc" tppabs="http://ccs.ucsd.edu/c/stdio.html#putc"><CODE>putc</CODE></A>
|
||||
are explicit exceptions to this rule. Their <CODE>stream</CODE>
|
||||
arguments can be evaluated more than once. Avoid argument expressions
|
||||
that have side effects with these macros.</P>
|
||||
|
||||
<P>A library function that alters a value stored in memory assumes
|
||||
that the function accesses no other objects that overlap the
|
||||
object whose stored value it alters. You cannot depend on consistent
|
||||
behavior from a library function that accesses and alters the same
|
||||
storage via different arguments. The function
|
||||
<A HREF="string.html#memmove" tppabs="http://ccs.ucsd.edu/c/string.html#memmove"><CODE>memmove</CODE></A>
|
||||
is an explicit exception to this rule. Its arguments
|
||||
can point at objects that overlap.</P>
|
||||
|
||||
<P>An implementation has a set of
|
||||
<B><A NAME="reserved names">reserved names</A></B> that it
|
||||
can use for its own purposes. All the library names described in this
|
||||
document are, of course, reserved for the library. Don't define
|
||||
macros with the same names. Don't try to supply your own definition
|
||||
of a library function, unless this document explicitly says you can
|
||||
(only in C++). An unauthorized replacement may be successful on some
|
||||
implementations and not on others. Names that begin with
|
||||
two underscores, such as <CODE>__STDIO</CODE>, and names that
|
||||
begin with an underscore followed by an upper case letter, such as
|
||||
<CODE>_Entry</CODE>, can be used as macro names, whether or not
|
||||
a translation unit explicitly includes any standard headers.
|
||||
Names that begin with an underscore can be defined with external
|
||||
linkage. Avoid writing such names in a program
|
||||
that you wish to keep maximally portable.</P>
|
||||
|
||||
<P>Some library functions operate on
|
||||
<B><A NAME="C string">C strings</A></B>, or pointers to
|
||||
<A HREF="charset.html#null-terminated string" tppabs="http://ccs.ucsd.edu/c/charset.html#null-terminated string">null-terminated strings</A>.
|
||||
You designate a C string
|
||||
that can be altered by an argument expression that has type
|
||||
<I>pointer to char</I> (or type <I>array of char,</I> which converts to
|
||||
<I>pointer to char</I> in an argument expression).
|
||||
You designate a C string that cannot be altered by an argument
|
||||
expression that has type <I>pointer to const char</I> (or type
|
||||
<I>const array of char</I>).
|
||||
In any case, the value of the expression is
|
||||
the address of the first byte in an array object.
|
||||
The first successive element of the array that has a
|
||||
<A HREF="charset.html#null character" tppabs="http://ccs.ucsd.edu/c/charset.html#null character">null character</A>
|
||||
stored in it marks the end of the C string.</P>
|
||||
|
||||
<UL>
|
||||
<LI>A
|
||||
<B><A NAME="filename">filename</A></B> is a string
|
||||
whose contents meet the requirements
|
||||
of the target environment for naming files.
|
||||
|
||||
<LI>A
|
||||
<B><A NAME="multibyte string">multibyte string</A></B>
|
||||
is composed of zero or more
|
||||
<A HREF="charset.html#Multibyte Characters" tppabs="http://ccs.ucsd.edu/c/charset.html#Multibyte Characters">multibyte characters</A>,
|
||||
followed by a
|
||||
<A HREF="charset.html#null character" tppabs="http://ccs.ucsd.edu/c/charset.html#null character">null character</A>.
|
||||
|
||||
<LI>A
|
||||
<B><A NAME="wide-character string">wide-character string</A></B>
|
||||
is composed of zero or more
|
||||
<A HREF="charset.html#Wide-Character Encoding" tppabs="http://ccs.ucsd.edu/c/charset.html#Wide-Character Encoding">wide characters</A>
|
||||
(stored in an array of
|
||||
<A HREF="stddef.html#wchar_t" tppabs="http://ccs.ucsd.edu/c/stddef.html#wchar_t"><CODE>wchar_t</CODE></A>), followed by a
|
||||
<A HREF="charset.html#null wide character" tppabs="http://ccs.ucsd.edu/c/charset.html#null wide character">null wide character</A>.
|
||||
</UL>
|
||||
|
||||
<P>If an argument to a library function has a pointer type, then
|
||||
the value of the argument expression must be a valid address for an
|
||||
object of its type. This is true even if the library function has
|
||||
no need to access an object by using the pointer argument. An explicit
|
||||
exception is when the description of the library function spells out
|
||||
what happens when you use a null pointer.</P>
|
||||
|
||||
<P>Some examples are:</P>
|
||||
|
||||
<PRE>
|
||||
strcpy(s1, 0) <B>is INVALID</B>
|
||||
memcpy(s1, 0, 0) <B>is UNSAFE</B>
|
||||
realloc(0, 50) <B>is the same as malloc(50)</B></PRE>
|
||||
|
||||
<H2><A NAME="C Program Startup and Termination">
|
||||
Program Startup and Termination</A></H2>
|
||||
|
||||
<P>The target environment controls the execution of the program
|
||||
(in contrast to the translator part of the implementation, which prepares
|
||||
the parts of the program for execution). The target environment passes
|
||||
control to the program at
|
||||
<B><A NAME="program startup">program startup</A></B>
|
||||
by calling the function
|
||||
<B><A NAME="main"><CODE>main</CODE></A></B>
|
||||
that you define as part of the program.
|
||||
<B><A NAME="program arguments">Program arguments</A></B> are
|
||||
<A HREF="#C string">C strings</A>
|
||||
that the target environment provides, such as text from the
|
||||
<B><A NAME="command line">command line</A></B>
|
||||
that you type to invoke the program. If the program
|
||||
does not need to access program arguments, you can define <CODE>main</CODE>
|
||||
as:</P>
|
||||
|
||||
<PRE>
|
||||
extern int main(void)
|
||||
{ <I><body of main></I> }</PRE>
|
||||
|
||||
<P>If the program uses program arguments, you define <CODE>main</CODE>
|
||||
as:</P>
|
||||
|
||||
<PRE>
|
||||
extern int main(int argc, char **argv)
|
||||
{ <I><body of main></I> }</PRE>
|
||||
|
||||
<P>You can omit either or both of <CODE>extern int</CODE>, since
|
||||
these are the default storage class and type for a function
|
||||
definition. For program arguments:</P>
|
||||
|
||||
<UL>
|
||||
<LI><CODE>argc</CODE> is a value (always greater than zero) that specifies
|
||||
the number of program arguments.
|
||||
|
||||
<LI><CODE>argv[0]</CODE> designates the first element of an array of
|
||||
<A HREF="#C string">C strings</A>.
|
||||
<CODE>argv[argc]</CODE> designates the last element of the array, whose
|
||||
stored value is a null pointer.
|
||||
</UL>
|
||||
|
||||
<P>For example, if you invoke a program by typing:</P>
|
||||
|
||||
<PRE>
|
||||
echo hello</PRE>
|
||||
|
||||
<P>a target environment can call <CODE>main</CODE> with:</P>
|
||||
|
||||
<UL>
|
||||
<LI>The value 2 for <CODE>argc</CODE>.
|
||||
|
||||
<LI>The address of an array object containing <CODE>"echo"</CODE> stored
|
||||
in <CODE>argv[0]</CODE>.
|
||||
|
||||
<LI>The address of an array object containing <CODE>"hello"</CODE> stored
|
||||
in <CODE>argv[1]</CODE>.
|
||||
|
||||
<LI>A null pointer stored in <CODE>argv[2]</CODE>.
|
||||
</UL>
|
||||
|
||||
<P><CODE>argv[0]</CODE> is the name used to invoke the program. The target
|
||||
environment can replace this name with a
|
||||
<A NAME="null string">null string</A> (<CODE>""</CODE>).
|
||||
The program can alter the values stored in <CODE>argc</CODE>,
|
||||
in <CODE>argv</CODE>, and in the array objects
|
||||
whose addresses are stored in <CODE>argv</CODE>.</P>
|
||||
|
||||
<P>Before the target environment calls <CODE>main</CODE>, it stores the
|
||||
initial values you specify in all objects that have static duration.
|
||||
It also opens three files, controlled by the text-stream objects designated
|
||||
by the macros:</P>
|
||||
|
||||
<UL>
|
||||
<LI><B><A HREF="stdio.html#stdin" tppabs="http://ccs.ucsd.edu/c/stdio.html#stdin"><CODE>stdin</CODE></A></B> --
|
||||
for <B><A NAME="standard input">standard input</A></B>
|
||||
|
||||
<LI><B><A HREF="stdio.html#stdout" tppabs="http://ccs.ucsd.edu/c/stdio.html#stdout"><CODE>stdout</CODE></A></B> --
|
||||
for <B><A NAME="standard output">standard output</A></B>
|
||||
|
||||
<LI><B><A HREF="stdio.html#stderr" tppabs="http://ccs.ucsd.edu/c/stdio.html#stderr"><CODE>stderr</CODE></A></B> --
|
||||
for <B><A NAME="standard error">standard error</A></B> output
|
||||
</UL>
|
||||
|
||||
<P>If <CODE>main</CODE> returns to its caller, the target environment calls
|
||||
<A HREF="stdlib.html#exit" tppabs="http://ccs.ucsd.edu/c/stdlib.html#exit"><CODE>exit</CODE></A>
|
||||
with the value returned from <CODE>main</CODE> as the status argument to
|
||||
<A HREF="stdlib.html#exit" tppabs="http://ccs.ucsd.edu/c/stdlib.html#exit"><CODE>exit</CODE></A>. If the
|
||||
<A HREF="function.html#Return Statement" tppabs="http://ccs.ucsd.edu/c/function.html#Return Statement"><I>return</I> statement</A> that
|
||||
the program executes has no expression, the status argument is undefined.
|
||||
This is the case if the program executes the implied
|
||||
<A HREF="function.html#Return Statement" tppabs="http://ccs.ucsd.edu/c/function.html#Return Statement"><I>return</I> statement</A>
|
||||
at the end of the function definition.</P>
|
||||
|
||||
<P>You can also call
|
||||
<A HREF="stdlib.html#exit" tppabs="http://ccs.ucsd.edu/c/stdlib.html#exit"><CODE>exit</CODE></A>
|
||||
directly from any expression within the program. In both cases,
|
||||
<A HREF="stdlib.html#exit" tppabs="http://ccs.ucsd.edu/c/stdlib.html#exit"><CODE>exit</CODE></A>
|
||||
calls all functions registered with
|
||||
<A HREF="stdlib.html#atexit" tppabs="http://ccs.ucsd.edu/c/stdlib.html#atexit"><CODE>atexit</CODE></A>
|
||||
in reverse order of registry and then begins
|
||||
<B><A NAME="program termination">program termination</A></B>.
|
||||
At program termination, the target environment closes
|
||||
all open files, removes any temporary files that you created by calling
|
||||
<A HREF="stdio.html#tmpfile" tppabs="http://ccs.ucsd.edu/c/stdio.html#tmpfile"><CODE>tmpfile</CODE></A>,
|
||||
and then returns control to the invoker, using the
|
||||
status argument value to determine the termination status to report
|
||||
for the program.</P>
|
||||
|
||||
<P>The program can terminate abnormally by calling
|
||||
<A HREF="stdlib.html#abort" tppabs="http://ccs.ucsd.edu/c/stdlib.html#abort"><CODE>abort</CODE></A>,
|
||||
for example. Each implementation defines whether it closes files,
|
||||
whether it removes temporary files, and what termination status it
|
||||
reports when a program terminates abnormally.</P>
|
||||
|
||||
<HR>
|
||||
<P>See also the
|
||||
<B><A HREF="index.html#Table of Contents" tppabs="http://ccs.ucsd.edu/c/index.html#Table of Contents">Table of Contents</A></B> and the
|
||||
<B><A HREF="_index.html" tppabs="http://ccs.ucsd.edu/c/_index.html">Index</A></B>.</P>
|
||||
|
||||
<P><I>
|
||||
<A HREF="crit_pb.html" tppabs="http://ccs.ucsd.edu/c/crit_pb.html">Copyright</A> © 1989-1996
|
||||
by P.J. Plauger and Jim Brodie. All rights reserved.</I></P>
|
||||
|
||||
</BODY></HTML>
|
||||
|
||||
417
study/Ref-docs/C/lib_prin.html
Normal file
@@ -0,0 +1,417 @@
|
||||
<HTML><HEAD><TITLE>Formatted Output</TITLE></HEAD><BODY BGCOLOR="#FFFFFF">
|
||||
|
||||
<H1><A NAME="Formatted Output">Formatted Output</A></H1><HR>
|
||||
|
||||
<P><B><A HREF="#Print Formats">Print Formats</A>
|
||||
· <A HREF="#Print Functions">Print Functions</A>
|
||||
· <A HREF="#Print Conversion Specifiers">Print Conversion
|
||||
Specifiers</A>
|
||||
</B></P>
|
||||
<HR>
|
||||
|
||||
<P>Several library functions help you convert data values from
|
||||
encoded internal representations to text sequences that are
|
||||
generally readable by people. You provide a
|
||||
<A HREF="#format string">format string</A> as the value of the
|
||||
<CODE>format</CODE> argument to each of these functions, hence
|
||||
the term <B>formatted output</B>. The functions fall
|
||||
into two categories:</P>
|
||||
|
||||
<UL>
|
||||
<LI>The <B><A NAME="byte print functions">byte print functions</A></B>
|
||||
(declared in
|
||||
<A HREF="stdio.html#<stdio.h>" tppabs="http://ccs.ucsd.edu/c/stdio.html#<stdio.h>"><CODE><stdio.h></CODE></A>)
|
||||
convert internal representations to sequences of type <I>char,</I>
|
||||
and help you compose such sequences for display:
|
||||
<A HREF="stdio.html#fprintf" tppabs="http://ccs.ucsd.edu/c/stdio.html#fprintf">fprintf</A>,
|
||||
<A HREF="stdio.html#printf" tppabs="http://ccs.ucsd.edu/c/stdio.html#printf">printf</A>,
|
||||
<A HREF="stdio.html#sprintf" tppabs="http://ccs.ucsd.edu/c/stdio.html#sprintf">sprintf</A>,
|
||||
<A HREF="stdio.html#vfprintf" tppabs="http://ccs.ucsd.edu/c/stdio.html#vfprintf">vfprintf</A>,
|
||||
<A HREF="stdio.html#vprintf" tppabs="http://ccs.ucsd.edu/c/stdio.html#vprintf">vprintf</A>, and
|
||||
<A HREF="stdio.html#vsprintf" tppabs="http://ccs.ucsd.edu/c/stdio.html#vsprintf">vsprintf</A>.
|
||||
For these function, a format string is a
|
||||
<A HREF="lib_over.html#multibyte string" tppabs="http://ccs.ucsd.edu/c/lib_over.html#multibyte string">multibyte string</A>
|
||||
that begins and ends in the
|
||||
<A HREF="charset.html#initial shift state" tppabs="http://ccs.ucsd.edu/c/charset.html#initial shift state">initial shift state</A>.
|
||||
|
||||
<LI>The <B><A NAME="wide print functions">wide print functions</A></B>
|
||||
(declared in
|
||||
<A HREF="wchar.html#<wchar.h>" tppabs="http://ccs.ucsd.edu/c/wchar.html#<wchar.h>"><CODE><wchar.h></CODE></A>
|
||||
and hence added with
|
||||
<B><A HREF="lib_over.html#Amendment 1" tppabs="http://ccs.ucsd.edu/c/lib_over.html#Amendment 1">Amendment 1</A></B>)
|
||||
convert internal representations to sequences of type
|
||||
<A HREF="stddef.html#wchar_t" tppabs="http://ccs.ucsd.edu/c/stddef.html#wchar_t"><CODE>wchar_t</CODE></A>,
|
||||
and help you compose such sequences for display:
|
||||
<A HREF="wchar.html#fwprintf" tppabs="http://ccs.ucsd.edu/c/wchar.html#fwprintf">fwprintf</A>,
|
||||
<A HREF="wchar.html#swprintf" tppabs="http://ccs.ucsd.edu/c/wchar.html#swprintf">swprintf</A>,
|
||||
<A HREF="wchar.html#wprintf" tppabs="http://ccs.ucsd.edu/c/wchar.html#wprintf">wprintf</A>,
|
||||
<A HREF="wchar.html#vfwprintf" tppabs="http://ccs.ucsd.edu/c/wchar.html#vfwprintf">vfwprintf</A>,
|
||||
<A HREF="wchar.html#vswprintf" tppabs="http://ccs.ucsd.edu/c/wchar.html#vswprintf">vswprintf</A>, and
|
||||
<A HREF="wchar.html#vwprintf" tppabs="http://ccs.ucsd.edu/c/wchar.html#vwprintf">vwprintf</A>.
|
||||
For these functions, a format string is a
|
||||
<A HREF="lib_over.html#wide-character string" tppabs="http://ccs.ucsd.edu/c/lib_over.html#wide-character string">wide-character string</A>.
|
||||
In the descriptions that follow, a wide character <CODE>wc</CODE>
|
||||
from a format string or a stream is compared to a specific (byte)
|
||||
character <CODE>c</CODE> as if by evaluating the expression
|
||||
<CODE><A HREF="wchar.html#wctob" tppabs="http://ccs.ucsd.edu/c/wchar.html#wctob">wctob</A>(wc) == c</CODE>.
|
||||
</UL>
|
||||
|
||||
<H2><A NAME="Print Formats">Print Formats</A></H2>
|
||||
|
||||
<P>A <B><A NAME="format string">format string</A></B> has the same
|
||||
syntax for both the print functions and the
|
||||
<A HREF="lib_scan.html#Formatted Input" tppabs="http://ccs.ucsd.edu/c/lib_scan.html#Formatted Input">scan functions</A>:</P>
|
||||
|
||||
<P><IMG SRC="format.gif" tppabs="http://ccs.ucsd.edu/c/gif/format.gif"></P>
|
||||
|
||||
<P>A format string consists of zero or more
|
||||
<B><A NAME="conversion specification">conversion specifications</A></B>
|
||||
interspersed with literal text and
|
||||
<B><A NAME="white space">white space</A></B>.
|
||||
White space is a sequence of one or more
|
||||
characters <CODE>c</CODE> for which the call
|
||||
<CODE><A HREF="ctype.html#isspace" tppabs="http://ccs.ucsd.edu/c/ctype.html#isspace">isspace</A>(c)</CODE> returns nonzero.
|
||||
(The characters defined as white space can change when you change the
|
||||
<A HREF="locale.html#LC_CTYPE" tppabs="http://ccs.ucsd.edu/c/locale.html#LC_CTYPE"><CODE>LC_CTYPE</CODE></A>
|
||||
<A HREF="locale.html#locale category" tppabs="http://ccs.ucsd.edu/c/locale.html#locale category">locale category</A>.)
|
||||
For the print functions, a conversion specification is one of the
|
||||
<A HREF="#print conversion specification">
|
||||
print conversion specifications</A> described below.</P>
|
||||
|
||||
<P>A print function scans the format string once from beginning
|
||||
to end to determine what conversions to perform. Every print
|
||||
function accepts a
|
||||
<A HREF="stdarg.html#varying number of arguments" tppabs="http://ccs.ucsd.edu/c/stdarg.html#varying number of arguments">varying number
|
||||
of arguments</A>, either directly or under control of an argument of type
|
||||
<A HREF="stdarg.html#va_list" tppabs="http://ccs.ucsd.edu/c/stdarg.html#va_list"><CODE>va_list</CODE></A>.
|
||||
Some print conversion specifications
|
||||
in the format string use the next argument in the list.
|
||||
A print function uses each successive argument no more than
|
||||
once. Trailing arguments can be left unused.</P>
|
||||
|
||||
<P>In the description that follows:</P>
|
||||
|
||||
<UL>
|
||||
<LI><B><A NAME="integer conversions">integer conversions</A></B> are the
|
||||
<B><A NAME="conversion specifiers">conversion specifiers</A></B> that
|
||||
end in <CODE>d</CODE>, <CODE>i</CODE>, <CODE>o</CODE>, <CODE>u</CODE>,
|
||||
<CODE>x</CODE>, or <CODE>X</CODE>
|
||||
|
||||
<LI><B><A NAME="floating-point conversions">
|
||||
floating-point conversions</A></B>
|
||||
are the conversion specifiers
|
||||
that end in <CODE>e</CODE>, <CODE>E</CODE>, <CODE>f</CODE>,
|
||||
<CODE>g</CODE>, or <CODE>G</CODE>
|
||||
</UL>
|
||||
|
||||
<H2><A NAME="Print Functions">Print Functions</A></H2>
|
||||
|
||||
<P>For the print functions, literal text or
|
||||
<A HREF="#white space">white space</A> in a format
|
||||
string generates characters that match the characters in the format
|
||||
string. A
|
||||
<B><A NAME="print conversion specification">
|
||||
print conversion specification</A></B> typically generates characters
|
||||
by converting the next argument value to a corresponding text sequence.
|
||||
A print conversion specification has the format:</P>
|
||||
|
||||
<P><IMG SRC="print.gif" tppabs="http://ccs.ucsd.edu/c/gif/print.gif"></P>
|
||||
|
||||
<P>Following the percent character (<B><CODE>%</CODE></B>)
|
||||
in the format string, you can write zero or more
|
||||
<B><A NAME="format flag">format flags</A></B>:</P>
|
||||
|
||||
<UL>
|
||||
<LI><B><CODE>-</CODE></B>
|
||||
-- to left-justify a conversion
|
||||
</UL>
|
||||
|
||||
<UL>
|
||||
<LI><B><CODE>+</CODE></B>
|
||||
-- to generate a plus sign for signed values that
|
||||
are positive
|
||||
|
||||
<LI><B><CODE><I>space</I></CODE></B>
|
||||
-- to generate a <CODE><I>space</I></CODE> for signed values
|
||||
that have neither a plus nor a minus sign
|
||||
|
||||
<LI><B><CODE>#</CODE></B>
|
||||
-- to prefix <CODE>0</CODE> on an <CODE>o</CODE> conversion,
|
||||
to prefix <CODE>0x</CODE> on an <CODE>x</CODE> conversion,
|
||||
to prefix <CODE>0X</CODE> on an <CODE>X</CODE> conversion,
|
||||
or to generate a decimal point and fraction
|
||||
digits that are otherwise suppressed on a floating-point conversion
|
||||
|
||||
<LI><B><CODE>0</CODE></B>
|
||||
-- to pad a conversion with leading zeros after
|
||||
any sign or prefix, in the absence of a minus (<CODE>-</CODE>)
|
||||
format flag or a specified precision
|
||||
</UL>
|
||||
|
||||
<P>Following any format flags, you can write a
|
||||
<B><A NAME="print field width">field width</A></B> that
|
||||
specifies the minimum number of characters to generate for the conversion.
|
||||
Unless altered by a format flag,
|
||||
the default behavior is to pad a short conversion
|
||||
on the left with <CODE><I>space</I></CODE> characters.
|
||||
If you write an asterisk (<B><CODE>*</CODE></B>)
|
||||
instead of a decimal number for a field width, then a print
|
||||
function takes the value of the next argument (which must be of type
|
||||
<I>int</I>) as the field width. If the argument value is negative,
|
||||
it supplies a <CODE>-</CODE> format flag
|
||||
and its magnitude is the field width.</P>
|
||||
|
||||
<P>Following any field width, you can write a dot (<B><CODE>.</CODE></B>)
|
||||
followed by a
|
||||
<B><A NAME="precision">precision</A></B>
|
||||
that specifies one of the following:
|
||||
the minimum number of digits to generate on an integer conversion;
|
||||
the number of fraction digits to generate on an <CODE>e</CODE>,
|
||||
<CODE>E</CODE>, or <CODE>f</CODE> conversion;
|
||||
the maximum number of significant digits to generate
|
||||
on a <CODE>g</CODE> or <CODE>G</CODE> conversion; or the maximum number
|
||||
of characters to generate from a
|
||||
<A HREF="lib_over.html#C string" tppabs="http://ccs.ucsd.edu/c/lib_over.html#C string">C string</A>
|
||||
on an <CODE>s</CODE> conversion.</P>
|
||||
|
||||
<P>If you write an <B><CODE>*</CODE></B> instead of
|
||||
a decimal number for a precision,
|
||||
a print function takes the value of the next argument (which must
|
||||
be of type <I>int</I>) as the precision. If the argument value is
|
||||
negative, the default precision applies. If you do not write either
|
||||
an <CODE>*</CODE> or a decimal number following the dot, the precision
|
||||
is zero.</P>
|
||||
|
||||
<H2><A NAME="Print Conversion Specifiers">
|
||||
Print Conversion Specifiers</A></H2>
|
||||
|
||||
<P>Following any
|
||||
<A HREF="#precision">precision</A>,
|
||||
you must write a one-character <B>print conversion specifier</B>,
|
||||
possibly preceded by a one-character qualifier.
|
||||
Each combination determines the type required of the
|
||||
next argument (if any) and how the library functions alter the argument
|
||||
value before converting it to a text sequence.
|
||||
The <A HREF="#integer conversions">integer</A> and
|
||||
<A HREF="#floating-point conversions">
|
||||
floating-point conversions</A> also determine
|
||||
what base to use for the text representation.
|
||||
If a conversion specifier requires a precision <I>p</I> and you do
|
||||
not provide one in the format, then the conversion specifier chooses
|
||||
a default value for the precision. The following table
|
||||
lists all defined combinations and their properties.</P>
|
||||
|
||||
<PRE><B>
|
||||
Conversion Argument Converted Default
|
||||
Specifier Type Value Base Precision</B>
|
||||
%c int x (unsigned char)x
|
||||
%lc wint_t x wchar_t a[2] = {x}
|
||||
%d int x (int)x 10 1
|
||||
%hd int x (short)x 10 1
|
||||
%ld long x (long)x 10 1
|
||||
%e double x (double)x 10 6
|
||||
%Le long double x (long double)x 10 6
|
||||
%E double x (double)x 10 6
|
||||
%E long double x (long double)x 10 6
|
||||
%f double x (double)x 10 6
|
||||
%Lf long double x (long double)x 10 6
|
||||
%g double x (double)x 10 6
|
||||
%Lg long double x (long double)x 10 6
|
||||
%G double x (double)x 10 6
|
||||
%LG long double x (long double)x 10 6
|
||||
%i int x (int)x 10 1
|
||||
%hi int x (short)x 10 1
|
||||
%li long x (long)x 10 1
|
||||
%n int *x
|
||||
%hn short *x
|
||||
%ln long *x
|
||||
%o int x (unsigned int)x 8 1
|
||||
%ho int x (unsigned short)x 8 1
|
||||
%lo long x (unsigned long)x 8 1
|
||||
%p void *x (void *)x
|
||||
%s char x[] x[0]... <B>large</B>
|
||||
%ls wchar_t x[] x[0]... <B>large</B>
|
||||
%u int x (unsigned int)x 10 1
|
||||
%hu int x (unsigned short)x 10 1
|
||||
%lu long x (unsigned long)x 10 1
|
||||
%x int x (unsigned int)x 16 1
|
||||
%hx int x (unsigned short)x 16 1
|
||||
%lx long x (unsigned long)x 16 1
|
||||
%X int x (unsigned int)x 16 1
|
||||
%hX int x (unsigned short)x 16 1
|
||||
%lX long x (unsigned long)x 16 1
|
||||
%% <B>none</B> '%'</PRE>
|
||||
|
||||
<P>The print conversion specifier determines any behavior not summarized
|
||||
in this table. In the following descriptions, <I>p</I> is the precision.
|
||||
Examples follow each of the print conversion specifiers.
|
||||
A single conversion can generate up to 509 characters.</P>
|
||||
|
||||
<P>You write <B><A NAME="%c"><CODE>%c</CODE></A></B>
|
||||
to generate a single character from the converted
|
||||
value. For a
|
||||
<A HREF="lib_file.html#wide stream" tppabs="http://ccs.ucsd.edu/c/lib_file.html#wide stream">wide stream</A>,
|
||||
conversion of the character <CODE>x</CODE> occurs as if by calling
|
||||
<CODE><A HREF="wchar.html#btowc" tppabs="http://ccs.ucsd.edu/c/wchar.html#btowc">btowc</A>(x)</CODE>. </P>
|
||||
|
||||
<PRE>
|
||||
printf("%c", 'a') <B>generates a</B>
|
||||
printf("<%3c|%-3c>", 'a', 'b') <B>generates < a|b ></B>
|
||||
wprintf(L"%c", 'a') <B>generates (wide) btowc(a)</B></PRE>
|
||||
|
||||
<P>You write <B><A NAME="%lc"><CODE>%lc</CODE></A></B>
|
||||
to generate a single character from the converted value.
|
||||
Conversion of the character <CODE>x</CODE> occurs as if
|
||||
it is followed by a null character in an array of two elements of type
|
||||
<A HREF="stddef.html#wchar_t" tppabs="http://ccs.ucsd.edu/c/stddef.html#wchar_t"><CODE>wchar_t</CODE></A>
|
||||
converted by the conversion specification
|
||||
<A HREF="#%ls"><CODE>ls</CODE></A>.</P>
|
||||
|
||||
<PRE>
|
||||
printf("%lc", L'a') <B>generates a</B>
|
||||
wprintf(L"lc", L'a') <B>generates (wide) L'a'</B></PRE>
|
||||
|
||||
<P>You write <B><A NAME="%d"><CODE>%d</CODE></A></B>,
|
||||
<B><A NAME="%i"><CODE>%i</CODE></A></B>,
|
||||
<B><A NAME="%o"><CODE>%o</CODE></A></B>,
|
||||
<B><A NAME="%u"><CODE>%u</CODE></A></B>,
|
||||
<B><A NAME="%x"><CODE>%x</CODE></A></B>, or
|
||||
<B><A NAME="%X"><CODE>%X</CODE></A></B> to generate
|
||||
a possibly signed integer representation. <CODE>%d</CODE> or <CODE>%i</CODE>
|
||||
specifies signed decimal representation, <CODE>%o</CODE>
|
||||
unsigned octal, <CODE>%u</CODE> unsigned decimal,
|
||||
<CODE>%x</CODE> unsigned hexadecimal using the digits <CODE>0-9</CODE>
|
||||
and <CODE>a-f</CODE>, and <CODE>%X</CODE> unsigned
|
||||
hexadecimal using the digits <CODE>0-9</CODE> and <CODE>A-F</CODE>.
|
||||
The conversion generates at least <I>p</I> digits
|
||||
to represent the converted value. If <I>p</I> is zero,
|
||||
a converted value of zero generates no digits.</P>
|
||||
|
||||
<PRE>
|
||||
printf("%d %o %x", 31, 31, 31) <B>generates 31 37 1f</B>
|
||||
printf("%hu", 0xffff) <B>generates 65535</B>
|
||||
printf("%#X %+d", 31, 31) <B>generates 0X1F +31</B></PRE>
|
||||
|
||||
<P>You write <B><A NAME="%e"><CODE>%e</CODE></A></B> or
|
||||
<B><A NAME="%E"><CODE>%E</CODE></A></B> to generate a signed fractional
|
||||
representation with an exponent. The generated text takes the form
|
||||
<I>±d.dddE±dd</I>, where <I>±</I> is either a plus or
|
||||
minus sign, <I>d</I> is a decimal digit, the dot (<I>.</I>)
|
||||
is the decimal point for the current
|
||||
<A HREF="locale.html#locale" tppabs="http://ccs.ucsd.edu/c/locale.html#locale">locale</A>,
|
||||
and <I>E</I> is either <CODE>e</CODE> (for <CODE>%e</CODE> conversion)
|
||||
or <CODE>E</CODE> (for <CODE>%E</CODE> conversion).
|
||||
The generated text has one integer digit,
|
||||
a decimal point if <I>p</I> is nonzero or if you specify the <CODE>#</CODE>
|
||||
format flag, <I>p</I> fraction digits, and at least two exponent digits.
|
||||
The result is rounded. The value zero has a zero exponent.</P>
|
||||
|
||||
<PRE>
|
||||
printf("%e", 31.4) <B>generates 3.140000e+01</B>
|
||||
printf("%.2E", 31.4) <B>generates 3.14E+01</B></PRE>
|
||||
|
||||
<P>You write <B><A NAME="%f"><CODE>%f</CODE></A></B>
|
||||
to generate a signed fractional representation
|
||||
with no exponent. The generated text takes the form <I>±d.ddd</I>,
|
||||
where <I>±</I> is either a plus or minus sign,
|
||||
<I>d</I> is a decimal digit, and the dot (<I>.</I>)
|
||||
is the decimal point for the current
|
||||
<A HREF="locale.html#locale" tppabs="http://ccs.ucsd.edu/c/locale.html#locale">locale</A>.
|
||||
The generated text has at least one integer digit,
|
||||
a decimal point if <I>p</I> is nonzero or if you specify
|
||||
the <CODE>#</CODE> format flag, and <I>p</I> fraction digits.
|
||||
The result is rounded.</P>
|
||||
|
||||
<PRE>
|
||||
printf("%f", 31.4) <B>generates 31.400000</B>
|
||||
printf("%.0f %#.0f", 31.0, 31.0) <B>generates 31 31.</B></PRE>
|
||||
|
||||
<P>You write <B><A NAME="%g"><CODE>%g</CODE></A></B> or
|
||||
<B><A NAME="%G"><CODE>%G</CODE></A></B> to generate a signed fractional
|
||||
representation with or without an exponent, as appropriate.
|
||||
For <CODE>%g</CODE> conversion, the generated text
|
||||
takes the same form as either <CODE>%e</CODE>
|
||||
or <CODE>%f</CODE> conversion. For <CODE>%G</CODE> conversion,
|
||||
it takes the same form as either
|
||||
<CODE>%E</CODE> or <CODE>%f</CODE> conversion.
|
||||
The precision <I>p</I> specifies the number
|
||||
of significant digits generated. (If <I>p</I> is zero, it is changed
|
||||
to 1.) If <CODE>%e</CODE> conversion would yield an exponent in the range
|
||||
[-4, <I>p</I>), then <CODE>%f</CODE> conversion occurs instead.
|
||||
The generated text has no trailing zeros
|
||||
in any fraction and has a decimal point
|
||||
only if there are nonzero fraction digits, unless you specify the
|
||||
<CODE>#</CODE> format flag.</P>
|
||||
|
||||
<PRE>
|
||||
printf("%.6g", 31.4) <B>generates 31.4</B>
|
||||
printf("%.1g", 31.4) <B>generates 3.14e+01</B></PRE>
|
||||
|
||||
<P>You write <B><A NAME="%n"><CODE>%n</CODE></A></B>
|
||||
to store the number of characters generated
|
||||
(up to this point in the format) in the object of type <I>int</I>
|
||||
whose address is the value of the next successive argument.</P>
|
||||
|
||||
<PRE>
|
||||
printf("abc%n", &x) <B>stores 3</B></PRE>
|
||||
|
||||
<P>You write <B><A NAME="%p"><CODE>%p</CODE></A></B>
|
||||
to generate an external representation of a <I>pointer to void.</I>
|
||||
The conversion is implementation defined.</P>
|
||||
|
||||
<PRE>
|
||||
printf("%p", (void *)&x) <B>generates, e.g. F4C0</B></PRE>
|
||||
|
||||
<P>You write <B><A NAME="%s"><CODE>%s</CODE></A></B>
|
||||
to generate a sequence of characters from
|
||||
the values stored in the argument
|
||||
<A HREF="lib_over.html#C string" tppabs="http://ccs.ucsd.edu/c/lib_over.html#C string">C string</A>. For a
|
||||
<A HREF="lib_file.html#wide stream" tppabs="http://ccs.ucsd.edu/c/lib_file.html#wide stream">wide stream</A>, conversion
|
||||
occurs as if by repeatedly calling
|
||||
<A HREF="wchar.html#mbrtowc" tppabs="http://ccs.ucsd.edu/c/wchar.html#mbrtowc"><CODE>mbrtowc</CODE></A>,
|
||||
beginning in the
|
||||
<A HREF="charset.html#initial conversion state" tppabs="http://ccs.ucsd.edu/c/charset.html#initial conversion state">
|
||||
initial conversion state</A>.
|
||||
The conversion generates no more than <I>p</I> characters,
|
||||
up to but not including the terminating null character.</P>
|
||||
|
||||
<PRE>
|
||||
printf("%s", "hello") <B>generates hello</B>
|
||||
printf("%.2s", "hello") <B>generates he</B>
|
||||
wprintf(L"%s", "hello") <B>generates (wide) hello</B></PRE>
|
||||
|
||||
<P>You write <B><A NAME="%ls"><CODE>%ls</CODE></A></B>
|
||||
to generate a sequence of characters from
|
||||
the values stored in the argument
|
||||
<A HREF="lib_over.html#wide-character string" tppabs="http://ccs.ucsd.edu/c/lib_over.html#wide-character string">wide-character string</A>.
|
||||
For a <A HREF="lib_file.html#byte stream" tppabs="http://ccs.ucsd.edu/c/lib_file.html#byte stream">byte stream</A>,
|
||||
conversion occurs as if by repeatedly calling
|
||||
<A HREF="wchar.html#wcrtomb" tppabs="http://ccs.ucsd.edu/c/wchar.html#wcrtomb"><CODE>wcrtomb</CODE></A>, beginning in the
|
||||
<A HREF="charset.html#initial conversion state" tppabs="http://ccs.ucsd.edu/c/charset.html#initial conversion state">
|
||||
initial conversion state</A>,
|
||||
so long as complete multibyte characters can be generated.
|
||||
The conversion generates no more than
|
||||
<I>p</I> characters, up to but not including the terminating null
|
||||
character.</P>
|
||||
|
||||
<PRE>
|
||||
printf("%ls", L"hello") <B>generates hello</B>
|
||||
wprintf(L"%.2s", L"hello") <B>generates (wide) he</B></PRE>
|
||||
|
||||
<P>You write <B><A NAME="%%"><CODE>%%</CODE></A></B> to generate
|
||||
the percent character (<CODE>%</CODE>).</P>
|
||||
|
||||
<PRE>
|
||||
printf("%%") <B>generates %</B></PRE>
|
||||
|
||||
<HR>
|
||||
<P>See also the
|
||||
<B><A HREF="index.html#Table of Contents" tppabs="http://ccs.ucsd.edu/c/index.html#Table of Contents">Table of Contents</A></B> and the
|
||||
<B><A HREF="_index.html" tppabs="http://ccs.ucsd.edu/c/_index.html">Index</A></B>.</P>
|
||||
|
||||
<P><I>
|
||||
<A HREF="crit_pb.html" tppabs="http://ccs.ucsd.edu/c/crit_pb.html">Copyright</A> © 1989-1996
|
||||
by P.J. Plauger and Jim Brodie. All rights reserved.</I></P>
|
||||
|
||||
</BODY></HTML>
|
||||
|
||||
427
study/Ref-docs/C/lib_scan.html
Normal file
@@ -0,0 +1,427 @@
|
||||
<HTML><HEAD><TITLE>Formatted Input</TITLE></HEAD><BODY BGCOLOR="#FFFFFF">
|
||||
|
||||
<H1><A NAME="Formatted Input">Formatted Input</A></H1><HR>
|
||||
|
||||
<P><B><A HREF="#Scan Formats">Scan Formats</A>
|
||||
· <A HREF="#Scan Functions">Scan Functions</A>
|
||||
· <A HREF="#Scan Conversion Specifiers">Scan Conversion Specifiers</A>
|
||||
</B></P>
|
||||
<HR>
|
||||
|
||||
<P>Several library functions help you convert data values from
|
||||
text sequences that are generally readable by people to
|
||||
encoded internal representations. You provide a
|
||||
<A HREF="lib_prin.html#format string" tppabs="http://ccs.ucsd.edu/c/lib_prin.html#format string">format string</A> as the value of the
|
||||
<CODE>format</CODE> argument to each of these functions, hence
|
||||
the term <B>formatted input</B>. The functions fall
|
||||
into two categories:</P>
|
||||
|
||||
<UL>
|
||||
<LI>The <B><A NAME="byte scan functions">byte scan functions</A></B>
|
||||
(declared in
|
||||
<A HREF="stdio.html#<stdio.h>" tppabs="http://ccs.ucsd.edu/c/stdio.html#<stdio.h>"><CODE><stdio.h></CODE></A>)
|
||||
convert sequences of type <I>char</I> to internal representations,
|
||||
and help you scan such sequences that you read:
|
||||
<A HREF="stdio.html#fscanf" tppabs="http://ccs.ucsd.edu/c/stdio.html#fscanf">fscanf</A>,
|
||||
<A HREF="stdio.html#scanf" tppabs="http://ccs.ucsd.edu/c/stdio.html#scanf">scanf</A>, and
|
||||
<A HREF="stdio.html#sscanf" tppabs="http://ccs.ucsd.edu/c/stdio.html#sscanf">sscanf</A>.
|
||||
For these function, a format string is a
|
||||
<A HREF="lib_over.html#multibyte string" tppabs="http://ccs.ucsd.edu/c/lib_over.html#multibyte string">multibyte string</A>
|
||||
that begins and ends in the
|
||||
<A HREF="charset.html#initial shift state" tppabs="http://ccs.ucsd.edu/c/charset.html#initial shift state">initial shift state</A>.
|
||||
|
||||
<LI>The <B><A NAME="wide scan functions">wide scan functions</A></B>
|
||||
(declared in
|
||||
<A HREF="wchar.html#<wchar.h>" tppabs="http://ccs.ucsd.edu/c/wchar.html#<wchar.h>"><CODE><wchar.h></CODE></A>
|
||||
and hence added with
|
||||
<B><A HREF="lib_over.html#Amendment 1" tppabs="http://ccs.ucsd.edu/c/lib_over.html#Amendment 1">Amendment 1</A></B>)
|
||||
convert sequences of type
|
||||
<A HREF="stddef.html#wchar_t" tppabs="http://ccs.ucsd.edu/c/stddef.html#wchar_t"><CODE>wchar_t</CODE></A>,
|
||||
to internal representations,
|
||||
and help you scan such sequences that you read:
|
||||
<A HREF="wchar.html#fwscanf" tppabs="http://ccs.ucsd.edu/c/wchar.html#fwscanf">fwscanf</A>,
|
||||
<A HREF="wchar.html#wscanf" tppabs="http://ccs.ucsd.edu/c/wchar.html#wscanf">wscanf</A> and
|
||||
<A HREF="wchar.html#swscanf" tppabs="http://ccs.ucsd.edu/c/wchar.html#swscanf">swscanf</A>.
|
||||
For these functions, a format string is a
|
||||
<A HREF="lib_over.html#wide-character string" tppabs="http://ccs.ucsd.edu/c/lib_over.html#wide-character string">wide-character string</A>.
|
||||
In the descriptions that follow, a wide character <CODE>wc</CODE>
|
||||
from a format string or a stream is compared to a specific (byte)
|
||||
character <CODE>c</CODE> as if by evaluating the expression
|
||||
<CODE><A HREF="wchar.html#wctob" tppabs="http://ccs.ucsd.edu/c/wchar.html#wctob">wctob</A>(wc) == c</CODE>.
|
||||
</UL>
|
||||
|
||||
<H2><A NAME="Scan Formats">Scan Formats</A></H2>
|
||||
|
||||
<P>A format string has the same general
|
||||
<B><A HREF="lib_prin.html#format string" tppabs="http://ccs.ucsd.edu/c/lib_prin.html#format string">syntax</A></B>
|
||||
for the scan functions as for the
|
||||
<A HREF="lib_prin.html#Formatted Output" tppabs="http://ccs.ucsd.edu/c/lib_prin.html#Formatted Output">print functions</A>:
|
||||
zero or more
|
||||
<B><A HREF="lib_prin.html#conversion specification" tppabs="http://ccs.ucsd.edu/c/lib_prin.html#conversion specification">
|
||||
conversion specifications</A></B>,
|
||||
interspersed with literal text and
|
||||
<B><A HREF="lib_prin.html#white space" tppabs="http://ccs.ucsd.edu/c/lib_prin.html#white space">white space</A></B>.
|
||||
For the scan functions, however, a conversion specification is one of the
|
||||
<A HREF="#scan conversion specification">
|
||||
scan conversion specifications</A> described below.</P>
|
||||
|
||||
<P>A scan function scans the format string once from beginning
|
||||
to end to determine what conversions to perform. Every scan
|
||||
function accepts a
|
||||
<A HREF="stdarg.html#varying number of arguments" tppabs="http://ccs.ucsd.edu/c/stdarg.html#varying number of arguments">varying number
|
||||
of arguments</A>, either directly or under control of an argument of type
|
||||
<A HREF="stdarg.html#va_list" tppabs="http://ccs.ucsd.edu/c/stdarg.html#va_list"><CODE>va_list</CODE></A>.
|
||||
Some scan conversion specifications
|
||||
in the format string use the next argument in the list.
|
||||
A scan function uses each successive argument no more than
|
||||
once. Trailing arguments can be left unused.</P>
|
||||
|
||||
<P>In the description that follows, the
|
||||
<A HREF="lib_prin.html#integer conversions" tppabs="http://ccs.ucsd.edu/c/lib_prin.html#integer conversions">integer conversions</A> and
|
||||
<A HREF="lib_prin.html#floating-point conversions" tppabs="http://ccs.ucsd.edu/c/lib_prin.html#floating-point conversions">
|
||||
floating-point conversions</A> are the same as for the
|
||||
<A HREF="lib_prin.html#Formatted Output" tppabs="http://ccs.ucsd.edu/c/lib_prin.html#Formatted Output">print functions</A>.</P>
|
||||
|
||||
<H2><A NAME="Scan Functions">Scan Functions</A></H2>
|
||||
|
||||
<P>For the scan functions, literal text in a format string must
|
||||
match the next characters to scan in the input text.
|
||||
<A HREF="lib_prin.html#white space" tppabs="http://ccs.ucsd.edu/c/lib_prin.html#white space">White space</A> in
|
||||
a format string must match the longest possible sequence of the next
|
||||
zero or more white-space characters in the input. Except for the
|
||||
<A HREF="#Scan Conversion Specifiers">
|
||||
scan conversion specifier</A>
|
||||
<A HREF="#%n"><CODE>%n</CODE></A>
|
||||
(which consumes no input), each
|
||||
<B><A NAME="scan conversion specification">
|
||||
scan conversion specification</A></B>
|
||||
determines a pattern that one or more of the next characters in the
|
||||
input must match. And except for the
|
||||
<A HREF="#Scan Conversion Specifiers">
|
||||
scan conversion specifiers
|
||||
<A HREF="#%c"><CODE>c</CODE></A>,
|
||||
<A HREF="#%n"><CODE>n</CODE></A>, and
|
||||
<A HREF="#%["><CODE>[</CODE></A>,
|
||||
every match begins by skipping any
|
||||
<A HREF="lib_prin.html#%n" tppabs="http://ccs.ucsd.edu/c/lib_prin.html#%n">white space</A> characters in the input.</P>
|
||||
|
||||
<P>A scan function returns when:</P>
|
||||
|
||||
<UL>
|
||||
<LI>it reaches the terminating null in the format string
|
||||
|
||||
<LI>it cannot obtain additional input characters to scan
|
||||
(<B><A NAME="input failure">input failure</A></B>)
|
||||
|
||||
<LI>a conversion fails
|
||||
(<B><A NAME="matching failure">matching failure</A></B>)
|
||||
</UL>
|
||||
|
||||
<P>A scan function returns
|
||||
<A HREF="stdio.html#EOF" tppabs="http://ccs.ucsd.edu/c/stdio.html#EOF"><CODE>EOF</CODE></A>
|
||||
if an input failure occurs before any conversion. Otherwise it returns
|
||||
the number of converted values stored. If one or more characters form
|
||||
a valid prefix but the conversion fails, the valid prefix is consumed
|
||||
before the scan function returns. Thus:</P>
|
||||
|
||||
<PRE>
|
||||
scanf("%i", &i) <B>consumes 0X from the field 0XZ</B>
|
||||
scanf("%f", &f) <B>consumes 3.2E from the field 3.2EZ</B></PRE>
|
||||
|
||||
<P>A scan conversion specification typically converts the matched input
|
||||
characters to a corresponding encoded value. The next argument value
|
||||
must be the address of an object. The conversion converts the encoded
|
||||
representation (as necessary) and stores its value in the object.
|
||||
A scan conversion specification has the format:</P>
|
||||
|
||||
<P><IMG SRC="scan.gif" tppabs="http://ccs.ucsd.edu/c/gif/scan.gif"></P>
|
||||
|
||||
<P>Following the percent character (<B><CODE>%</CODE></B>)
|
||||
in the format string, you can write an asterisk (<B><CODE>*</CODE></B>)
|
||||
to indicate that the conversion should not store
|
||||
the converted value in an object.</P>
|
||||
|
||||
<P>Following any <CODE>*</CODE>, you can write a nonzero
|
||||
<B><A NAME="scan field width">field width</A></B>
|
||||
that specifies the maximum number of input characters
|
||||
to match for the conversion (not counting any
|
||||
<A HREF="lib_prin.html#white space" tppabs="http://ccs.ucsd.edu/c/lib_prin.html#white space">white space</A> that the
|
||||
pattern can first skip).</P>
|
||||
|
||||
<H2><A NAME="Scan Conversion Specifiers">Scan Conversion Specifiers</A></H2>
|
||||
|
||||
<P>Following any
|
||||
<A HREF="#scan field width">field width</A>,
|
||||
you must write a one-character <B>scan conversion specifier</B>,
|
||||
either a one-character code or a
|
||||
<A HREF="#scan set">scan set</A>,
|
||||
possibly preceded by a one-character qualifier.
|
||||
Each combination determines the type required of the
|
||||
next argument (if any) and how
|
||||
the scan functions interpret the text sequence and converts it to
|
||||
an encoded value.
|
||||
The <A HREF="lib_prin.html#integer conversions" tppabs="http://ccs.ucsd.edu/c/lib_prin.html#integer conversions">integer</A> and
|
||||
<A HREF="lib_prin.html#floating-point conversions" tppabs="http://ccs.ucsd.edu/c/lib_prin.html#floating-point conversions">
|
||||
floating-point conversions</A> also determine
|
||||
what base to assume for the text representation. (The base is
|
||||
the <CODE>base</CODE> argument to the functions
|
||||
<A HREF="stdlib.html#strtol" tppabs="http://ccs.ucsd.edu/c/stdlib.html#strtol"><CODE>strtol</CODE></A> and
|
||||
<A HREF="stdlib.html#strtoul" tppabs="http://ccs.ucsd.edu/c/stdlib.html#strtoul"><CODE>strtoul</CODE></A>.)
|
||||
The following table lists all defined combinations and
|
||||
their properties.</P>
|
||||
|
||||
<PRE><B>
|
||||
Conversion Argument Conversion
|
||||
Specifier Type Function Base</B>
|
||||
%c char x[]
|
||||
%lc wchar_t x[]
|
||||
%d int *x strtol 10
|
||||
%hd short *x strtol 10
|
||||
%ld long *x strtol 10
|
||||
%e float *x strtod 10
|
||||
%le double *x strtod 10
|
||||
%Le long double *x strtod 10
|
||||
%E float *x strtod 10
|
||||
%lE double *x strtod 10
|
||||
%LE long double *x strtod 10
|
||||
%f float *x strtod 10
|
||||
%lf double *x strtod 10
|
||||
%Lf long double *x strtod 10
|
||||
%g float *x strtod 10
|
||||
%lg double *x strtod 10
|
||||
%Lg long double *x strtod 10
|
||||
%G float *x strtod 10
|
||||
%lG double *x strtod 10
|
||||
%LG long double *x strtod 10
|
||||
%i int *x strtol 0
|
||||
%hi short *x strtol 0
|
||||
%li long *x strtol 0
|
||||
%n int *x
|
||||
%hn short *x
|
||||
%ln long *x
|
||||
%o unsigned int *x strtoul 8
|
||||
%ho unsigned short *x strtoul 8
|
||||
%lo unsigned long *x strtoul 8
|
||||
%p void **x
|
||||
%s char x[]
|
||||
%ls wchar_t x[]
|
||||
%u unsigned int *x strtoul 10
|
||||
%hu unsigned short *x strtoul 10
|
||||
%lu unsigned long *x strtoul 10
|
||||
%x unsigned int *x strtoul 16
|
||||
%hx unsigned short *x strtoul 16
|
||||
%lx unsigned long *x strtoul 16
|
||||
%X unsigned int *x strtoul 16
|
||||
%hX unsigned short *x strtoul 16
|
||||
%lX unsigned long *x strtoul 16
|
||||
%[...] char x[]
|
||||
%l[...] wchar_t x[]
|
||||
%% <B>none</B></PRE>
|
||||
|
||||
<P>The scan conversion specifier (or
|
||||
<A HREF="#scan set">scan set</A>) determines any behavior
|
||||
not summarized in this table. In the following descriptions,
|
||||
examples follow each of the scan conversion specifiers.
|
||||
In each example, the function
|
||||
<A HREF="stdio.html#sscanf" tppabs="http://ccs.ucsd.edu/c/stdio.html#sscanf"><CODE>sscanf</CODE></A>
|
||||
matches the <B><CODE>bold</CODE></B> characters.</P>
|
||||
|
||||
<P>You write <B><A NAME="%c"><CODE>%c</CODE></A></B>
|
||||
to store the matched input characters in
|
||||
an array object. If you specify no field width <I>w,</I> then <I>w</I>
|
||||
has the value one. The match does not skip leading
|
||||
<A HREF="lib_prin.html#white space" tppabs="http://ccs.ucsd.edu/c/lib_prin.html#white space">white space</A>. Any
|
||||
sequence of <I>w</I> characters matches the conversion pattern. For a
|
||||
<A HREF="lib_file.html#wide stream" tppabs="http://ccs.ucsd.edu/c/lib_file.html#wide stream">wide stream</A>,
|
||||
conversion occurs as if by repeatedly calling
|
||||
<A HREF="wchar.html#wcrtomb" tppabs="http://ccs.ucsd.edu/c/wchar.html#wcrtomb"><CODE>wcrtomb</CODE></A>,
|
||||
beginning in the
|
||||
<A HREF="charset.html#initial conversion state" tppabs="http://ccs.ucsd.edu/c/charset.html#initial conversion state">
|
||||
initial conversion state</A>.</P>
|
||||
|
||||
<PRE>
|
||||
sscanf("<B>1</B>29E-2", "%c", &c) <B>stores '1'</B>
|
||||
sscanf("<B>12</B>9E-2", "%2c", &c[0]) <B>stores '1', '2'</B>
|
||||
swscanf(L"<B>1</B>29E-2", L"%c", &c) <B>stores '1'</B></PRE>
|
||||
|
||||
<P>You write <B><A NAME="%lc"><CODE>%lc</CODE></A></B>
|
||||
to store the matched input characters in an array object,
|
||||
with elements of type
|
||||
<A HREF="stddef.html#wchar_t" tppabs="http://ccs.ucsd.edu/c/stddef.html#wchar_t">wchar_t</A>.
|
||||
If you specify no field width <I>w,</I> then <I>w</I>
|
||||
has the value one. The match does not skip leading
|
||||
<A HREF="lib_prin.html#white space" tppabs="http://ccs.ucsd.edu/c/lib_prin.html#white space">white space</A>. Any
|
||||
sequence of <I>w</I> characters matches the conversion pattern. For a
|
||||
<A HREF="lib_file.html#byte stream" tppabs="http://ccs.ucsd.edu/c/lib_file.html#byte stream">byte stream</A>,
|
||||
conversion occurs as if by repeatedly calling
|
||||
<A HREF="wchar.html#wcrtomb" tppabs="http://ccs.ucsd.edu/c/wchar.html#wcrtomb"><CODE>mbrtowc</CODE></A>, beginning in the
|
||||
<A HREF="charset.html#initial conversion state" tppabs="http://ccs.ucsd.edu/c/charset.html#initial conversion state">
|
||||
initial conversion state</A>.</P>
|
||||
|
||||
<PRE>
|
||||
sscanf("<B>1</B>29E-2", "%lc", &c) <B>stores L'1'</B>
|
||||
sscanf("<B>12</B>9E-2", "%2lc", &c) <B>stores L'1', L'2'</B>
|
||||
swscanf(L"<B>1</B>29E-2", L"%lc", &c) <B>stores L'1'</B></PRE>
|
||||
|
||||
<P>You write <B><A NAME="%d"><CODE>%d</CODE></A></B>,
|
||||
<B><A NAME="%i"><CODE>%i</CODE></A></B>,
|
||||
<B><A NAME="%o"><CODE>%o</CODE></A></B>,
|
||||
<B><A NAME="%u"><CODE>%u</CODE></A></B>,
|
||||
<B><A NAME="%x"><CODE>%x</CODE></A></B>, or
|
||||
<B><A NAME="%X"><CODE>%X</CODE></A></B> to convert
|
||||
the matched input characters as a signed integer
|
||||
and store the result in an integer object.</P>
|
||||
|
||||
<PRE>
|
||||
sscanf("<B>129E</B>-2", "%o%d%x", &i, &j, &k) <B>stores 10, 9, 14</B></PRE>
|
||||
|
||||
<P>You write <B><A NAME="%e"><CODE>%e</CODE></A></B>,
|
||||
<B><A NAME="%E"><CODE>%E</CODE></A></B>,
|
||||
<B><A NAME="%f"><CODE>%f</CODE></A></B>,
|
||||
<B><A NAME="%g"><CODE>%g</CODE></A></B>, or
|
||||
<B><A NAME="%G"><CODE>%G</CODE></A></B>
|
||||
to convert the matched input characters as a signed fraction, with
|
||||
an optional exponent, and store the result in a floating-point object.</P>
|
||||
|
||||
<PRE>
|
||||
sscanf("<B>129E-2</B>", "%e", &f) <B>stores 1.29</B></PRE>
|
||||
|
||||
<P>You write <B><A NAME="%n"><CODE>%n</CODE></A></B>
|
||||
to store the number of characters
|
||||
matched (up to this point in the format) in an integer object. The
|
||||
match does not skip leading
|
||||
<A HREF="lib_prin.html#white space" tppabs="http://ccs.ucsd.edu/c/lib_prin.html#white space">white space</A>
|
||||
and does not match any input characters.</P>
|
||||
|
||||
<PRE>
|
||||
sscanf("<B>12</B>9E-2", "12%n", &i) <B>stores 2</B></PRE>
|
||||
|
||||
<P>You write <B><A NAME="%p"><CODE>%p</CODE></A></B>
|
||||
to convert the matched input characters as
|
||||
an external representation of a <I>pointer to void</I> and store the
|
||||
result in an object of type <I>pointer to void.</I> The input characters
|
||||
must match the form generated by the
|
||||
<A HREF="lib_prin.html#%p" tppabs="http://ccs.ucsd.edu/c/lib_prin.html#%p"><CODE>%p</CODE>
|
||||
<A HREF="lib_prin.html#print conversion specification" tppabs="http://ccs.ucsd.edu/c/lib_prin.html#print conversion specification">
|
||||
print conversion specification</A>.</P>
|
||||
|
||||
<PRE>
|
||||
sscanf("<B>129E</B>-2", "%p", &p) <B>stores, e.g. 0x129E</B></PRE>
|
||||
|
||||
<P>You write <B><A NAME="%s"><CODE>%s</CODE></A></B>
|
||||
to store the matched input characters in
|
||||
an array object, followed by a terminating null character. If you
|
||||
do not specify a field width <I>w,</I> then <I>w</I> has a large value.
|
||||
Any sequence of up to <I>w</I> non white-space characters matches
|
||||
the conversion pattern. For a
|
||||
<A HREF="lib_file.html#wide stream" tppabs="http://ccs.ucsd.edu/c/lib_file.html#wide stream">wide stream</A>,
|
||||
conversion occurs as if by repeatedly calling
|
||||
<CODE>wcrtomb</CODE> beginning in the
|
||||
<A HREF="charset.html#initial conversion state" tppabs="http://ccs.ucsd.edu/c/charset.html#initial conversion state">
|
||||
initial conversion state</A>.</P>
|
||||
|
||||
<PRE>
|
||||
sscanf("<B>129E-2</B>", "%s", &s[0]) <B>stores "129E-2"</B>
|
||||
swscanf(L"<B>129E-2</B>", L"%s", &s[0]) <B>stores "129E-2"</B></PRE>
|
||||
|
||||
<P>You write <B><A NAME="%ls"><CODE>%ls</CODE></A></B>
|
||||
to store the matched input characters in
|
||||
an array object, with elements of type
|
||||
<A HREF="stddef.html#wchar_t" tppabs="http://ccs.ucsd.edu/c/stddef.html#wchar_t">wchar_t</A>,
|
||||
followed by a terminating null wide character. If you
|
||||
do not specify a field width <I>w,</I> then <I>w</I> has a large value.
|
||||
Any sequence of up to <I>w</I> non white-space characters matches
|
||||
the conversion pattern. For a
|
||||
<A HREF="lib_file.html#byte stream" tppabs="http://ccs.ucsd.edu/c/lib_file.html#byte stream">byte stream</A>,
|
||||
conversion occurs as if by repeatedly calling
|
||||
<A HREF="wchar.html#mbrtowc" tppabs="http://ccs.ucsd.edu/c/wchar.html#mbrtowc"><CODE>mbrtowc</CODE></A>,
|
||||
beginning in the
|
||||
<A HREF="charset.html#initial conversion state" tppabs="http://ccs.ucsd.edu/c/charset.html#initial conversion state">
|
||||
initial conversion state</A>.</P>
|
||||
|
||||
<PRE>
|
||||
sscanf("<B>129E-2</B>", "%ls", &s[0]) <B>stores L"129E-2"</B>
|
||||
swscanf(L"<B>129E-2</B>", L"%ls", &s[0]) <B>stores L"129E-2"</B></PRE>
|
||||
|
||||
<P>You write <B><A NAME="%["><CODE>%[</CODE></A></B>
|
||||
to store the matched input characters in
|
||||
an array object, followed by a terminating null character. If you
|
||||
do not specify a field width <I>w,</I> then <I>w</I> has a large value.
|
||||
The match does not skip leading
|
||||
<A HREF="lib_prin.html#white space" tppabs="http://ccs.ucsd.edu/c/lib_prin.html#white space">white space</A>.
|
||||
A sequence of up to <I>w</I>
|
||||
characters matches the conversion pattern in the
|
||||
<B><A NAME="scan set">scan set</A></B> that follows.
|
||||
To complete the scan set, you follow the left bracket
|
||||
(<CODE>[</CODE>) in the conversion specification with a sequence
|
||||
of zero or more <B>match</B> characters, terminated by a right bracket
|
||||
(<B><CODE>]</CODE></B>).</P>
|
||||
|
||||
<P>If you do not write a caret (<B><CODE>^</CODE></B>)
|
||||
immediately after the <CODE>[</CODE>, then each
|
||||
input character must match <I>one</I> of the match
|
||||
characters. Otherwise, each input character must not match <I>any</I>
|
||||
of the match characters, which begin with the character following
|
||||
the <CODE>^</CODE>. If you write a <B><CODE>]</CODE></B>
|
||||
immediately after the <CODE>[</CODE> or <CODE>[^</CODE>,
|
||||
then the <CODE>]</CODE> is the first match character, not
|
||||
the terminating <CODE>]</CODE>. If you write a minus
|
||||
(<B><CODE>-</CODE></B>) as other than the first or last match character,
|
||||
an implementation can give it special meaning.
|
||||
It usually indicates a range of characters, in conjunction with the
|
||||
characters immediately preceding or following, as in
|
||||
<CODE>0-9</CODE> for all the digits.)
|
||||
You cannot specify a null match character.</P>
|
||||
|
||||
<P> For a <A HREF="lib_file.html#wide stream" tppabs="http://ccs.ucsd.edu/c/lib_file.html#wide stream">wide stream</A>,
|
||||
conversion occurs as if by repeatedly calling
|
||||
<A HREF="wchar.html#wcrtomb" tppabs="http://ccs.ucsd.edu/c/wchar.html#wcrtomb"><CODE>wcrtomb</CODE></A>,
|
||||
beginning in the
|
||||
<A HREF="charset.html#initial conversion state" tppabs="http://ccs.ucsd.edu/c/charset.html#initial conversion state">
|
||||
initial conversion state</A>.</P>
|
||||
|
||||
<PRE>
|
||||
sscanf("<B>12</B>9E-2", "[54321]", &s[0]) <B>stores "12"</B>
|
||||
swscanf(L"<B>12</B>9E-2", L"[54321]", &s[0]) <B>stores "12"</B></PRE>
|
||||
|
||||
<P>You write <B><A NAME="%l["><CODE>%l[</CODE></A></B>
|
||||
to store the matched input characters in
|
||||
an array object, with elements of type
|
||||
<A HREF="stddef.html#wchar_t" tppabs="http://ccs.ucsd.edu/c/stddef.html#wchar_t">wchar_t</A>,
|
||||
followed by a terminating null wide character. If you
|
||||
do not specify a field width <I>w,</I> then <I>w</I> has a large value.
|
||||
The match does not skip leading
|
||||
<A HREF="lib_prin.html#white space" tppabs="http://ccs.ucsd.edu/c/lib_prin.html#white space">.
|
||||
A sequence of up to <I>w</I>
|
||||
characters matches the conversion pattern in the
|
||||
<A HREF="#scan set">scan set</A> that follows.
|
||||
|
||||
<P> For a <A HREF="lib_file.html#byte stream" tppabs="http://ccs.ucsd.edu/c/lib_file.html#byte stream">byte stream</A>,
|
||||
conversion occurs as if by repeatedly calling
|
||||
<A HREF="wchar.html#mbrtowc" tppabs="http://ccs.ucsd.edu/c/wchar.html#mbrtowc"><CODE>mbrtowc</CODE></A>,
|
||||
beginning in the
|
||||
<A HREF="charset.html#initial conversion state" tppabs="http://ccs.ucsd.edu/c/charset.html#initial conversion state">
|
||||
initial conversion state</A>.</P>
|
||||
|
||||
<PRE>
|
||||
sscanf("<B>12</B>9E-2", "l[54321]", &s[0]) <B>stores L"12"</B>
|
||||
swscanf(L"<B>12</B>9E-2", L"l[54321]", &s[0]) <B>stores L"12"</B></PRE>
|
||||
|
||||
<P>You write <B><A NAME="%%"><CODE>%%</CODE></A></B>
|
||||
to match the percent character (<CODE>%</CODE>).
|
||||
The function does not store a value.</P>
|
||||
|
||||
<PRE>
|
||||
sscanf("<B>% 0XA</B>", "%% %i") <B>stores 10</B></PRE>
|
||||
|
||||
<HR>
|
||||
<P>See also the
|
||||
<B><A HREF="index.html#Table of Contents" tppabs="http://ccs.ucsd.edu/c/index.html#Table of Contents">Table of Contents</A></B> and the
|
||||
<B><A HREF="_index.html" tppabs="http://ccs.ucsd.edu/c/_index.html">Index</A></B>.</P>
|
||||
|
||||
<P><I>
|
||||
<A HREF="crit_pb.html" tppabs="http://ccs.ucsd.edu/c/crit_pb.html">Copyright</A> © 1989-1996
|
||||
by P.J. Plauger and Jim Brodie. All rights reserved.</I></P>
|
||||
|
||||
</BODY></HTML>
|
||||
|
||||
210
study/Ref-docs/C/limits.html
Normal file
@@ -0,0 +1,210 @@
|
||||
<HTML><HEAD><TITLE><limits.h></TITLE></HEAD><BODY BGCOLOR="#FFFFFF">
|
||||
|
||||
<H1><A NAME="<limits.h>"><CODE><limits.h></CODE></A></H1><HR>
|
||||
|
||||
<P><CODE>
|
||||
#define <A HREF="#CHAR_BIT"><B>CHAR_BIT</B></A>
|
||||
<I><#if expression >= 8></I><BR>
|
||||
#define <A HREF="#CHAR_MAX"><B>CHAR_MAX</B></A>
|
||||
<I><#if expression >= 127></I><BR>
|
||||
#define <A HREF="#CHAR_MIN"><B>CHAR_MIN</B></A>
|
||||
<I><#if expression <= 0></I><BR>
|
||||
#define <A HREF="#INT_MAX"><B>INT_MAX</B></A>
|
||||
<I><#if expression >= 32,767></I><BR>
|
||||
#define <A HREF="#INT_MIN"><B>INT_MIN</B></A>
|
||||
<I><#if expression <= -32,767></I><BR>
|
||||
#define <A HREF="#LONG_MAX"><B>LONG_MAX</B></A>
|
||||
<I><#if expression >= 2,147,483,647></I><BR>
|
||||
#define <A HREF="#LONG_MIN"><B>LONG_MIN</B></A>
|
||||
<I><#if expression <= -2,147,483,647></I><BR>
|
||||
#define <A HREF="#MB_LEN_MAX"><B>MB_LEN_MAX</B></A>
|
||||
<I><#if expression >= 1></I><BR>
|
||||
#define <A HREF="#SCHAR_MAX"><B>SCHAR_MAX</B></A>
|
||||
<I><#if expression >= 127></I><BR>
|
||||
#define <A HREF="#SCHAR_MIN"><B>SCHAR_MIN</B></A>
|
||||
<I><#if expression <= -127></I><BR>
|
||||
#define <A HREF="#SHRT_MAX"><B>SHRT_MAX</B></A>
|
||||
<I><#if expression >= 32,767></I><BR>
|
||||
#define <A HREF="#SHRT_MIN"><B>SHRT_MIN</B></A>
|
||||
<I><#if expression <= -32,767></I><BR>
|
||||
#define <A HREF="#UCHAR_MAX"><B>UCHAR_MAX</B></A>
|
||||
<I><#if expression >= 255></I><BR>
|
||||
#define <A HREF="#UINT_MAX"><B>UINT_MAX</B></A>
|
||||
<I><#if expression >= 65,535></I><BR>
|
||||
#define <A HREF="#ULONG_MAX"><B>ULONG_MAX</B></A>
|
||||
<I><#if expression >= 4,294,967,295></I><BR>
|
||||
#define <A HREF="#USHRT_MAX"><B>USHRT_MAX</B></A>
|
||||
<I><#if expression >= 65,535></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>Include the standard header <B><CODE><limits.h></CODE></B>
|
||||
to determine various properties of the integer type representations.
|
||||
The standard header <CODE><limits.h></CODE> is available
|
||||
even in a
|
||||
<A HREF="lib_over.html#freestanding implementation" tppabs="http://ccs.ucsd.edu/c/lib_over.html#freestanding implementation">
|
||||
freestanding implementation</A>.</P>
|
||||
|
||||
<P>You can test the values of all these macros in an
|
||||
<A HREF="preproc.html#if directive" tppabs="http://ccs.ucsd.edu/c/preproc.html#if directive"><I>if</I> directive</A>.
|
||||
(The macros are
|
||||
<A HREF="preproc.html#if expression" tppabs="http://ccs.ucsd.edu/c/preproc.html#if expression"><I>#if</I> expressions</A>.)</P>
|
||||
|
||||
<H2><A NAME="CHAR_BIT"><CODE>CHAR_BIT</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>CHAR_BIT</B> <I><#if expression >= 8></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the maximum value for the number of bits used
|
||||
to represent an object of type <I>char.</I></P>
|
||||
|
||||
<H2><A NAME="CHAR_MAX"><CODE>CHAR_MAX</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>CHAR_MAX</B> <I><#if expression >= 127></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the maximum value for type <I>char.</I> Its
|
||||
value is:</P>
|
||||
|
||||
<UL>
|
||||
<LI><A HREF="#SCHAR_MAX"><CODE>SCHAR_MAX</CODE></A>
|
||||
if <I>char</I> represents negative values
|
||||
|
||||
<LI><A HREF="#UCHAR_MAX"><CODE>UCHAR_MAX</CODE></A> otherwise
|
||||
</UL>
|
||||
|
||||
<H2><A NAME="CHAR_MIN"><CODE>CHAR_MIN</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>CHAR_MIN</B> <I><#if expression <= 0></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the minimum value for type <I>char.</I> Its
|
||||
value is:</P>
|
||||
|
||||
<UL>
|
||||
<LI><A HREF="#SCHAR_MIN"><CODE>SCHAR_MIN</CODE></A>
|
||||
if <I>char</I> represents negative values
|
||||
|
||||
<LI>zero otherwise
|
||||
</UL>
|
||||
|
||||
<H2><A NAME="INT_MAX"><CODE>INT_MAX</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>INT_MAX</B> <I><#if expression >= 32,767></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the maximum value for type <I>int.</I></P>
|
||||
|
||||
<H2><A NAME="INT_MIN"><CODE>INT_MIN</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>INT_MIN</B> <I><#if expression <= -32,767></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the minimum value for type <I>int.</I></P>
|
||||
|
||||
<H2><A NAME="LONG_MAX"><CODE>LONG_MAX</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>LONG_MAX</B> <I><#if expression >= 2,147,483,647></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the maximum value for type <I>long.</I></P>
|
||||
|
||||
<H2><A NAME="LONG_MIN"><CODE>LONG_MIN</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>LONG_MIN</B> <I><#if expression <= -2,147,483,647></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the minimum value for type <I>long.</I></P>
|
||||
|
||||
<H2><A NAME="MB_LEN_MAX"><CODE>MB_LEN_MAX</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>MB_LEN_MAX</B> <I><#if expression >= 1></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the maximum number of characters that constitute a
|
||||
<A HREF="charset.html#Multibyte Characters" tppabs="http://ccs.ucsd.edu/c/charset.html#Multibyte Characters">multibyte character</A>
|
||||
in any supported
|
||||
<A HREF="locale.html" tppabs="http://ccs.ucsd.edu/c/locale.html">locale</A>. Its value is >=
|
||||
<A HREF="stdlib.html#MB_CUR_MAX" tppabs="http://ccs.ucsd.edu/c/stdlib.html#MB_CUR_MAX"><CODE>MB_CUR_MAX</CODE></A>.</P>
|
||||
|
||||
<H2><A NAME="SCHAR_MAX"><CODE>SCHAR_MAX</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>SCHAR_MAX</B> <I><#if expression >= 127></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the maximum value for type <I>signed char.</I></P>
|
||||
|
||||
<H2><A NAME="SCHAR_MIN"><CODE>SCHAR_MIN</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>SCHAR_MIN</B> <I><#if expression <= -127></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the minimum value for type <I>signed char.</I></P>
|
||||
|
||||
<H2><A NAME="SHRT_MAX"><CODE>SHRT_MAX</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>SHRT_MAX</B> <I><#if expression >= 32,767></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the maximum value for type <I>short.</I></P>
|
||||
|
||||
<H2><A NAME="SHRT_MIN"><CODE>SHRT_MIN</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>SHRT_MIN</B> <I><#if expression <= -32,767></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the minimum value for type <I>short.</I></P>
|
||||
|
||||
<H2><A NAME="UCHAR_MAX"><CODE>UCHAR_MAX</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>UCHAR_MAX</B> <I><#if expression >= 255></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the maximum value for type <I>unsigned char.</I></P>
|
||||
|
||||
<H2><A NAME="UINT_MAX"><CODE>UINT_MAX</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>UINT_MAX</B> <I><#if expression >= 65,535></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the maximum value for type <I>unsigned int.</I></P>
|
||||
|
||||
<H2><A NAME="ULONG_MAX"><CODE>ULONG_MAX</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>ULONG_MAX</B> <I><#if expression >= 4,294,967,295></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the maximum value for type <I>unsigned long.</I></P>
|
||||
|
||||
<H2><A NAME="USHRT_MAX"><CODE>USHRT_MAX</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>USHRT_MAX</B> <I><#if expression >= 65,535></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the maximum value for type <I>unsigned short.</P>
|
||||
|
||||
<HR>
|
||||
<P>See also the
|
||||
<B><A HREF="index.html#Table of Contents" tppabs="http://ccs.ucsd.edu/c/index.html#Table of Contents">Table of Contents</A></B> and the
|
||||
<B><A HREF="_index.html" tppabs="http://ccs.ucsd.edu/c/_index.html">Index</A></B>.</P>
|
||||
|
||||
<P><I>
|
||||
<A HREF="crit_pb.html" tppabs="http://ccs.ucsd.edu/c/crit_pb.html">Copyright</A> © 1989-1996
|
||||
by P.J. Plauger and Jim Brodie. All rights reserved.</I></P>
|
||||
|
||||
</BODY></HTML>
|
||||
BIN
study/Ref-docs/C/line.gif
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
study/Ref-docs/C/line_grp.gif
Normal file
|
After Width: | Height: | Size: 1.4 KiB |
378
study/Ref-docs/C/locale.html
Normal file
@@ -0,0 +1,378 @@
|
||||
<HTML><HEAD><TITLE><locale.h></TITLE></HEAD><BODY BGCOLOR="#FFFFFF">
|
||||
|
||||
<H1><A NAME="<locale.h>"><CODE><locale.h></CODE></A></H1><HR>
|
||||
|
||||
<P><CODE>
|
||||
#define <A HREF="#LC_ALL"><B>LC_ALL</B></A>
|
||||
<I><integer constant expression></I><BR>
|
||||
#define <A HREF="#LC_COLLATE"><B>LC_COLLATE</B></A>
|
||||
<I><integer constant expression></I><BR>
|
||||
#define <A HREF="#LC_CTYPE"><B>LC_CTYPE</B></A>
|
||||
<I><integer constant expression></I><BR>
|
||||
#define <A HREF="#LC_MONETARY"><B>LC_MONETARY</B></A>
|
||||
<I><integer constant expression></I><BR>
|
||||
#define <A HREF="#LC_NUMERIC"><B>LC_NUMERIC</B></A>
|
||||
<I><integer constant expression></I><BR>
|
||||
#define <A HREF="#LC_TIME"><B>LC_TIME</B></A>
|
||||
<I><integer constant expression></I><BR>
|
||||
#define <A HREF="#NULL"><B>NULL</B></A>
|
||||
<I><either 0, 0L, or (void *)0></I> <B>[0 in C++]</B><BR>
|
||||
struct <A HREF="#lconv"><B>lconv</B></A>;<BR>
|
||||
struct lconv *<A HREF="#localeconv"><B>localeconv</B></A>(void);<BR>
|
||||
char *<A HREF="#setlocale"><B>setlocale</B></A>(int category,
|
||||
const char *locale);
|
||||
</CODE></P>
|
||||
|
||||
<P>Include the standard header <B><CODE><locale.h></CODE></B>
|
||||
to alter or access properties of the current
|
||||
<B><A NAME="locale">locale</A></B>
|
||||
-- a collection of culture-specific information.
|
||||
An implementation can define additional
|
||||
macros in this standard header with names that begin with <CODE>LC_</CODE>.
|
||||
You can use any of these macro names as the
|
||||
<B><A NAME="locale category">locale category</A></B> argument
|
||||
(which selects a cohesive subset of a locale) to
|
||||
<A HREF="#setlocale"><CODE>setlocale</CODE></A>.</P>
|
||||
|
||||
<H2><A NAME="LC_ALL"><CODE>LC_ALL</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>LC_ALL</B> <I><integer constant expression></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the
|
||||
<A HREF="#locale category">locale category</A>
|
||||
argument value that affects all locale categories.</P>
|
||||
|
||||
<H2><A NAME="LC_COLLATE"><CODE>LC_COLLATE</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>LC_COLLATE</B> <I><integer constant expression></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the
|
||||
<A HREF="#locale category">locale category</A>
|
||||
argument value that affects the collation functions
|
||||
<CODE>strcoll</CODE> and
|
||||
<CODE>strxfrm</CODE>.</P>
|
||||
|
||||
<H2><A NAME="LC_CTYPE"><CODE>LC_CTYPE</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>LC_CTYPE</B> <I><integer constant expression></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the
|
||||
<A HREF="#locale category">locale category</A>
|
||||
argument value that affects
|
||||
<A HREF="ctype.html" tppabs="http://ccs.ucsd.edu/c/ctype.html">character classification</A> functions,
|
||||
<A HREF="wctype.html" tppabs="http://ccs.ucsd.edu/c/wctype.html">wide-character classification</A> functions,
|
||||
and various multibyte conversion functions.</P>
|
||||
|
||||
<H2><A NAME="LC_MONETARY"><CODE>LC_MONETARY</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>LC_MONETARY</B> <I><integer constant expression></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the
|
||||
<A HREF="#locale category">locale category</A>
|
||||
argument value that affects monetary information returned by
|
||||
<A HREF="#localeconv"><CODE>localeconv</CODE></A>.</P>
|
||||
|
||||
<H2><A NAME="LC_NUMERIC"><CODE>LC_NUMERIC</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>LC_NUMERIC</B> <I><integer constant expression></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the
|
||||
<A HREF="#locale category">locale category</A>
|
||||
argument value that affects numeric information returned by
|
||||
<A HREF="#localeconv"><CODE>localeconv</CODE></A>,
|
||||
including the decimal point used by numeric conversion,
|
||||
read, and write functions.</P>
|
||||
|
||||
<H2><A NAME="LC_TIME"><CODE>LC_TIME</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>LC_TIME</B> <I><integer constant expression></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the
|
||||
<A HREF="#locale category">locale category</A>
|
||||
argument value that affects the time conversion function
|
||||
<A HREF="time.html#strftime" tppabs="http://ccs.ucsd.edu/c/time.html#strftime"><CODE>strftime</CODE></A>.</P>
|
||||
|
||||
<H2><A NAME="NULL"><CODE>NULL</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>NULL</B> <I><either 0, 0L, or (void *)0></I> <B>[0 in C++]</B>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields a null pointer constant that is usable as an
|
||||
<A HREF="express.html#address constant expression" tppabs="http://ccs.ucsd.edu/c/express.html#address constant expression">
|
||||
address constant expression</A>.</P>
|
||||
|
||||
<H2><A NAME="lconv"><CODE>lconv</CODE></A></H2>
|
||||
|
||||
<PRE>struct <B>lconv</B> {
|
||||
<B>ELEMENT "C" LOCALE LOCALE CATEGORY</B>
|
||||
char *currency_symbol; <B>"" LC_MONETARY</B>
|
||||
char *decimal_point; <B>"." LC_NUMERIC</B>
|
||||
char *grouping; <B>"" LC_NUMERIC</B>
|
||||
char *int_curr_symbol; <B>"" LC_MONETARY</B>
|
||||
char *mon_decimal_point; <B>"" LC_MONETARY</B>
|
||||
char *mon_grouping; <B>"" LC_MONETARY</B>
|
||||
char *mon_thousands_sep; <B>"" LC_MONETARY</B>
|
||||
char *negative_sign; <B>"" LC_MONETARY</B>
|
||||
char *positive_sign; <B>"" LC_MONETARY</B>
|
||||
char *thousands_sep; <B>"" LC_NUMERIC</B>
|
||||
char frac_digits; <B>CHAR_MAX LC_MONETARY</B>
|
||||
char int_frac_digits; <B>CHAR_MAX LC_MONETARY</B>
|
||||
char n_cs_precedes; <B>CHAR_MAX LC_MONETARY</B>
|
||||
char n_sep_by_space; <B>CHAR_MAX LC_MONETARY</B>
|
||||
char n_sign_posn; <B>CHAR_MAX LC_MONETARY</B>
|
||||
char p_cs_precedes; <B>CHAR_MAX LC_MONETARY</B>
|
||||
char p_sep_by_space; <B>CHAR_MAX LC_MONETARY</B>
|
||||
char p_sign_posn; <B>CHAR_MAX LC_MONETARY</B>
|
||||
};
|
||||
</PRE>
|
||||
|
||||
<P><CODE>struct lconv</CODE> contains members that describe how to format
|
||||
numeric and monetary values. Functions in the Standard C library use
|
||||
only the field <CODE>decimal_point</CODE>.
|
||||
The information is otherwise advisory:</P>
|
||||
|
||||
<UL>
|
||||
<LI>Members of type <I>pointer to char</I> all point to
|
||||
<A HREF="lib_over.html#C string" tppabs="http://ccs.ucsd.edu/c/lib_over.html#C string">C strings</A>.
|
||||
|
||||
<LI>Members of type <I>char</I> have nonnegative values.
|
||||
|
||||
<LI>A <I>char</I> value of
|
||||
<A HREF="limits.html#CHAR_MAX" tppabs="http://ccs.ucsd.edu/c/limits.html#CHAR_MAX"><CODE>CHAR_MAX</CODE></A>
|
||||
indicates that a meaningful
|
||||
value is not available in the current locale.
|
||||
</UL>
|
||||
|
||||
<P>The members shown above can occur in arbitrary order and can
|
||||
be interspersed with additional members. The comment following each
|
||||
member shows its value for the
|
||||
<B><A NAME="C locale"><CODE>"C"</CODE> locale</A></B>,
|
||||
the locale in effect at
|
||||
<A HREF="lib_over.html#program startup" tppabs="http://ccs.ucsd.edu/c/lib_over.html#program startup">program startup</A>,
|
||||
followed by the
|
||||
<A HREF="#locale category">locale category</A>
|
||||
that can affect its value.</P>
|
||||
|
||||
<P>A description of each member follows, with an example in parentheses
|
||||
that would be suitable for a USA locale.</P>
|
||||
|
||||
<P><B><A NAME="currency_symbol"><CODE>currency_symbol</CODE></A></B>
|
||||
-- the local currency symbol (<CODE>"$"</CODE>)</P>
|
||||
|
||||
<P><B><A NAME="decimal_point"><CODE>decimal_point</CODE></A></B>
|
||||
-- the decimal point for non-monetary values (<CODE>"."</CODE>)</P>
|
||||
|
||||
<P><B><A NAME="grouping"><CODE>grouping</CODE></A></B>
|
||||
-- the sizes of digit groups for non-monetary values.
|
||||
Successive elements of the string describe groups going away
|
||||
from the decimal point:</P>
|
||||
|
||||
<UL>
|
||||
<LI>An element value of zero (the terminating null character) calls
|
||||
for the previous element value to be repeated indefinitely.
|
||||
|
||||
<LI>An element value of
|
||||
<A HREF="limits.html#CHAR_MAX" tppabs="http://ccs.ucsd.edu/c/limits.html#CHAR_MAX"><CODE>CHAR_MAX</CODE></A>
|
||||
ends any further grouping (and hence ends the string).
|
||||
</UL>
|
||||
|
||||
<P>Thus, the array <CODE>{3, 2, CHAR_MAX}</CODE> calls for a group of
|
||||
three digits, then two, then whatever remains, as in
|
||||
<CODE>9876,54,321</CODE>, while <CODE>"\3"</CODE>
|
||||
calls for repeated groups of three digits, as in
|
||||
<CODE>987,654,321</CODE>. (<CODE>"\3"</CODE>)</P>
|
||||
|
||||
<P><B><A NAME="int_curr_symbol"><CODE>int_curr_symbol</CODE></A></B>
|
||||
-- the international currency symbol
|
||||
specified by ISO 4217 (<CODE>"USD "</CODE>)</P>
|
||||
|
||||
<P><B><A NAME="mon_decimal_point"><CODE>mon_decimal_point</CODE></A></B>
|
||||
-- the decimal point for monetary values (<CODE>"."</CODE>)</P>
|
||||
|
||||
<P><B><A NAME="mon_grouping"><CODE>mon_grouping</CODE></A></B>
|
||||
-- the sizes of digit groups for monetary values.
|
||||
Successive elements of the string describe groups going away
|
||||
from the decimal point. The encoding is the same as for
|
||||
<A HREF="#grouping"><CODE>grouping</CODE></A>.</P>
|
||||
|
||||
<P><B><A NAME="mon_thousands_sep"><CODE>mon_thousands_sep</CODE></A></B>
|
||||
-- the separator for digit groups to the left of the decimal point
|
||||
for monetary values (<CODE>","</CODE>)</P>
|
||||
|
||||
<P><B><A NAME="negative_sign"><CODE>negative_sign</CODE></A></B>
|
||||
-- the negative sign for monetary values (<CODE>"-"</CODE>)</P>
|
||||
|
||||
<P><B><A NAME="positive_sign"><CODE>positive_sign</CODE></A></B>
|
||||
-- the positive sign for monetary values (<CODE>"+"</CODE>)</P>
|
||||
|
||||
<P><B><A NAME="thousands_sep"><CODE>thousands_sep</CODE></A></B>
|
||||
-- the separator for digit groups to the left of the decimal point
|
||||
for non-monetary values (<CODE>","</CODE>)</P>
|
||||
|
||||
<P><B><A NAME="frac_digits"><CODE>frac_digits</CODE></A></B>
|
||||
-- the number of digits to display to the right of the decimal point
|
||||
for monetary values (<CODE>2</CODE>)</P>
|
||||
|
||||
<P><B><A NAME="int_frac_digits"><CODE>int_frac_digits</CODE></A></B>
|
||||
-- the number of digits to display to the right of the decimal point
|
||||
for international monetary values (<CODE>2</CODE>)</P>
|
||||
|
||||
<P><B><A NAME="n_cs_precedes"><CODE>n_cs_precedes</CODE></A></B>
|
||||
-- whether the currency symbol
|
||||
precedes or follows the value for negative monetary values:</P>
|
||||
|
||||
<UL>
|
||||
<LI>A value of 0 indicates that the symbol follows the value.
|
||||
|
||||
<LI>A value of 1 indicates that the symbol precedes the value.
|
||||
(<CODE>1</CODE>)
|
||||
</UL>
|
||||
|
||||
<P><B><A NAME="n_sep_by_space"><CODE>n_sep_by_space</CODE></A></B>
|
||||
-- whether the currency symbol
|
||||
is separated by a space or by no space from the value
|
||||
for negative monetary values:</P>
|
||||
|
||||
<UL>
|
||||
<LI>A value of 0 indicates that no space separates symbol and value.
|
||||
|
||||
<LI>A value of 1 indicates that a space separates symbol and value.
|
||||
(<CODE>0</CODE>)
|
||||
</UL>
|
||||
|
||||
<P><B><A NAME="n_sign_posn"><CODE>n_sign_posn</CODE></A></B>
|
||||
-- the format for negative monetary values:</P>
|
||||
|
||||
<UL>
|
||||
<LI>A value of 0 indicates that parentheses surround the value and the
|
||||
currency symbol.
|
||||
|
||||
<LI>A value of 1 indicates that the negative sign precedes the value and the
|
||||
currency symbol.
|
||||
|
||||
<LI>A value of 2 indicates that the negative sign follows the value and the
|
||||
currency_symbol.
|
||||
|
||||
<LI>A value of 3 indicates that the negative sign immediately precedes the
|
||||
currency symbol.
|
||||
|
||||
<LI>A value of 4 indicates that the negative sign immediately follows the
|
||||
currency_symbol. (<CODE>4</CODE>)
|
||||
</UL>
|
||||
|
||||
<P><B><A NAME="p_cs_precedes"><CODE>p_cs_precedes</CODE></A></B>
|
||||
-- whether the currency symbol precedes
|
||||
or follows the value for positive monetary values:</P>
|
||||
|
||||
<UL>
|
||||
<LI>A value of 0 indicates that the symbol follows the value.
|
||||
|
||||
<LI>A value of 1 indicates that the symbol precedes the value.
|
||||
(<CODE>1</CODE>)
|
||||
</UL>
|
||||
|
||||
<P><B><A NAME="p_sep_by_space"><CODE>p_sep_by_space</CODE></A></B>
|
||||
-- whether the currency symbol is separated
|
||||
by a space or by no space from the value for positive monetary values:</P>
|
||||
|
||||
<UL>
|
||||
<LI>A value of 0 indicates that no space separates symbol and value.
|
||||
|
||||
<LI>A value of 1 indicates that a space separates symbol and value.
|
||||
(<CODE>0</CODE>)
|
||||
</UL>
|
||||
|
||||
<P><B><A NAME="p_sign_posn"><CODE>p_sign_posn</CODE></A></B>
|
||||
-- the format for positive monetary values:</P>
|
||||
|
||||
<UL>
|
||||
<LI>A value of 0 indicates that parentheses surround the value and
|
||||
the currency symbol.
|
||||
|
||||
<LI>A value of 1 indicates that the negative sign precedes the value
|
||||
and the currency symbol.
|
||||
|
||||
<LI>A value of 2 indicates that the negative sign follows the value
|
||||
and the currency symbol.
|
||||
|
||||
<LI>A value of 3 indicates that the negative sign immediately precedes
|
||||
the currency symbol.
|
||||
|
||||
<LI>A value of 4 indicates that the negative sign immediately follows
|
||||
the currency symbol. (<CODE>4</CODE>)
|
||||
</UL>
|
||||
|
||||
<H2><A NAME="localeconv"><CODE>localeconv</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
struct lconv *<B>localeconv</B>(void);
|
||||
</CODE></P>
|
||||
|
||||
<P>The function returns a pointer to a static-duration structure
|
||||
containing numeric formatting information for the current locale.
|
||||
You cannot alter values stored in the static-duration structure. The
|
||||
stored values can change on later calls
|
||||
to <CODE>localeconv</CODE> or on calls to
|
||||
<A HREF="#setlocale"><CODE>setlocale</CODE></A>
|
||||
that alter any of the categories
|
||||
<A HREF="#LC_ALL"><CODE>LC_ALL</CODE></A>,
|
||||
<A HREF="#LC_MONETARY"><CODE>LC_MONETARY</CODE></A>, or
|
||||
<A HREF="#LC_NUMERIC"><CODE>LC_NUMERIC</CODE></A>.</P>
|
||||
|
||||
<H2><A NAME="setlocale"><CODE>setlocale</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
char *<B>setlocale</B>(int category, const char *locale);
|
||||
</CODE></P>
|
||||
|
||||
<P>The function either returns a pointer to a static-duration string
|
||||
describing a new locale or returns a null pointer (if the new locale
|
||||
cannot be selected). The value of <CODE>category</CODE>
|
||||
selects one or more
|
||||
<A HREF="#locale category">locale categories</A>,
|
||||
each of which must match the value
|
||||
of one of the macros defined in this standard header with names that
|
||||
begin with <CODE>LC_</CODE>.</P>
|
||||
|
||||
<P>If <CODE>locale</CODE> is a null pointer, the locale remains unchanged.
|
||||
If <CODE>locale</CODE> points to the string <CODE>"C"</CODE>,
|
||||
the new locale is the
|
||||
<A HREF="#C locale"><CODE>"C"</CODE></A> locale
|
||||
for the locale category specified. If <CODE>locale</CODE>
|
||||
points to the string <CODE>""</CODE>, the new locale is the
|
||||
<B><A NAME="native locale">native locale</A></B>
|
||||
(a default locale presumably tailored for the local culture)
|
||||
for the locale category specified.
|
||||
<CODE>locale</CODE> can also point to a string
|
||||
returned on an earlier call to <CODE>setlocale</CODE> or to other strings
|
||||
that the implementation can define.</P>
|
||||
|
||||
<P>At
|
||||
<A HREF="lib_over.html#program startup" tppabs="http://ccs.ucsd.edu/c/lib_over.html#program startup">program startup</A>,
|
||||
the target environment calls <CODE>setlocale(
|
||||
<A HREF="#LC_ALL">LC_ALL</A>,
|
||||
"C")</CODE> before it calls <CODE>main</CODE>.</P>
|
||||
|
||||
<HR>
|
||||
<P>See also the
|
||||
<B><A HREF="index.html#Table of Contents" tppabs="http://ccs.ucsd.edu/c/index.html#Table of Contents">Table of Contents</A></B> and the
|
||||
<B><A HREF="_index.html" tppabs="http://ccs.ucsd.edu/c/_index.html">Index</A></B>.</P>
|
||||
|
||||
<P><I>
|
||||
<A HREF="crit_pb.html" tppabs="http://ccs.ucsd.edu/c/crit_pb.html">Copyright</A> © 1989-1996
|
||||
by P.J. Plauger and Jim Brodie. All rights reserved.</I></P>
|
||||
|
||||
</BODY></HTML>
|
||||
641
study/Ref-docs/C/math.html
Normal file
@@ -0,0 +1,641 @@
|
||||
<HTML><HEAD><TITLE><math.h></TITLE></HEAD><BODY BGCOLOR="#FFFFFF">
|
||||
|
||||
<H1><A NAME="<math.h>"><CODE><math.h></CODE></A></H1><HR>
|
||||
|
||||
<P><CODE>
|
||||
#define <A HREF="#HUGE_VAL"><B>HUGE_VAL</B></A>
|
||||
<I><double rvalue></I><BR>
|
||||
double <A HREF="#abs"><B>abs</B></A>(double x);
|
||||
<B>[C++ only]</B><BR>
|
||||
float <A HREF="#abs"><B>abs</B></A>(float x);
|
||||
<B>[C++ only]</B><BR>
|
||||
long double <A HREF="#abs"><B>abs</B></A>(long double x);
|
||||
<B>[C++ only]</B><BR>
|
||||
double <A HREF="#acos"><B>acos</B></A>(double x);<BR>
|
||||
float <A HREF="#acos"><B>acos</B></A>(float x);
|
||||
<B>[C++ only]</B><BR>
|
||||
long double <A HREF="#acos"><B>acos</B></A>(long double x);
|
||||
<B>[C++ only]</B><BR>
|
||||
float <A HREF="#acosf"><B>acosf</B></A>(float x);
|
||||
<B>[optional]</B><BR>
|
||||
long double <A HREF="#acosl"><B>acosl</B></A>(long double x);
|
||||
<B>[optional]</B><BR>
|
||||
double <A HREF="#asin"><B>asin</B></A>(double x);<BR>
|
||||
float <A HREF="#asin"><B>asin</B></A>(float x);
|
||||
<B>[C++ only]</B><BR>
|
||||
long double <A HREF="#asin"><B>asin</B></A>(long double x);
|
||||
<B>[C++ only]</B><BR>
|
||||
float <A HREF="#asinf"><B>asinf</B></A>(float x);
|
||||
<B>[optional]</B><BR>
|
||||
long double <A HREF="#asinl"><B>asinl</B></A>(long double x);
|
||||
<B>[optional]</B><BR>
|
||||
double <A HREF="#atan"><B>atan</B></A>(double x);<BR>
|
||||
float <A HREF="#atan"><B>atan</B></A>(float x);
|
||||
<B>[C++ only]</B><BR>
|
||||
long double <A HREF="#atan"><B>atan</B></A>(long double x);
|
||||
<B>[C++ only]</B><BR>
|
||||
float <A HREF="#atanf"><B>atanf</B></A>(float x);
|
||||
<B>[optional]</B><BR>
|
||||
long double <A HREF="#atanl"><B>atanl</B></A>(long double x);
|
||||
<B>[optional]</B><BR>
|
||||
double <A HREF="#atan2"><B>atan2</B></A>(double y, double x);<BR>
|
||||
float <A HREF="#atan2"><B>atan2</B></A>(float y, float x);
|
||||
<B>[C++ only]</B><BR>
|
||||
long double <A HREF="#atan2"><B>atan2</B></A>(long double y,
|
||||
long double x); <B>[C++ only]</B><BR>
|
||||
float <A HREF="#atan2f"><B>atan2f</B></A>(float y, float x);
|
||||
<B>[optional]</B><BR>
|
||||
long double <A HREF="#atan2l"><B>atan2l</B></A>(long double y,
|
||||
long double x); <B>[optional]</B><BR>
|
||||
double <A HREF="#ceil"><B>ceil</B></A>(double x);<BR>
|
||||
float <A HREF="#ceil"><B>ceil</B></A>(float x);
|
||||
<B>[C++ only]</B><BR>
|
||||
long double <A HREF="#ceil"><B>ceil</B></A>(long double x);
|
||||
<B>[C++ only]</B><BR>
|
||||
float <A HREF="#ceilf"><B>ceilf</B></A>(float x);
|
||||
<B>[optional]</B><BR>
|
||||
long double <A HREF="#ceill"><B>ceill</B></A>(long double x);
|
||||
<B>[optional]</B><BR>
|
||||
double <A HREF="#cos"><B>cos</B></A>(double x);<BR>
|
||||
float <A HREF="#cos"><B>cos</B></A>(float x);
|
||||
<B>[C++ only]</B><BR>
|
||||
long double <A HREF="#cos"><B>cos</B></A>(long double x);
|
||||
<B>[C++ only]</B><BR>
|
||||
float <A HREF="#cosf"><B>cosf</B></A>(float x);
|
||||
<B>[optional]</B><BR>
|
||||
long double <A HREF="#cosl"><B>cosl</B></A>(long double x);
|
||||
<B>[optional]</B><BR>
|
||||
double <A HREF="#cosh"><B>cosh</B></A>(double x);<BR>
|
||||
float <A HREF="#cosh"><B>cosh</B></A>(float x);
|
||||
<B>[C++ only]</B><BR>
|
||||
long double <A HREF="#cosh"><B>cosh</B></A>(long double x);
|
||||
<B>[C++ only]</B><BR>
|
||||
float <A HREF="#coshf"><B>coshf</B></A>(float x);
|
||||
<B>[optional]</B><BR>
|
||||
long double <A HREF="#coshl"><B>coshl</B></A>(long double x);
|
||||
<B>[optional]</B><BR>
|
||||
double <A HREF="#exp"><B>exp</B></A>(double x);<BR>
|
||||
float <A HREF="#exp"><B>exp</B></A>(float x);
|
||||
<B>[C++ only]</B><BR>
|
||||
long double <A HREF="#exp"><B>exp</B></A>(long double x);
|
||||
<B>[C++ only]</B><BR>
|
||||
float <A HREF="#expf"><B>expf</B></A>(float x);
|
||||
<B>[optional]</B><BR>
|
||||
long double <A HREF="#expl"><B>expl</B></A>(long double x);
|
||||
<B>[optional]</B><BR>
|
||||
double <A HREF="#fabs"><B>fabs</B></A>(double x);<BR>
|
||||
float <A HREF="#fabs"><B>fabs</B></A>(float x);
|
||||
<B>[C++ only]</B><BR>
|
||||
long double <A HREF="#fabs"><B>fabs</B></A>(long double x);
|
||||
<B>[C++ only]</B><BR>
|
||||
float <A HREF="#fabsf"><B>fabsf</B></A>(float x);
|
||||
<B>[optional]</B><BR>
|
||||
long double <A HREF="#fabsl"><B>fabsl</B></A>(long double x);
|
||||
<B>[optional]</B><BR>
|
||||
double <A HREF="#floor"><B>floor</B></A>(double x);<BR>
|
||||
float <A HREF="#floor"><B>floor</B></A>(float x);
|
||||
<B>[C++ only]</B><BR>
|
||||
long double <A HREF="#floor"><B>floor</B></A>(long double x);
|
||||
<B>[C++ only]</B><BR>
|
||||
float <A HREF="#floorf"><B>floorf</B></A>(float x);
|
||||
<B>[optional]</B><BR>
|
||||
long double <A HREF="#floorl"><B>floorl</B></A>(long double x);
|
||||
<B>[optional]</B><BR>
|
||||
double <A HREF="#fmod"><B>fmod</B></A>(double x, double y);<BR>
|
||||
float <A HREF="#fmod"><B>fmod</B></A>(float x, float y);
|
||||
<B>[C++ only]</B><BR>
|
||||
long double <A HREF="#fmod"><B>fmod</B></A>(long double x,
|
||||
long double y); <B>[C++ only]</B><BR>
|
||||
float <A HREF="#fmodf"><B>fmodf</B></A>(float x, float y);
|
||||
<B>[optional]</B><BR>
|
||||
long double <A HREF="#fmodl"><B>fmodl</B></A>(long double x,
|
||||
long double y); <B>[optional]</B><BR>
|
||||
double <A HREF="#frexp"><B>frexp</B></A>(double x, int *pexp);<BR>
|
||||
float <A HREF="#frexp"><B>frexp</B></A>(float x, int *pexp);
|
||||
<B>[C++ only]</B><BR>
|
||||
long double <A HREF="#frexp"><B>frexp</B></A>(long double x,
|
||||
int *pexp); <B>[C++ only]</B><BR>
|
||||
float <A HREF="#frexpf"><B>frexpf</B></A>(float x, int *pexp);
|
||||
<B>[optional]</B><BR>
|
||||
long double <A HREF="#frexpl"><B>frexpl</B></A>(long double x,
|
||||
int *pexp); <B>[optional]</B><BR>
|
||||
double <A HREF="#ldexp"><B>ldexp</B></A>(double x, int exp);<BR>
|
||||
float <A HREF="#ldexp"><B>ldexp</B></A>(float x, int exp);
|
||||
<B>[C++ only]</B><BR>
|
||||
long double <A HREF="#ldexp"><B>ldexp</B></A>(long double x,
|
||||
int exp); <B>[C++ only]</B><BR>
|
||||
float <A HREF="#ldexpf"><B>ldexpf</B></A>(float x, int exp);
|
||||
<B>[optional]</B><BR>
|
||||
long double <A HREF="#ldexpl"><B>ldexpl</B></A>(long double x,
|
||||
int exp); <B>[optional]</B><BR>
|
||||
double <A HREF="#log"><B>log</B></A>(double x);<BR>
|
||||
float <A HREF="#log"><B>log</B></A>(float x);
|
||||
<B>[C++ only]</B><BR>
|
||||
long double <A HREF="#log"><B>log</B></A>(long double x);
|
||||
<B>[C++ only]</B><BR>
|
||||
float <A HREF="#logf"><B>logf</B></A>(float x);
|
||||
<B>[optional]</B><BR>
|
||||
long double <A HREF="#logl"><B>logl</B></A>(long double x);
|
||||
<B>[optional]</B><BR>
|
||||
double <A HREF="#log10"><B>log10</B></A>(double x);<BR>
|
||||
float <A HREF="#log10"><B>log10</B></A>(float x);
|
||||
<B>[C++ only]</B><BR>
|
||||
long double <A HREF="#log10"><B>log10</B></A>(long double x);
|
||||
<B>[C++ only]</B><BR>
|
||||
float <A HREF="#log10f"><B>log10f</B></A>(float x);
|
||||
<B>[optional]</B><BR>
|
||||
long double <A HREF="#log10l"><B>log10l</B></A>(long double x);
|
||||
<B>[optional]</B><BR>
|
||||
double <A HREF="#modf"><B>modf</B></A>(double x, double *pint);<BR>
|
||||
float <A HREF="#modf"><B>modf</B></A>(float x, float *pint);
|
||||
<B>[C++ only]</B><BR>
|
||||
long double <A HREF="#modf"><B>modf</B></A>(long double x,
|
||||
long double *pint); <B>[C++ only]</B><BR>
|
||||
float <A HREF="#modff"><B>modff</B></A>(float x, float *pint);
|
||||
<B>[optional]</B><BR>
|
||||
long double <A HREF="#modfl"><B>modfl</B></A>(long double x,
|
||||
long double *pint); <B>[optional]</B><BR>
|
||||
double <A HREF="#pow"><B>pow</B></A>(double x, double y);<BR>
|
||||
float <A HREF="#pow"><B>pow</B></A>(float x, float y);
|
||||
<B>[C++ only]</B><BR>
|
||||
long double <A HREF="#pow"><B>pow</B></A>(long double x,
|
||||
long double y); <B>[C++ only]</B><BR>
|
||||
double <A HREF="#pow"><B>pow</B></A>(double x, int y);
|
||||
<B>[C++ only]</B><BR>
|
||||
float <A HREF="#pow"><B>pow</B></A>(float x, int y);
|
||||
<B>[C++ only]</B><BR>
|
||||
long double <A HREF="#pow"><B>pow</B></A>(long double x, int y);
|
||||
<B>[C++ only]</B><BR>
|
||||
float <A HREF="#powf"><B>powf</B></A>(float x, float y);
|
||||
<B>[optional]</B><BR>
|
||||
long double <A HREF="#powl"><B>powl</B></A>(long double x,
|
||||
long double y); <B>[optional]</B><BR>
|
||||
double <A HREF="#sin"><B>sin</B></A>(double x);<BR>
|
||||
float <A HREF="#sin"><B>sin</B></A>(float x);
|
||||
<B>[C++ only]</B><BR>
|
||||
long double <A HREF="#sin"><B>sin</B></A>(long double x);
|
||||
<B>[C++ only]</B><BR>
|
||||
float <A HREF="#sinf"><B>sinf</B></A>(float x);
|
||||
<B>[optional]</B><BR>
|
||||
long double <A HREF="#sinl"><B>sinl</B></A>(long double x);
|
||||
<B>[optional]</B><BR>
|
||||
double <A HREF="#sinh"><B>sinh</B></A>(double x);<BR>
|
||||
float <A HREF="#sinh"><B>sinh</B></A>(float x);
|
||||
<B>[C++ only]</B><BR>
|
||||
long double <A HREF="#sinh"><B>sinh</B></A>(long double x);
|
||||
<B>[C++ only]</B><BR>
|
||||
float <A HREF="#sinhf"><B>sinhf</B></A>(float x);
|
||||
<B>[optional]</B><BR>
|
||||
long double <A HREF="#sinhl"><B>sinhl</B></A>(long double x);
|
||||
<B>[optional]</B><BR>
|
||||
double <A HREF="#sqrt"><B>sqrt</B></A>(double x);<BR>
|
||||
float <A HREF="#sqrt"><B>sqrt</B></A>(float x);
|
||||
<B>[C++ only]</B><BR>
|
||||
long double <A HREF="#sqrt"><B>sqrt</B></A>(long double x);
|
||||
<B>[C++ only]</B><BR>
|
||||
float <A HREF="#sqrtf"><B>sqrtf</B></A>(float x);
|
||||
<B>[optional]</B><BR>
|
||||
long double <A HREF="#sqrtl"><B>sqrtl</B></A>(long double x);
|
||||
<B>[optional]</B><BR>
|
||||
double <A HREF="#tan"><B>tan</B></A>(double x);<BR>
|
||||
float <A HREF="#tan"><B>tan</B></A>(float x);
|
||||
<B>[C++ only]</B><BR>
|
||||
long double <A HREF="#tan"><B>tan</B></A>(long double x);
|
||||
<B>[C++ only]</B><BR>
|
||||
float <A HREF="#tanf"><B>tanf</B></A>(float x);
|
||||
<B>[optional]</B><BR>
|
||||
long double <A HREF="#tanl"><B>tanl</B></A>(long double x);
|
||||
<B>[optional]</B><BR>
|
||||
double <A HREF="#tanh"><B>tanh</B></A>(double x);<BR>
|
||||
float <A HREF="#tanh"><B>tanh</B></A>(float x);
|
||||
<B>[C++ only]</B><BR>
|
||||
long double <A HREF="#tanh"><B>tanh</B></A>(long double x);
|
||||
<B>[C++ only]</B><BR>
|
||||
float <A HREF="#tanhf"><B>tanhf</B></A>(float x);
|
||||
<B>[optional]</B><BR>
|
||||
long double <A HREF="#tanhl"><B>tanhl</B></A>(long double x);
|
||||
<B>[optional]</B>
|
||||
</CODE></P>
|
||||
|
||||
<P>Include the standard header <B><CODE><math.h></CODE></B>
|
||||
to declare several functions that perform
|
||||
common mathematical operations on floating-point values.</P>
|
||||
|
||||
<P>A <B><A NAME="domain error">domain error</A></B>
|
||||
exception occurs when the function is
|
||||
not defined for its input argument value or values. A function reports
|
||||
a domain error by storing the value of
|
||||
<A HREF="errno.html#EDOM" tppabs="http://ccs.ucsd.edu/c/errno.html#EDOM"><CODE>EDOM</CODE></A> in
|
||||
<A HREF="errno.html#errno" tppabs="http://ccs.ucsd.edu/c/errno.html#errno"><CODE>errno</CODE></A>
|
||||
and returning a peculiar value defined for each implementation.</P>
|
||||
|
||||
<P>A <B><A NAME="range error">range error</A></B>
|
||||
exception occurs when the return value of the
|
||||
function is defined but cannot be represented.
|
||||
A function reports a range error by storing the value of
|
||||
<A HREF="errno.html#ERANGE" tppabs="http://ccs.ucsd.edu/c/errno.html#ERANGE"><CODE>ERANGE</CODE></A> in
|
||||
<A HREF="errno.html#errno" tppabs="http://ccs.ucsd.edu/c/errno.html#errno"><CODE>errno</CODE></A>
|
||||
and returning one of three values:</P>
|
||||
|
||||
<UL>
|
||||
<LI><A HREF="#HUGE_VAL"><CODE>HUGE_VAL</CODE></A>
|
||||
-- if the value of a function returning <I>double</I> is positive
|
||||
and too large in magnitude to represent
|
||||
|
||||
<LI>zero -- if the value of the function is too small to represent
|
||||
with a finite value
|
||||
|
||||
<LI><A HREF="#HUGE_VAL"><CODE>-HUGE_VAL</CODE></A>
|
||||
-- if the value of a function returning <I>double</I> is negative
|
||||
and too large in magnitude to represent
|
||||
</UL>
|
||||
|
||||
<H2><A NAME="HUGE_VAL"><CODE>HUGE_VAL</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
#define <B>HUGE_VAL</B> <I><double rvalue></I>
|
||||
</CODE></P>
|
||||
|
||||
<P>The macro yields the value returned by some functions on a range
|
||||
error. The value can be a representation of infinity.</P>
|
||||
|
||||
<H2><A NAME="abs"><CODE>abs</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
double <B>abs</B>(double x); <B>[C++ only]</B><BR>
|
||||
float <B>abs</B>(float x); <B>[C++ only]</B><BR>
|
||||
long double <B>abs</B>(long double x); <B>[C++ only]</B>
|
||||
</CODE></P>
|
||||
|
||||
<P>The function returns the absolute value of <CODE>x</CODE>,
|
||||
<CODE>|x|</CODE>, the same as
|
||||
<A HREF="#fabs"><CODE>fabs</CODE></A>.</P>
|
||||
|
||||
<H2><A NAME="acos"><CODE>acos</CODE></A>,
|
||||
<A NAME="acosf"><CODE>acosf</CODE></A>,
|
||||
<A NAME="acosl"><CODE>acosl</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
double <B>acos</B>(double x);<BR>
|
||||
float <B>acos</B>(float x); <B>[C++ only]</B><BR>
|
||||
long double <B>acos</B>(long double x); <B>[C++ only]</B><BR>
|
||||
float <B>acosf</B>(float x); <B>[optional]</B><BR>
|
||||
long double <B>acosl</B>(long double x); <B>[optional]</B>
|
||||
</CODE></P>
|
||||
|
||||
<P>The function returns the angle whose cosine is <CODE>x</CODE>, in
|
||||
the range [0, pi] radians.</P>
|
||||
|
||||
<H2><A NAME="asin"><CODE>asin</CODE></A>,
|
||||
<A NAME="asinf"><CODE>asinf</CODE></A>,
|
||||
<A NAME="asinl"><CODE>asinl</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
double <B>asin</B>(double x);<BR>
|
||||
float <B>asin</B>(float x); <B>[C++ only]</B><BR>
|
||||
long double <B>asin</B>(long double x); <B>[C++ only]</B><BR>
|
||||
float <B>asinf</B>(float x); <B>[optional]</B><BR>
|
||||
long double <B>asinl</B>(long double x); <B>[optional]</B>
|
||||
</CODE></P>
|
||||
|
||||
<P>The function returns the angle whose sine is <CODE>x</CODE>, in the
|
||||
range [-pi/2, +pi/2] radians.</P>
|
||||
|
||||
<H2><A NAME="atan"><CODE>atan</CODE></A>,
|
||||
<A NAME="atanf"><CODE>atanf</CODE></A>,
|
||||
<A NAME="atanl"><CODE>atanl</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
double <B>atan</B>(double x);<BR>
|
||||
float <B>atan</B>(float x); <B>[C++ only]</B><BR>
|
||||
long double <B>atan</B>(long double x); <B>[C++ only]</B><BR>
|
||||
float <B>atanf</B>(float x); <B>[optional]</B><BR>
|
||||
long double <B>atanl</B>(long double x); <B>[optional]</B>
|
||||
</CODE></P>
|
||||
|
||||
<P>The function returns the angle whose tangent is <CODE>x</CODE>, in
|
||||
the range [-pi/2, +pi/2] radians.</P>
|
||||
|
||||
<H2><A NAME="atan2"><CODE>atan2</CODE></A>,
|
||||
<A NAME="atan2f"><CODE>atan2f</CODE></A>,
|
||||
<A NAME="atan2l"><CODE>atan2l</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
double <B>atan2</B>(double y, double x);<BR>
|
||||
float <B>atan2</B>(float y, float x); <B>[C++ only]</B><BR>
|
||||
long double <B>atan2</B>(long double y, long double x); <B>[C++ only]</B><BR>
|
||||
float <B>atan2f</B>(float y, float x); <B>[optional]</B><BR>
|
||||
long double <B>atan2l</B>(long double y, long double x); <B>[optional]</B>
|
||||
</CODE></P>
|
||||
|
||||
<P>The function returns the angle whose tangent is <CODE>y/x</CODE>,
|
||||
in the full angular range [-pi, +pi] radians.</P>
|
||||
|
||||
<H2><A NAME="ceil"><CODE>ceil</CODE></A>,
|
||||
<A NAME="ceilf"><CODE>ceilf</CODE></A>,
|
||||
<A NAME="ceill"><CODE>ceill</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
double <B>ceil</B>(double x);<BR>
|
||||
float <B>ceil</B>(float x); <B>[C++ only]</B><BR>
|
||||
long double <B>ceil</B>(long double x); <B>[C++ only]</B><BR>
|
||||
float <B>ceilf</B>(float x); <B>[optional]</B><BR>
|
||||
long double <B>ceill</B>(long double x); <B>[optional]</B>
|
||||
</CODE></P>
|
||||
|
||||
<P>The function returns the smallest integer value not less than
|
||||
<CODE>x</CODE>.</P>
|
||||
|
||||
<H2><A NAME="cos"><CODE>cos</CODE></A>,
|
||||
<A NAME="cosf"><CODE>cosf</CODE></A>,
|
||||
<A NAME="cosl"><CODE>cosl</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
double <B>cos</B>(double x);<BR>
|
||||
float <B>cos</B>(float x); <B>[C++ only]</B><BR>
|
||||
long double <B>cos</B>(long double x); <B>[C++ only]</B><BR>
|
||||
float <B>cosf</B>(float x); <B>[optional]</B><BR>
|
||||
long double <B>cosl</B>(long double x); <B>[optional]</B>
|
||||
</CODE></P>
|
||||
|
||||
<P>The function returns the cosine of <CODE>x</CODE> for <CODE>x</CODE> in
|
||||
radians. If <CODE>x</CODE> is large the value returned
|
||||
might not be meaningful, but the function reports no error.</P>
|
||||
|
||||
<H2><A NAME="cosh"><CODE>cosh</CODE></A>,
|
||||
<A NAME="coshf"><CODE>coshf</CODE></A>,
|
||||
<A NAME="coshl"><CODE>coshl</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
double <B>cosh</B>(double x);<BR>
|
||||
float <B>cosh</B>(float x); <B>[C++ only]</B><BR>
|
||||
long double <B>cosh</B>(long double x); <B>[C++ only]</B><BR>
|
||||
float <B>coshf</B>(float x); <B>[optional]</B><BR>
|
||||
long double <B>coshl</B>(long double x); <B>[optional]</B>
|
||||
</CODE></P>
|
||||
|
||||
<P>The function returns the hyperbolic cosine of <CODE>x</CODE>.</P>
|
||||
|
||||
<H2><A NAME="exp"><CODE>exp</CODE></A>,
|
||||
<A NAME="expf"><CODE>expf</CODE></A>,
|
||||
<A NAME="expl"><CODE>expl</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
double <B>exp</B>(double x);<BR>
|
||||
float <B>exp</B>(float x); <B>[C++ only]</B><BR>
|
||||
long double <B>exp</B>(long double x); <B>[C++ only]</B><BR>
|
||||
float <B>expf</B>(float x); <B>[optional]</B><BR>
|
||||
long double <B>expl</B>(long double x); <B>[optional]</B>
|
||||
</CODE></P>
|
||||
|
||||
<P>The function returns the exponential of <CODE>x</CODE>,
|
||||
e^<CODE>x</CODE>.</P>
|
||||
|
||||
<H2><A NAME="fabs"><CODE>fabs</CODE></A>,
|
||||
<A NAME="fabsf"><CODE>fabsf</CODE></A>,
|
||||
<A NAME="fabsl"><CODE>fabsl</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
double <B>fabs</B>(double x);<BR>
|
||||
float <B>fabs</B>(float x); <B>[C++ only]</B><BR>
|
||||
long double <B>fabs</B>(long double x); <B>[C++ only]</B><BR>
|
||||
float <B>fabsf</B>(float x); <B>[optional]</B><BR>
|
||||
long double <B>fabsl</B>(long double x); <B>[optional]</B>
|
||||
</CODE></P>
|
||||
|
||||
<P>The function returns the absolute value of <CODE>x</CODE>,
|
||||
<CODE>|x|</CODE>, the same as
|
||||
<A HREF="#abs"><CODE>abs</CODE></A>.</P>
|
||||
|
||||
<H2><A NAME="floor"><CODE>floor</CODE></A>,
|
||||
<A NAME="floorf"><CODE>floorf</CODE></A>,
|
||||
<A NAME="floorl"><CODE>floorl</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
double <B>floor</B>(double x);<BR>
|
||||
float <B>floor</B>(float x); <B>[C++ only]</B><BR>
|
||||
long double <B>floor</B>(long double x); <B>[C++ only]</B><BR>
|
||||
float <B>floorf</B>(float x); <B>[optional]</B><BR>
|
||||
long double <B>floorl</B>(long double x); <B>[optional]</B>
|
||||
</CODE></P>
|
||||
|
||||
<P>The function returns the largest integer value not greater than
|
||||
<CODE>x</CODE>.</P>
|
||||
|
||||
<H2><A NAME="fmod"><CODE>fmod</CODE></A>,
|
||||
<A NAME="fmodf"><CODE>fmodf</CODE></A>,
|
||||
<A NAME="fmodl"><CODE>fmodl</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
double <B>fmod</B>(double x, double y);<BR>
|
||||
float <B>fmod</B>(float x, float y); <B>[C++ only]</B><BR>
|
||||
long double <B>fmod</B>(long double x, long double y); <B>[C++ only]</B><BR>
|
||||
float <B>fmodf</B>(float x, float y); <B>[optional]</B><BR>
|
||||
long double <B>fmodl</B>(long double x, long double y); <B>[optional]</B>
|
||||
</CODE></P>
|
||||
|
||||
<P>The function returns the remainder of <CODE>x/y</CODE>,
|
||||
which is defined as follows:</P>
|
||||
|
||||
<UL>
|
||||
<LI>If <CODE>y</CODE> is zero,
|
||||
the function either reports a domain error or simply returns zero.
|
||||
|
||||
<LI>Otherwise, if <CODE>0 <= x</CODE>,
|
||||
the value is <CODE>x - i*y</CODE>
|
||||
for some integer <CODE>i</CODE> such that:<BR>
|
||||
<CODE>0 <= i*|y| <= x < (i + 1)*|y|</CODE>
|
||||
|
||||
<LI>Otherwise, <CODE>x < 0</CODE>
|
||||
and the value is <CODE>x - i*y</CODE>
|
||||
for some integer <CODE>i</CODE> such that:<BR>
|
||||
<CODE>i*|y| <= x < (i + 1)*|y| <= 0</CODE>
|
||||
</UL>
|
||||
|
||||
<H2><A NAME="frexp"><CODE>frexp</CODE></A>,
|
||||
<A NAME="frexpf"><CODE>frexpf</CODE></A>,
|
||||
<A NAME="frexpl"><CODE>frexpl</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
double <B>frexp</B>(double x, int *pexp);<BR>
|
||||
float <B>frexp</B>(float x, int *pexp); <B>[C++ only]</B><BR>
|
||||
long double <B>frexp</B>(long double x, int *pexp); <B>[C++ only]</B><BR>
|
||||
float <B>frexpf</B>(float x, int *pexp); <B>[optional]</B><BR>
|
||||
long double <B>frexpl</B>(long double x, int *pexp); <B>[optional]</B>
|
||||
</CODE></P>
|
||||
|
||||
<P>The function determines a fraction <CODE>f</CODE> and base-2 integer
|
||||
<CODE>i</CODE> that represent the value of <CODE>x</CODE>.
|
||||
It returns the value <CODE>f</CODE> and stores the integer
|
||||
<CODE>i</CODE> in <CODE>*pexp</CODE>, such that
|
||||
<CODE>|f|</CODE> is in the interval [1/2, 1) or has the value 0,
|
||||
and <CODE>x</CODE> equals <CODE>f*2^i</CODE>.
|
||||
If <CODE>x</CODE> is zero, <CODE>*pexp</CODE> is also zero.</P>
|
||||
|
||||
<H2><A NAME="ldexp"><CODE>ldexp</CODE></A>,
|
||||
<A NAME="ldexpf"><CODE>ldexpf</CODE></A>,
|
||||
<A NAME="ldexpl"><CODE>ldexpl</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
double <B>ldexp</B>(double x, int exp);<BR>
|
||||
float <B>ldexp</B>(float x, int exp); <B>[C++ only]</B><BR>
|
||||
long double <B>ldexp</B>(long double x, int exp); <B>[C++ only]</B><BR>
|
||||
float <B>ldexpf</B>(float x, int exp); <B>[optional]</B><BR>
|
||||
long double <B>ldexpl</B>(long double x, int exp); <B>[optional]</B>
|
||||
</CODE></P>
|
||||
|
||||
<P>The function returns <CODE>x*2^exp</CODE>.</P>
|
||||
|
||||
<H2><A NAME="log"><CODE>log</CODE></A>,
|
||||
<A NAME="logf"><CODE>logf</CODE></A>,
|
||||
<A NAME="logl"><CODE>logl</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
double <B>log</B>(double x);<BR>
|
||||
float <B>log</B>(float x); <B>[C++ only]</B><BR>
|
||||
long double <B>log</B>(long double x); <B>[C++ only]</B><BR>
|
||||
float <B>logf</B>(float x); <B>[optional]</B><BR>
|
||||
long double <B>logl</B>(long double x); <B>[optional]</B>
|
||||
</CODE></P>
|
||||
|
||||
<P>The function returns the natural logarithm of <CODE>x</CODE>.</P>
|
||||
|
||||
<H2><A NAME="log10"><CODE>log10</CODE></A>,
|
||||
<A NAME="log10f"><CODE>log10f</CODE></A>,
|
||||
<A NAME="log10l"><CODE>log10l</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
double <B>log10</B>(double x);<BR>
|
||||
float <B>log10</B>(float x); <B>[C++ only]</B><BR>
|
||||
long double <B>log10</B>(long double x); <B>[C++ only]</B><BR>
|
||||
float <B>log10f</B>(float x); <B>[optional]</B><BR>
|
||||
long double <B>log10l</B>(long double x); <B>[optional]</B>
|
||||
</CODE></P>
|
||||
|
||||
<P>The function returns the base-10 logarithm of <CODE>x</CODE>.</P>
|
||||
|
||||
<H2><A NAME="modf"><CODE>modf</CODE></A>,
|
||||
<A NAME="modff"><CODE>modff</CODE></A>,
|
||||
<A NAME="modfl"><CODE>modfl</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
double <B>modf</B>(double x, double *pint);<BR>
|
||||
float <B>modf</B>(float x, float *pint); <B>[C++ only]</B><BR>
|
||||
long double <B>modf</B>(long double x, long double *pint); <B>[C++ only]</B><BR>
|
||||
float <B>modff</B>(float x, float *pint); <B>[optional]</B><BR>
|
||||
long double <B>modfl</B>(long double x, long double *pint); <B>[optional]</B>
|
||||
</CODE></P>
|
||||
|
||||
<P>The function determines an integer <CODE>i</CODE> plus a fraction
|
||||
<CODE>f</CODE> that represent the value of <CODE>x</CODE>.
|
||||
It returns the value <CODE>f</CODE> and stores the integer
|
||||
<CODE>i</CODE> in <CODE>*pint</CODE>, such that
|
||||
<CODE>f + i == x</CODE>, <CODE>|f| is in the interval [0, 1),
|
||||
and both <CODE>f</CODE> and <CODE>i</CODE> have the
|
||||
same sign as <CODE>x</CODE>.</P>
|
||||
|
||||
<H2><A NAME="pow"><CODE>pow</CODE></A>,
|
||||
<A NAME="powf"><CODE>powf</CODE></A>,
|
||||
<A NAME="powl"><CODE>powl</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
double <B>pow</B>(double x, double y);<BR>
|
||||
float <B>pow</B>(float x, float y); <B>[C++ only]</B><BR>
|
||||
long double <B>pow</B>(long double x, long double y); <B>[C++ only]</B><BR>
|
||||
double <B>pow</B>(double x, int y); <B>[C++ only]</B><BR>
|
||||
float <B>pow</B>(float x, int y); <B>[C++ only]</B><BR>
|
||||
long double <B>pow</B>(long double x, int y); <B>[C++ only]</B><BR>
|
||||
float <B>powf</B>(float x, float y); <B>[optional]</B><BR>
|
||||
long double <B>powl</B>(long double x, long double y); <B>[optional]</B>
|
||||
</CODE></P>
|
||||
|
||||
<P>The function returns <CODE>x</CODE> raised to the power <CODE>y</CODE>,
|
||||
<CODE>x^y</CODE>.</P>
|
||||
|
||||
<H2><A NAME="sin"><CODE>sin</CODE></A>,
|
||||
<A NAME="sinf"><CODE>sinf</CODE></A>,
|
||||
<A NAME="sinl"><CODE>sinl</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
double <B>sin</B>(double x);<BR>
|
||||
float <B>sin</B>(float x); <B>[C++ only]</B><BR>
|
||||
long double <B>sin</B>(long double x); <B>[C++ only]</B><BR>
|
||||
float <B>sinf</B>(float x); <B>[optional]</B><BR>
|
||||
long double <B>sinl</B>(long double x); <B>[optional]</B>
|
||||
</CODE></P>
|
||||
|
||||
<P>The function returns the sine of <CODE>x</CODE>
|
||||
for <CODE>x</CODE> in radians. If <CODE>x</CODE> is large
|
||||
the value returned might not be meaningful, but
|
||||
the function reports no error.</P>
|
||||
|
||||
<H2><A NAME="sinh"><CODE>sinh</CODE></A>,
|
||||
<A NAME="sinhf"><CODE>sinhf</CODE></A>,
|
||||
<A NAME="sinhl"><CODE>sinhl</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
double <B>sinh</B>(double x);<BR>
|
||||
float <B>sinh</B>(float x); <B>[C++ only]</B><BR>
|
||||
long double <B>sinh</B>(long double x); <B>[C++ only]</B><BR>
|
||||
float <B>sinhf</B>(float x); <B>[optional]</B><BR>
|
||||
long double <B>sinhl</B>(long double x); <B>[optional]</B>
|
||||
</CODE></P>
|
||||
|
||||
<P>The function returns the hyperbolic sine of <CODE>x</CODE>.</P>
|
||||
|
||||
<H2><A NAME="sqrt"><CODE>sqrt</CODE></A>,
|
||||
<A NAME="sqrtf"><CODE>sqrtf</CODE></A>,
|
||||
<A NAME="sqrtl"><CODE>sqrtl</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
double <B>sqrt</B>(double x);<BR>
|
||||
float <B>sqrt</B>(float x); <B>[C++ only]</B><BR>
|
||||
long double <B>sqrt</B>(long double x); <B>[C++ only]</B><BR>
|
||||
float <B>sqrtf</B>(float x); <B>[optional]</B><BR>
|
||||
long double <B>sqrtl</B>(long double x); <B>[optional]</B>
|
||||
</CODE></P>
|
||||
|
||||
<P>The function returns the square root of <CODE>x</CODE>,
|
||||
<CODE>x^(1/2)</CODE>.</P>
|
||||
|
||||
<H2><A NAME="tan"><CODE>tan</CODE></A>,
|
||||
<A NAME="tanf"><CODE>tanf</CODE></A>,
|
||||
<A NAME="tanl"><CODE>tanl</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
double <B>tan</B>(double x);<BR>
|
||||
float <B>tan</B>(float x); <B>[C++ only]</B><BR>
|
||||
long double <B>tan</B>(long double x); <B>[C++ only]</B><BR>
|
||||
float <B>tanf</B>(float x); <B>[optional]</B><BR>
|
||||
long double <B>tanl</B>(long double x); <B>[optional]</B>
|
||||
</CODE></P>
|
||||
|
||||
<P>The function returns the tangent of <CODE>x</CODE> for <CODE>x</CODE> in
|
||||
radians.If <CODE>x</CODE> is large the value returned
|
||||
might not be meaningful,
|
||||
but the function reports no error.</P>
|
||||
|
||||
<H2><A NAME="tanh"><CODE>tanh</CODE></A>,
|
||||
<A NAME="tanhf"><CODE>tanhf</CODE></A>,
|
||||
<A NAME="tanhl"><CODE>tanhl</CODE></A></H2>
|
||||
|
||||
<P><CODE>
|
||||
double <B>tanh</B>(double x);<BR>
|
||||
float <B>tanh</B>(float x); <B>[C++ only]</B><BR>
|
||||
long double <B>tanh</B>(long double x); <B>[C++ only]</B><BR>
|
||||
float <B>tanhf</B>(float x); <B>[optional]</B><BR>
|
||||
long double <B>tanhl</B>(long double x); <B>[optional]</B>
|
||||
</CODE></P>
|
||||
|
||||
<P>The function returns the hyperbolic tangent of <CODE>x</CODE>.</P>
|
||||
|
||||
<HR>
|
||||
<P>See also the
|
||||
<B><A HREF="index.html#Table of Contents" tppabs="http://ccs.ucsd.edu/c/index.html#Table of Contents">Table of Contents</A></B> and the
|
||||
<B><A HREF="_index.html" tppabs="http://ccs.ucsd.edu/c/_index.html">Index</A></B>.</P>
|
||||
|
||||
<P><I>
|
||||
<A HREF="crit_pb.html" tppabs="http://ccs.ucsd.edu/c/crit_pb.html">Copyright</A> © 1989-1996
|
||||
by P.J. Plauger and Jim Brodie. All rights reserved.</I></P>
|
||||
|
||||
</BODY></HTML>
|
||||
BIN
study/Ref-docs/C/member_d.gif
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
BIN
study/Ref-docs/C/name.gif
Normal file
|
After Width: | Height: | Size: 845 B |
BIN
study/Ref-docs/C/namesp.gif
Normal file
|
After Width: | Height: | Size: 3.9 KiB |
BIN
study/Ref-docs/C/null.gif
Normal file
|
After Width: | Height: | Size: 480 B |
BIN
study/Ref-docs/C/null_f.gif
Normal file
|
After Width: | Height: | Size: 225 B |
BIN
study/Ref-docs/C/null_s.gif
Normal file
|
After Width: | Height: | Size: 402 B |
BIN
study/Ref-docs/C/number.gif
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
study/Ref-docs/C/opt.gif
Normal file
|
After Width: | Height: | Size: 444 B |
BIN
study/Ref-docs/C/outer_d.gif
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
study/Ref-docs/C/param_d.gif
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
743
study/Ref-docs/C/portable.html
Normal file
@@ -0,0 +1,743 @@
|
||||
<HTML><HEAD><TITLE>Portability</TITLE></HEAD><BODY BGCOLOR="#FFFFFF">
|
||||
|
||||
<H1><A NAME="Portability">Portability</A></H1><HR>
|
||||
|
||||
<P><B><A HREF="#Writing Portable Programs">Writing Portable Programs</A>
|
||||
· <A HREF="#Translation-Time Issues">Translation-Time Issues</A>
|
||||
· <A HREF="#Character-Set Issues">Character-Set Issues</A>
|
||||
· <A HREF="#Representation Issues">Representation Issues</A>
|
||||
· <A HREF="#Expression-Evaluation Issues">Expression-Evaluation Issues</A>
|
||||
· <A HREF="#Library Issues">Library Issues</A>
|
||||
· <A HREF="#Converting to Standard C">Converting to Standard C</A>
|
||||
· <A HREF="#Function-Call Issues">Function-Call Issues</A>
|
||||
· <A HREF="#Preprocessing Issues">Preprocessing Issues</A>
|
||||
· <A HREF="#Library Issues">Library Issues</A>
|
||||
· <A HREF="#Quiet Changes">Quiet Changes</A>
|
||||
· <A HREF="#Newer Dialects">Newer Dialects</A>
|
||||
</B></P>
|
||||
<HR>
|
||||
|
||||
<P>A <B>portable</B> program is one that you can move with little
|
||||
or no extra investment of effort to a computer that differs from the
|
||||
one on which you originally developed the program. Writing a program in
|
||||
<A HREF="index.html#Standard C" tppabs="http://ccs.ucsd.edu/c/index.html#Standard C">Standard C</A>
|
||||
does not guarantee that it will be portable. You must
|
||||
be aware of the aspects of the program that can vary among implementations.
|
||||
You can then write the program so that it does not depend critically
|
||||
on implementation-specific aspects.</P>
|
||||
|
||||
<P>This document describes what you must be aware of when writing
|
||||
a portable program. It also tells you what to look for when you alter
|
||||
programs written in older dialects of C so that they behave properly
|
||||
under a Standard C implementation. It briefly
|
||||
summarizes the features added with
|
||||
<A HREF="lib_over.html#Amendment 1" tppabs="http://ccs.ucsd.edu/c/lib_over.html#Amendment 1">Amendment 1</A>
|
||||
to the C Standard. And it suggests ways to
|
||||
write C code that is also valid as C++ code.</P>
|
||||
|
||||
<H2><A NAME="Writing Portable Programs">Writing Portable Programs</A></H2>
|
||||
|
||||
<P>Although the language definition specifies most aspects of Standard
|
||||
C, it intentionally leaves some aspects unspecified. The language
|
||||
definition also permits other aspects to vary among implementations.
|
||||
If the program depends on behavior that is not fully specified or
|
||||
that can vary among implementations, then there is a good chance that
|
||||
you will need to alter the program when you move it to another
|
||||
computer.</P>
|
||||
|
||||
<P>This section identifies issues that affect portability, such
|
||||
as how the translator interprets the program and how the target environment
|
||||
represents files. The list of issues is not complete, but it does
|
||||
include the common issues that you confront when you write a portable
|
||||
program.</P>
|
||||
|
||||
<P>An implementation of Standard C must include a document that
|
||||
describes any behavior that is
|
||||
<B><A NAME="implementation defined">implementation defined</A></B>. You
|
||||
should read this document to be aware of those aspects that can vary,
|
||||
to be alert to behavior that can be peculiar to a particular implementation,
|
||||
and to take advantage of special features in programs that need not
|
||||
be portable.</P>
|
||||
|
||||
<H3><A NAME="Translation-Time Issues">Translation-Time Issues</A></H3>
|
||||
|
||||
<P>A program can depend on peculiar properties of the translator.</P>
|
||||
|
||||
<P>The
|
||||
<A HREF="lib_over.html#filename" tppabs="http://ccs.ucsd.edu/c/lib_over.html#filename">filenames</A> acceptable to an
|
||||
<A HREF="preproc.html#Include Directives" tppabs="http://ccs.ucsd.edu/c/preproc.html#Include Directives"><I>include</I> directive</A> can
|
||||
vary considerably among implementations. If you use filenames that
|
||||
consist of other than six letters (of a single case), followed by
|
||||
a dot (<CODE>.</CODE>), followed by a single letter, then an implementation
|
||||
can find the name unacceptable. Each implementation defines the filenames
|
||||
that you can create.</P>
|
||||
|
||||
<P>How preprocessing uses a filename
|
||||
to locate a file can also vary. Each
|
||||
<A HREF="#implementation defined">implementation defines</A>
|
||||
where you must place files that
|
||||
you want to include with an <I>include</I> directive.</P>
|
||||
|
||||
<P>If you write two or more of the operators <CODE>##</CODE> within a
|
||||
macro definition, the order in which preprocessing
|
||||
<A HREF="preproc.html#Expanding Macros" tppabs="http://ccs.ucsd.edu/c/preproc.html#Expanding Macros">concatenates tokens</A>
|
||||
can vary. If any order produces an invalid preprocessing token as
|
||||
an intermediate result, the program can misbehave when you move it.</P>
|
||||
|
||||
<P>A translator can limit the size and complexity of a program
|
||||
that it can translate. Such limits can also depend on the environment
|
||||
in which the translator executes. Thus, no translation unit you write
|
||||
can assuredly survive all Standard C translators. Obey the following
|
||||
individual limits, however, to ensure the highest probability of success:</P>
|
||||
|
||||
<UL>
|
||||
<LI>Nest statements -- such as
|
||||
<A HREF="function.html#If Statement" tppabs="http://ccs.ucsd.edu/c/function.html#If Statement"><I>if</I></A> and
|
||||
<A HREF="function.html#While Statement" tppabs="http://ccs.ucsd.edu/c/function.html#While Statement"><I>while</I> statements</A>
|
||||
-- no more than fifteen levels deep. The braces surrounding a block
|
||||
add a level of nesting.</LI>
|
||||
|
||||
<LI>Nest
|
||||
<A HREF="preproc.html#Conditional Directives" tppabs="http://ccs.ucsd.edu/c/preproc.html#Conditional Directives">conditional directives</A>
|
||||
-- such as
|
||||
<A HREF="preproc.html#if directive" tppabs="http://ccs.ucsd.edu/c/preproc.html#if directive"><I>if</I></A> and
|
||||
<A HREF="preproc.html#ifdef directive" tppabs="http://ccs.ucsd.edu/c/preproc.html#ifdef directive"><I>ifdef</I> directives</A>
|
||||
-- no more than eight levels deep.</LI>
|
||||
|
||||
<LI>Add no more than twelve decorations -- to derive
|
||||
<A HREF="syntax.html#pointer decoration" tppabs="http://ccs.ucsd.edu/c/syntax.html#pointer decoration">pointer</A>,
|
||||
<A HREF="syntax.html#array decoration" tppabs="http://ccs.ucsd.edu/c/syntax.html#array decoration">array</A>, and
|
||||
<A HREF="syntax.html#function decoration" tppabs="http://ccs.ucsd.edu/c/syntax.html#function decoration">function</A> types --
|
||||
to a declarator.</LI>
|
||||
|
||||
<LI>Write no more than 31 nested pairs of parentheses in a
|
||||
<A HREF="syntax.html#Declarators" tppabs="http://ccs.ucsd.edu/c/syntax.html#Declarators">declarator</A>.</LI>
|
||||
|
||||
<LI>Write no more than 32 nested pairs of parentheses within an
|
||||
<A HREF="syntax.html#Expression Syntax" tppabs="http://ccs.ucsd.edu/c/syntax.html#Expression Syntax">expression</A>.</LI>
|
||||
|
||||
<LI>Ensure that all distinct
|
||||
<A HREF="syntax.html#name" tppabs="http://ccs.ucsd.edu/c/syntax.html#name">names</A> differ in their first 31 characters.
|
||||
Also ensure that all characters match for names that the translator
|
||||
should treat as the same.</LI>
|
||||
|
||||
<LI>Ensure that all
|
||||
<B><A NAME="distinct external names">distinct names</A></B> with
|
||||
<A HREF="declare.html#external linkage" tppabs="http://ccs.ucsd.edu/c/declare.html#external linkage">external linkage</A> differ
|
||||
in the first six characters, even if the translator converts all letters
|
||||
to a single case. Also ensure that all characters match for such names
|
||||
that the translator should treat as the same.</LI>
|
||||
|
||||
<LI>Write no more than 511 distinct names with
|
||||
<A HREF="declare.html#external linkage" tppabs="http://ccs.ucsd.edu/c/declare.html#external linkage">external linkage</A>
|
||||
within a translation unit.</LI>
|
||||
|
||||
<LI>Write no more than 127 distinct names in
|
||||
<A HREF="declare.html#block-level declaration" tppabs="http://ccs.ucsd.edu/c/declare.html#block-level declaration">block-level declarations</A>
|
||||
that share a single name space.</LI>
|
||||
|
||||
<LI>Define no more than 1,024 distinct names as
|
||||
<A HREF="preproc.html#Define Directives" tppabs="http://ccs.ucsd.edu/c/preproc.html#Define Directives">macros</A> at any point
|
||||
within a translation unit.</LI>
|
||||
|
||||
<LI>Write no more than 31 parameters in a
|
||||
<A HREF="syntax.html#function decoration" tppabs="http://ccs.ucsd.edu/c/syntax.html#function decoration">function decoration</A>.</LI>
|
||||
|
||||
<LI>Write no more than 31 arguments in a
|
||||
<A HREF="function.html#Function Calls" tppabs="http://ccs.ucsd.edu/c/function.html#Function Calls">function call</A>.</LI>
|
||||
|
||||
<LI>Write no more than 31 parameters in a
|
||||
<A HREF="preproc.html#Define Directives" tppabs="http://ccs.ucsd.edu/c/preproc.html#Define Directives">macro definition</A>.</LI>
|
||||
|
||||
<LI>Write no more than 31 arguments in a
|
||||
<A HREF="preproc.html#Expanding Macros" tppabs="http://ccs.ucsd.edu/c/preproc.html#Expanding Macros">macro invocation</A>.</LI>
|
||||
|
||||
<LI>Write no
|
||||
<A HREF="preproc.html#logical line" tppabs="http://ccs.ucsd.edu/c/preproc.html#logical line">logical</A>
|
||||
source line that exceeds 509 characters.</LI>
|
||||
|
||||
<LI>Construct no
|
||||
<A HREF="preproc.html#string literal" tppabs="http://ccs.ucsd.edu/c/preproc.html#string literal">string literal</A>
|
||||
that contains more than 509 characters or wide characters.</LI>
|
||||
|
||||
<LI>Declare no
|
||||
<A HREF="declare.html#Object Declaration" tppabs="http://ccs.ucsd.edu/c/declare.html#Object Declaration">object</A>
|
||||
whose size exceeds 32,767 bytes.</LI>
|
||||
|
||||
<LI>Ensure that
|
||||
<A HREF="preproc.html#Include Directives" tppabs="http://ccs.ucsd.edu/c/preproc.html#Include Directives"><I>include</I> directives</A>
|
||||
nest no more than eight files deep.</LI>
|
||||
|
||||
<LI>Write no more than 257
|
||||
<A HREF="function.html#Case Label" tppabs="http://ccs.ucsd.edu/c/function.html#Case Label"><I>case</I> labels</A> for any one
|
||||
<A HREF="function.html#Switch Statement" tppabs="http://ccs.ucsd.edu/c/function.html#Switch Statement"><I>switch</I> statement</A>.
|
||||
(<I>Case</I> labels within nested <I>switch</I> statements
|
||||
do not affect this limit.)</LI>
|
||||
|
||||
<LI>Write no more than 127
|
||||
<A HREF="declare.html#Member Declaration" tppabs="http://ccs.ucsd.edu/c/declare.html#Member Declaration">members</A>
|
||||
in any one structure or union.</LI>
|
||||
|
||||
<LI>Write no more than 127
|
||||
<A HREF="types.html#enumeration constants" tppabs="http://ccs.ucsd.edu/c/types.html#enumeration constants">enumeration constants</A>
|
||||
in any one enumeration.</LI>
|
||||
|
||||
<LI>Nest structure or union definitions no more than fifteen deep
|
||||
in any one list of
|
||||
<A HREF="declare.html#Member Declaration" tppabs="http://ccs.ucsd.edu/c/declare.html#Member Declaration">member declarations</A>.</LI>
|
||||
</UL>
|
||||
|
||||
<H3><A NAME="Character-Set Issues">Character-Set Issues</A></H3>
|
||||
|
||||
<P>The program can depend on peculiar properties of the <B>character
|
||||
set</B>.</P>
|
||||
|
||||
<P>If you write in the source files any characters not in the
|
||||
<A HREF="charset.html#basic C character set" tppabs="http://ccs.ucsd.edu/c/charset.html#basic C character set">basic C character set</A>,
|
||||
a corresponding character might not be in another
|
||||
character set, or the corresponding character might not be what you
|
||||
want. The set of characters is
|
||||
<A HREF="#implementation defined">defined</A> for each implementation.</P>
|
||||
|
||||
<P>Similarly, if the program makes special use of characters not
|
||||
in the basic C character set when it executes, you might get different
|
||||
behavior when you move the program.</P>
|
||||
|
||||
<P>If you write a
|
||||
<A HREF="charset.html#character constant" tppabs="http://ccs.ucsd.edu/c/charset.html#character constant">character constant</A>
|
||||
that specifies more than one character,
|
||||
such as <CODE>'ab'</CODE>, the result might change when you move
|
||||
the program. Each implementation
|
||||
<A HREF="#implementation defined">defines</A> what values it assigns such
|
||||
character constants.</P>
|
||||
|
||||
<P>If the program depends on a particular value for one or more
|
||||
character codes, it can behave differently
|
||||
on an implementation with a different
|
||||
<A HREF="charset.html#Character Sets" tppabs="http://ccs.ucsd.edu/c/charset.html#Character Sets">character set</A>.
|
||||
The codes associated with each character
|
||||
are implementation defined.</P>
|
||||
|
||||
<H3><A NAME="Representation Issues">Representation Issues</A></H3>
|
||||
|
||||
<P>The program can depend on how an implementation <B>represents</B> objects.
|
||||
All representations are implementation defined.</P>
|
||||
|
||||
<P>If the program depends on the representation of an object type
|
||||
(such as its size in bits or whether type
|
||||
<A HREF="types.html#Basic Integer Types" tppabs="http://ccs.ucsd.edu/c/types.html#Basic Integer Types"><I>char</I></A> or the plain
|
||||
<A HREF="types.html#Bitfields" tppabs="http://ccs.ucsd.edu/c/types.html#Bitfields"><I>bitfield</I></A>
|
||||
types can represent negative values), the program
|
||||
can change behavior when you move it.</P>
|
||||
|
||||
<P>If you treat an arithmetic object that has more than one byte
|
||||
as an array of characters, you must be aware that the order of significant
|
||||
bytes can vary among implementations. You cannot write an integer
|
||||
or floating-point type object to a
|
||||
<A HREF="lib_file.html#binary stream" tppabs="http://ccs.ucsd.edu/c/lib_file.html#binary stream">binary stream</A>
|
||||
on one implementation,
|
||||
then later read those bytes into an object of the same type on a different
|
||||
implementation, and portably obtain the same stored value.</P>
|
||||
|
||||
<P>The method of encoding integer and floating-point values can
|
||||
vary widely. For
|
||||
<A HREF="types.html#Basic Integer Types" tppabs="http://ccs.ucsd.edu/c/types.html#Basic Integer Types">signed integer types</A>,
|
||||
negative values have several popular encodings.
|
||||
<A HREF="types.html#Floating-Point Types" tppabs="http://ccs.ucsd.edu/c/types.html#Floating-Point Types">Floating-point types</A>
|
||||
have numerous popular encodings.
|
||||
This means that, except for the minimum guaranteed range of values
|
||||
for each type, the range of values can vary widely.</P>
|
||||
|
||||
<P>Both signed integer and floating-point types
|
||||
can have values that represent an
|
||||
<A HREF="express.html#exceptional result" tppabs="http://ccs.ucsd.edu/c/express.html#exceptional result">exceptional result</A>
|
||||
on some implementations. Performing an arithmetic operation
|
||||
or a comparison on such a value can report a
|
||||
<A HREF="signal.html#signals" tppabs="http://ccs.ucsd.edu/c/signal.html#signals">signal</A> or otherwise
|
||||
<A HREF="lib_over.html#program termination" tppabs="http://ccs.ucsd.edu/c/lib_over.html#program termination">terminate execution</A>.
|
||||
Initialize all such objects before accessing them --
|
||||
and avoid overflow, underflow, or zero divide --
|
||||
to avoid exceptional results.</P>
|
||||
|
||||
<P>The alignment requirements of various object types can vary
|
||||
widely. The placement and size of
|
||||
<A HREF="types.html#holes" tppabs="http://ccs.ucsd.edu/c/types.html#holes">holes</A> in structures is
|
||||
<A HREF="#implementation defined">implementation defined</A>.
|
||||
You can portably determine the offset of a given member from the beginning
|
||||
of a structure, but only by using the
|
||||
<A HREF="stddef.html#offsetof" tppabs="http://ccs.ucsd.edu/c/stddef.html#offsetof"><CODE>offsetof</CODE></A> macro.</P>
|
||||
|
||||
<P>Each implementation defines how
|
||||
<A HREF="types.html#Bitfields" tppabs="http://ccs.ucsd.edu/c/types.html#Bitfields">bitfields</A> pack into integer
|
||||
objects and whether bitfields can straddle two or more underlying
|
||||
objects. You can declare bitfields of 16 bits
|
||||
or less in all implementations.</P>
|
||||
|
||||
<P>How an implementation represents
|
||||
<A HREF="types.html#Enumerations" tppabs="http://ccs.ucsd.edu/c/types.html#Enumerations">enumeration</A> types can vary.
|
||||
You can be certain that all enumeration constants can be represented
|
||||
as type <I>int.</I></P>
|
||||
|
||||
<H3><A NAME="Expression-Evaluation Issues">Expression-Evaluation Issues</A></H3>
|
||||
|
||||
<P>The program can depend on how an implementation
|
||||
<B>evaluates expressions</B>.</P>
|
||||
|
||||
<P>The order in which the program evaluates subexpressions can
|
||||
vary widely, subject to the limits imposed by the
|
||||
<A HREF="express.html#sequence point" tppabs="http://ccs.ucsd.edu/c/express.html#sequence point">sequence points</A>
|
||||
within and between expressions. Therefore, the timing and order of
|
||||
<A HREF="function.html#side effects" tppabs="http://ccs.ucsd.edu/c/function.html#side effects">side effects</A>
|
||||
can vary between any two sequence points. A common error
|
||||
is to depend on a particular order for the evaluation of argument
|
||||
expressions on a
|
||||
<A HREF="function.html#Function Calls" tppabs="http://ccs.ucsd.edu/c/function.html#Function Calls">function call</A>.
|
||||
Any order is permissible.</P>
|
||||
|
||||
<P>Whether you can usefully
|
||||
<A HREF="express.html#Assigning and Type Casting" tppabs="http://ccs.ucsd.edu/c/express.html#Assigning and Type Casting">type cast</A>
|
||||
a pointer value to an integer
|
||||
value or type cast a nonzero integer value to a pointer value depends
|
||||
on the implementation. Each implementation
|
||||
<A HREF="#implementation defined">defines</A> how it converts
|
||||
between scalar types.</P>
|
||||
|
||||
<P>If the quotient of an integer
|
||||
<A HREF="express.html#Divide" tppabs="http://ccs.ucsd.edu/c/express.html#Divide">division</A> is negative, the sign
|
||||
of a nonzero remainder can be either positive or negative. The result
|
||||
is implementation defined. Use the
|
||||
<A HREF="stdlib.html#div" tppabs="http://ccs.ucsd.edu/c/stdlib.html#div"><CODE>div</CODE></A> and
|
||||
<A HREF="stdlib.html#ldiv" tppabs="http://ccs.ucsd.edu/c/stdlib.html#ldiv"><CODE>ldiv</CODE></A> functions
|
||||
for consistent behavior across implementations.</P>
|
||||
|
||||
<P>When the program
|
||||
<A HREF="express.html#Right Shift" tppabs="http://ccs.ucsd.edu/c/express.html#Right Shift">right shifts</A>
|
||||
a negative integer value, different
|
||||
implementations can define different results. To get consistent results
|
||||
across implementations, you can right shift only positive (or unsigned)
|
||||
integer values.</P>
|
||||
|
||||
<P>When the program
|
||||
<A HREF="express.html#Changing Representations" tppabs="http://ccs.ucsd.edu/c/express.html#Changing Representations">converts</A>
|
||||
a <I>long double</I> value to another
|
||||
floating-point type, or a <I>double</I> to a <I>float,</I> it can
|
||||
round the result to either a nearby higher or a nearby lower representation
|
||||
of the original value. Each implementation
|
||||
<A HREF="#implementation defined">defines</A> how such conversions
|
||||
behave.</P>
|
||||
|
||||
<P>When the program accesses or stores a value in a
|
||||
<A HREF="types.html#Type Qualifiers" tppabs="http://ccs.ucsd.edu/c/types.html#Type Qualifiers"><I>volatile</I></A>
|
||||
object, each implementation defines the number and nature of the accesses
|
||||
and stores. Three possibilities exist:</P>
|
||||
|
||||
<UL>
|
||||
<LI>multiple accesses to different bytes</LI>
|
||||
|
||||
<LI>multiple accesses to the same byte</LI>
|
||||
|
||||
<LI>no accesses at all</LI>
|
||||
</UL>
|
||||
|
||||
<P>You cannot write a program that assuredly produces the same
|
||||
pattern of accesses across multiple implementations.</P>
|
||||
|
||||
<P>The expansion of the
|
||||
<A HREF="types.html#null pointer value" tppabs="http://ccs.ucsd.edu/c/types.html#null pointer value">null pointer</A> constant macro
|
||||
<A HREF="stddef.html#NULL" tppabs="http://ccs.ucsd.edu/c/stddef.html#NULL"><CODE>NULL</CODE></A>
|
||||
can be any of <CODE>0</CODE>, <CODE>0L</CODE>, or <CODE>(void *)0</CODE>.
|
||||
The program should not depend on a particular choice.
|
||||
You should not assign <CODE>NULL</CODE>
|
||||
to a pointer to a function, and you should not use <CODE>NULL</CODE> as
|
||||
an argument to a function call that has no
|
||||
<A HREF="function.html#function prototypes" tppabs="http://ccs.ucsd.edu/c/function.html#function prototypes">type information</A> for the
|
||||
corresponding parameter.</P>
|
||||
|
||||
<P>The actual integer types corresponding to the type definitions
|
||||
<A HREF="stddef.html#ptrdiff_t" tppabs="http://ccs.ucsd.edu/c/stddef.html#ptrdiff_t"><CODE>ptrdiff_t</CODE></A>,
|
||||
<A HREF="stddef.html#size_t" tppabs="http://ccs.ucsd.edu/c/stddef.html#size_t"><CODE>size_t</CODE></A>, and
|
||||
<A HREF="stddef.html#wchar_t" tppabs="http://ccs.ucsd.edu/c/stddef.html#wchar_t"><CODE>wchar_t</CODE></A> can vary.
|
||||
Use the type definitions.</P>
|
||||
|
||||
<H3><A NAME="Library Issues">Library Issues</A></H3>
|
||||
|
||||
<P>The behavior of the
|
||||
<A HREF="index.html#Standard C Library" tppabs="http://ccs.ucsd.edu/c/index.html#Standard C Library">Standard C library</A> can vary.</P>
|
||||
|
||||
<P>What happens to the
|
||||
<A HREF="lib_file.html#file-position indicator" tppabs="http://ccs.ucsd.edu/c/lib_file.html#file-position indicator">file-position indicator</A>
|
||||
for a <A HREF="lib_file.html#text stream" tppabs="http://ccs.ucsd.edu/c/lib_file.html#text stream">text stream</A>
|
||||
immediately after a successful call to
|
||||
<A HREF="stdio.html#ungetc" tppabs="http://ccs.ucsd.edu/c/stdio.html#ungetc"><CODE>ungetc</CODE></A> is not defined.
|
||||
Avoid mixing
|
||||
<A HREF="lib_file.html#position functions" tppabs="http://ccs.ucsd.edu/c/lib_file.html#position functions">file-positioning operations</A>
|
||||
with calls to this function.</P>
|
||||
|
||||
<P>When the function
|
||||
<A HREF="stdlib.html#bsearch" tppabs="http://ccs.ucsd.edu/c/stdlib.html#bsearch"><CODE>bsearch</CODE></A>
|
||||
can match either of two equal elements of an array,
|
||||
different implementations can return different matches.</P>
|
||||
|
||||
<P>When the function
|
||||
<A HREF="stdlib.html#qsort" tppabs="http://ccs.ucsd.edu/c/stdlib.html#qsort"><CODE>qsort</CODE></A>
|
||||
sorts an array containing two
|
||||
elements that compare equal, different implementations can leave the
|
||||
elements in different order.</P>
|
||||
|
||||
<P>Whether or not floating-point
|
||||
<B><A NAME="underflow">underflow</A></B> causes the value
|
||||
<A HREF="errno.html#ERANGE" tppabs="http://ccs.ucsd.edu/c/errno.html#ERANGE"><CODE>ERANGE</CODE></A> to be stored in
|
||||
<A HREF="errno.html#errno" tppabs="http://ccs.ucsd.edu/c/errno.html#errno"><CODE>errno</CODE></A>
|
||||
(as the result of a
|
||||
<A HREF="math.html#range error" tppabs="http://ccs.ucsd.edu/c/math.html#range error">range error</A>) can vary.
|
||||
Each implementation defines how it handles floating-point underflow.</P>
|
||||
|
||||
<P>What library functions store values in <CODE>errno</CODE>
|
||||
varies considerably.
|
||||
To determine whether the function of interest reported an error, you
|
||||
must store the value zero in <CODE>errno</CODE> before you call a library
|
||||
function and then test the stored value before you call another library
|
||||
function.</P>
|
||||
|
||||
<P>You can do very little with
|
||||
<A HREF="signal.html#signals" tppabs="http://ccs.ucsd.edu/c/signal.html#signals">signals</A> in a portable program. A
|
||||
target environment can elect not to report signals. If it does report
|
||||
signals, any handler you write for an asynchronous signal can only:</P>
|
||||
|
||||
<UL>
|
||||
<LI>make a successful call to
|
||||
<A HREF="signal.html#signal" tppabs="http://ccs.ucsd.edu/c/signal.html#signal"><CODE>signal</CODE></A> for that particular
|
||||
signal</LI>
|
||||
|
||||
<LI>alter the value stored in an object of type <CODE>volatile
|
||||
<A HREF="signal.html#sig_atomic_t" tppabs="http://ccs.ucsd.edu/c/signal.html#sig_atomic_t">sig_atomic_t</A></CODE></LI>
|
||||
|
||||
<LI>return control to its caller</LI>
|
||||
</UL>
|
||||
|
||||
<P>Asynchronous signals can disrupt proper operation of the library.
|
||||
Avoid using signals, or tailor how you use them
|
||||
to each target environment.</P>
|
||||
|
||||
<P><A HREF="lib_scan.html#Scan Functions" tppabs="http://ccs.ucsd.edu/c/lib_scan.html#Scan Functions">Scan functions</A>
|
||||
can give special meaning to a minus (<CODE>-</CODE>)
|
||||
that is not the first or the last character of a
|
||||
<A HREF="lib_scan.html#scan set" tppabs="http://ccs.ucsd.edu/c/lib_scan.html#scan set">scan set</A>. The behavior is
|
||||
<A HREF="#implementation defined">implementation defined</A>.
|
||||
Write this character only first or last in a scan set.</P>
|
||||
|
||||
<P>If you allocate an object of zero size by calling one of the functions
|
||||
<A HREF="stdlib.html#calloc" tppabs="http://ccs.ucsd.edu/c/stdlib.html#calloc"><CODE>calloc</CODE></A>,
|
||||
<A HREF="stdlib.html#malloc" tppabs="http://ccs.ucsd.edu/c/stdlib.html#malloc"><CODE>malloc</CODE></A>, or
|
||||
<A HREF="stdlib.html#realloc" tppabs="http://ccs.ucsd.edu/c/stdlib.html#realloc"><CODE>realloc</CODE></A>, the behavior is
|
||||
<A HREF="#implementation defined">implementation defined</A>.
|
||||
Avoid such calls.</P>
|
||||
|
||||
<P>If you call the function
|
||||
<A HREF="stdlib.html#exit" tppabs="http://ccs.ucsd.edu/c/stdlib.html#exit"><CODE>exit</CODE></A> with a status argument
|
||||
value other than zero (for successful termination),
|
||||
<A HREF="stdlib.html#EXIT_FAILURE" tppabs="http://ccs.ucsd.edu/c/stdlib.html#EXIT_FAILURE"><CODE>EXIT_FAILURE</CODE></A>, or
|
||||
<A HREF="stdlib.html#EXIT_SUCCESS" tppabs="http://ccs.ucsd.edu/c/stdlib.html#EXIT_SUCCESS"><CODE>EXIT_SUCCESS</CODE></A>,
|
||||
the behavior is
|
||||
<A HREF="#implementation defined">implementation defined</A>. Use
|
||||
only these values to report status.</P>
|
||||
|
||||
<H2><A NAME="Converting to Standard C">Converting to Standard C</A></H2>
|
||||
|
||||
<P>If you have a program written in an earlier dialect of C that
|
||||
you want to convert to Standard C, be aware of all the portability
|
||||
issues described earlier in this document. You must also be aware
|
||||
of issues peculiar to earlier dialects of C. Standard C tries to codify
|
||||
existing practice wherever possible, but existing practice varied
|
||||
in certain areas. This section discusses the major areas to address
|
||||
when moving an older C program to a Standard C environment.</P>
|
||||
|
||||
<H3><A NAME="Function-Call Issues">Function-Call Issues</A></H3>
|
||||
|
||||
<P>In earlier dialects of C, you cannot write a
|
||||
<A HREF="function.html#function prototypes" tppabs="http://ccs.ucsd.edu/c/function.html#function prototypes">function prototype</A>.
|
||||
Function types do not have argument information, and function calls
|
||||
occur in the absence of any argument information. Many implementations
|
||||
let you call any function with a
|
||||
<A HREF="stdarg.html#varying number of arguments" tppabs="http://ccs.ucsd.edu/c/stdarg.html#varying number of arguments">varying number
|
||||
of arguments</A>.</P>
|
||||
|
||||
<P>You can directly address many of the potential difficulties
|
||||
in converting a program to Standard C by writing function prototypes
|
||||
for all functions. Declare functions with
|
||||
<A HREF="declare.html#external linkage" tppabs="http://ccs.ucsd.edu/c/declare.html#external linkage">external linkage</A> that you
|
||||
use in more than one file in a separate file, and then include that
|
||||
file in all source files that call or define the functions.</P>
|
||||
|
||||
<P>The translator will check that function calls and function definitions
|
||||
are consistent with the function prototypes that you write. It will
|
||||
emit a diagnostic if you call a function with an incorrect number
|
||||
of arguments. It will emit a diagnostic if you call a function with
|
||||
an argument expression that is not
|
||||
<A HREF="types.html#assignment compatible" tppabs="http://ccs.ucsd.edu/c/types.html#assignment compatible">assignment compatible</A>
|
||||
with the corresponding function parameter. It will
|
||||
<A HREF="express.html#Assigning and Type Casting" tppabs="http://ccs.ucsd.edu/c/express.html#Assigning and Type Casting">convert</A>
|
||||
an argument expression that is assignment compatible
|
||||
but that does not have the same type
|
||||
as the corresponding function parameter.</P>
|
||||
|
||||
<P>Older C programs often rely on argument values of different
|
||||
types having the same representation on a given implementation. By
|
||||
providing function prototypes, you can ensure that the translator
|
||||
will diagnose, or quietly correct, any function calls for which the
|
||||
representation of an argument value is not always acceptable.</P>
|
||||
|
||||
<P>For functions intended to accept a varying number of arguments,
|
||||
different implementations provide different methods of accessing the
|
||||
unnamed arguments. When you identify such a function, declare it with
|
||||
the ellipsis notation, such as <CODE>int f(int x, ...)</CODE>. Within the
|
||||
function, use the macros defined in
|
||||
<A HREF="stdarg.html" tppabs="http://ccs.ucsd.edu/c/stdarg.html"><CODE><stdarg.h></CODE></A> to replace the
|
||||
existing method for accessing unnamed arguments.</P>
|
||||
|
||||
<H3><A NAME="Preprocessing Issues">Preprocessing Issues</A></H3>
|
||||
|
||||
<P>Perhaps the greatest variation in dialects among earlier implementations
|
||||
of C occurs in preprocessing. If the program
|
||||
<A HREF="preproc.html#Define Directives" tppabs="http://ccs.ucsd.edu/c/preproc.html#Define Directives">defines macros</A> that perform
|
||||
only simple substitutions of preprocessing tokens, then you can expect
|
||||
few problems. Otherwise, be wary of variations in several areas.</P>
|
||||
|
||||
<P>Some earlier dialects
|
||||
<A HREF="preproc.html#Expanding Macros" tppabs="http://ccs.ucsd.edu/c/preproc.html#Expanding Macros">expand macro</A>
|
||||
arguments after substitution, rather than before.
|
||||
This can lead to differences in how a macro expands
|
||||
when you write other macro invocations within its arguments.</P>
|
||||
|
||||
<P>Some earlier dialects do not rescan the replacement token sequence
|
||||
after substitution. Macros that expand to macro invocations work differently,
|
||||
depending on whether the rescan occurs.</P>
|
||||
|
||||
<P>Dialects that rescan the replacement token sequence work differently,
|
||||
depending on whether a macro that expands to a macro invocation can
|
||||
involve preprocessing tokens in the text following the macro invocation.</P>
|
||||
|
||||
<P>The handling of a macro name during an expansion of its invocation
|
||||
varies considerably.</P>
|
||||
|
||||
<P>Some dialects permit empty argument sequences in a macro invocation.
|
||||
Standard C does not always permit empty arguments.</P>
|
||||
|
||||
<P>The concatenation of tokens with the operator <CODE>##</CODE> is new
|
||||
with Standard C. It replaces several earlier methods.</P>
|
||||
|
||||
<P>The
|
||||
<A HREF="preproc.html#Creating String Literals" tppabs="http://ccs.ucsd.edu/c/preproc.html#Creating String Literals">creation of
|
||||
string literals</A> with the operator <CODE>#</CODE> is
|
||||
new with Standard C. It replaces the practice in some earlier dialects
|
||||
of substituting macro parameter names that you write within string
|
||||
literals in macro definitions.</P>
|
||||
|
||||
<H3><A NAME="Library Issues">Library Issues</A></H3>
|
||||
|
||||
<P>The
|
||||
<A HREF="index.html#Standard C Library" tppabs="http://ccs.ucsd.edu/c/index.html#Standard C Library">Standard C library</A>
|
||||
is largely a superset of existing libraries.
|
||||
Some conversion problems, however, can occur.</P>
|
||||
|
||||
<P>Many earlier implementations offer an additional set of input/output
|
||||
functions with names such as <CODE>close</CODE>,
|
||||
<CODE>creat</CODE>, <CODE>lseek</CODE>,
|
||||
<CODE>open</CODE>, <CODE>read</CODE>, and <CODE>write</CODE>.
|
||||
You must replace calls to these functions
|
||||
with calls to other functions defined in
|
||||
<A HREF="stdio.html" tppabs="http://ccs.ucsd.edu/c/stdio.html"><CODE><stdio.h></CODE></A>.</P>
|
||||
|
||||
<P>Standard C has several minor changes in the behavior of library
|
||||
functions, compared with popular earlier dialects. These changes generally
|
||||
occur in areas where practice also varied.</P>
|
||||
|
||||
<H3><A NAME="Quiet Changes">Quiet Changes</A></H3>
|
||||
|
||||
<P>Most differences between Standard C and earlier dialects of
|
||||
C cause a Standard C translator to emit a diagnostic when it encounters
|
||||
a program written in the earlier dialect of C. Some changes, unfortunately,
|
||||
require no diagnostic. What was a valid program in the earlier dialect
|
||||
is also a valid program in Standard C, but with different meaning.</P>
|
||||
|
||||
<P>While these <B>quiet changes</B> are few in number and generally
|
||||
subtle, you need to be aware of them. They occasionally give rise
|
||||
to unexpected behavior in a program that you convert to Standard C.
|
||||
The principal quiet changes are discussed below.</P>
|
||||
|
||||
<P><A HREF="charset.html#Trigraphs" tppabs="http://ccs.ucsd.edu/c/charset.html#Trigraphs">Trigraphs</A>
|
||||
do not occur in earlier dialects of C. An older program
|
||||
that happens to contain a sequence of two question marks (<CODE>??</CODE>)
|
||||
can change meaning in a variety of ways.</P>
|
||||
|
||||
<P>Some earlier dialects effectively promote any declaration you
|
||||
write that has external linkage to file level. Standard C keeps such
|
||||
declarations at block level.</P>
|
||||
|
||||
<P>Earlier dialects of C let you use the digits
|
||||
<CODE>8</CODE> and <CODE>9</CODE> in an
|
||||
<A HREF="charset.html#octal escape sequence" tppabs="http://ccs.ucsd.edu/c/charset.html#octal escape sequence">octal escape sequence</A>,
|
||||
such as in the string literal <CODE>"\08"</CODE>.
|
||||
Standard C treats this as a string literal with two characters (plus
|
||||
the terminating null character).</P>
|
||||
|
||||
<P><A HREF="charset.html#hexadecimal escape sequence" tppabs="http://ccs.ucsd.edu/c/charset.html#hexadecimal escape sequence">Hexadecimal
|
||||
escape sequences</A>, such as <CODE>\xff</CODE>, and the escape
|
||||
sequence <CODE>\a</CODE> are new with Standard C.
|
||||
In certain earlier implementations, they may have different meaning.</P>
|
||||
|
||||
<P>Some earlier dialects guarantee that identical
|
||||
<A HREF="charset.html#string literal" tppabs="http://ccs.ucsd.edu/c/charset.html#string literal">string literals</A>
|
||||
share common storage, and others guarantee that they do not. Some
|
||||
dialects let you alter the values stored in string literals. You cannot
|
||||
be certain that identical string literals overlap in Standard C,
|
||||
or that they do not. Do
|
||||
not alter the values stored in string literals in Standard C.</P>
|
||||
|
||||
<P>Some earlier dialects have different rules for
|
||||
<A HREF="express.html#Promoting" tppabs="http://ccs.ucsd.edu/c/express.html#Promoting">promoting</A> the
|
||||
types <I>unsigned char, unsigned short,</I> and <I>unsigned bitfields.</I>
|
||||
On most implementations, the difference is detectable only on a few
|
||||
expressions where a negative value becomes a large positive value
|
||||
of unsigned type. Add
|
||||
<A HREF="express.html#Type Cast" tppabs="http://ccs.ucsd.edu/c/express.html#Type Cast">type casts</A>
|
||||
to specify the types you require.</P>
|
||||
|
||||
<P>Earlier dialects convert lvalue expressions of type
|
||||
<I>float</I> to <I>double,</I> in a
|
||||
<A HREF="function.html#value context" tppabs="http://ccs.ucsd.edu/c/function.html#value context">value context</A>,
|
||||
so all floating-point arithmetic
|
||||
occurs only in type <I>double.</I> A program that depends on this
|
||||
implicit increase in precision can behave differently in a Standard
|
||||
C environment. Add type casts if you need the extra precision.</P>
|
||||
|
||||
<P>On some earlier dialects of C, shifting
|
||||
an <I>int</I> or <I>unsigned int</I> value
|
||||
<A HREF="express.html#Left Shift" tppabs="http://ccs.ucsd.edu/c/express.html#Left Shift">left</A> or
|
||||
<A HREF="express.html#Right Shift" tppabs="http://ccs.ucsd.edu/c/express.html#Right Shift">right</A>
|
||||
by a <I>long</I> or <I>unsigned long</I>
|
||||
value first converts the value to be shifted to the type of the shift
|
||||
count. In Standard C, the type of the shift count has no such effect.
|
||||
Use a type cast if you need this behavior.</P>
|
||||
|
||||
<P>Some earlier dialects guarantee that the
|
||||
<A HREF="preproc.html#if directive" tppabs="http://ccs.ucsd.edu/c/preproc.html#if directive"><I>if</I> directive</A>
|
||||
performs arithmetic to the same precision as the
|
||||
<A HREF="charset.html#target environment" tppabs="http://ccs.ucsd.edu/c/charset.html#target environment">target environment</A>.
|
||||
(You can write an <I>if</I> directive that reveals properties of the
|
||||
target environment.) Standard C makes no such guarantee.
|
||||
Use the macros defined in
|
||||
<A HREF="float.html" tppabs="http://ccs.ucsd.edu/c/float.html"><CODE><float.h></CODE></A> and
|
||||
<A HREF="limits.html" tppabs="http://ccs.ucsd.edu/c/limits.html"><CODE><limits.h></CODE></A>
|
||||
to test properties of the target environment.</P>
|
||||
|
||||
<P>Earlier dialects vary considerably
|
||||
in the grouping of values within an object
|
||||
<A HREF="declare.html#Object Initializers" tppabs="http://ccs.ucsd.edu/c/declare.html#Object Initializers">initializer</A>,
|
||||
when you omit some (but not all) of the braces within the initializer.
|
||||
Supply all braces for maximum clarity.</P>
|
||||
|
||||
<P>Earlier dialects convert the expression in any
|
||||
<A HREF="function.html#Switch Statement" tppabs="http://ccs.ucsd.edu/c/function.html#Switch Statement"><I>switch</I> statement</A>
|
||||
to type <I>int.</I> Standard C also performs comparisons
|
||||
within a <I>switch</I> statement in other integer types. A
|
||||
<A HREF="function.html#Case Label" tppabs="http://ccs.ucsd.edu/c/function.html#Case Label"><I>case</I> label</A>
|
||||
expression that relies on being truncated when
|
||||
<A HREF="express.html#Changing Representations" tppabs="http://ccs.ucsd.edu/c/express.html#Changing Representations">converted</A> to
|
||||
<I>int,</I> in an earlier dialect, can behave differently in a Standard
|
||||
C environment.</P>
|
||||
|
||||
<P>Some earlier preprocessing
|
||||
<A HREF="preproc.html#Expanding Macros" tppabs="http://ccs.ucsd.edu/c/preproc.html#Expanding Macros">expands</A>
|
||||
parameter names within string literals or character constants
|
||||
that you write within a macro definition.
|
||||
Standard C does not. Use the string literal
|
||||
<A HREF="preproc.html#Creating String Literals" tppabs="http://ccs.ucsd.edu/c/preproc.html#Creating String Literals">creation</A>
|
||||
operator <CODE>#</CODE>, along with
|
||||
<A HREF="preproc.html#string-literal concatenation" tppabs="http://ccs.ucsd.edu/c/preproc.html#string-literal concatenation">string-literal
|
||||
concatenation</A>, to replace this method.</P>
|
||||
|
||||
<P>Some earlier preprocessing concatenates preprocessor tokens
|
||||
separated only by a comment within a macro definition. Standard C
|
||||
does not. Use the
|
||||
<A HREF="preproc.html#token concatenation" tppabs="http://ccs.ucsd.edu/c/preproc.html#token concatenation">token concatenation</A>
|
||||
operator <CODE>##</CODE> to replace this method.</P>
|
||||
|
||||
<H2><A NAME="Newer Dialects">Newer Dialects</A></H2>
|
||||
|
||||
<P>Making standards for programming languages is an on-going activity.
|
||||
As of this writing, the C Standard has been formally amended. A standard
|
||||
for C++, which is closely related to C, is in the late stages of development.
|
||||
One aspect of portability is writing code that is compatible with
|
||||
these newer dialects, whether or not the code makes use of the newer
|
||||
features.</P>
|
||||
|
||||
<P>Most of the features added with
|
||||
<A HREF="lib_over.html#Amendment 1" tppabs="http://ccs.ucsd.edu/c/lib_over.html#Amendment 1">Amendment 1</A> are declared or
|
||||
defined in three new headers --
|
||||
<A HREF="iso646.html" tppabs="http://ccs.ucsd.edu/c/iso646.html"><CODE><iso646.h></CODE></A>,
|
||||
<A HREF="wchar.html" tppabs="http://ccs.ucsd.edu/c/wchar.html"><CODE><wchar.h></CODE></A>, and
|
||||
<A HREF="wctype.html" tppabs="http://ccs.ucsd.edu/c/wctype.html"><CODE><wctype.h></CODE></A>.
|
||||
A few take the form of capabilities added to
|
||||
the functions declared in
|
||||
<A HREF="stdio.html" tppabs="http://ccs.ucsd.edu/c/stdio.html"><CODE><stdio.h></CODE></A>.
|
||||
While not strictly necessary,
|
||||
it is best to avoid using any of the names declared or defined in
|
||||
these new headers.</P>
|
||||
|
||||
<P>Maintaining compatibility with C++ takes considerably more work.
|
||||
It can be useful, however, to write in a common dialect called
|
||||
<B><A NAME="typesafe C">typesafe C</A></B>
|
||||
Here is a brief summary of the added constraints:</P>
|
||||
|
||||
<P>Avoid using any C++ keywords. As of this writing, the list includes:</P>
|
||||
|
||||
<PRE>
|
||||
and and_eq asm bitand bitor
|
||||
bool catch class compl delete
|
||||
explicit false friend inline mutable
|
||||
namespace new not not_eq operator
|
||||
or or_eq private protected public
|
||||
template this throw true try
|
||||
typeid typename using virtual wchar_t
|
||||
xor xor_eq const_cast dynamic_cast
|
||||
reinterpret_cast static_cast</PRE>
|
||||
|
||||
<P>Write
|
||||
<A HREF="function.html#function prototypes" tppabs="http://ccs.ucsd.edu/c/function.html#function prototypes">function prototypes</A>
|
||||
for all functions you call.</P>
|
||||
|
||||
<P>Define each
|
||||
<A HREF="declare.html#Tags" tppabs="http://ccs.ucsd.edu/c/declare.html#Tags">tag</A> name also as a type, as in:</P>
|
||||
|
||||
<PRE>
|
||||
typedef struct x x;</PRE>
|
||||
|
||||
<P>Assume each
|
||||
<A HREF="types.html#Enumerations" tppabs="http://ccs.ucsd.edu/c/types.html#Enumerations">enumeration</A> type
|
||||
is a distinct type that promotes to an integer type.
|
||||
<A HREF="express.html#Type Cast" tppabs="http://ccs.ucsd.edu/c/express.html#Type Cast">Type cast</A>
|
||||
an integer expression that you assign
|
||||
to an object of enumeration type.</P>
|
||||
|
||||
<P>Write an explicit storage class for each constant object declaration
|
||||
at <A HREF="declare.html#file-level declaration" tppabs="http://ccs.ucsd.edu/c/declare.html#file-level declaration">file level</A>.</P>
|
||||
|
||||
<P>Do not write
|
||||
<A HREF="declare.html#tentative declaration" tppabs="http://ccs.ucsd.edu/c/declare.html#tentative declaration">tentative
|
||||
declarations</A>.</P>
|
||||
|
||||
<P>Do not apply the
|
||||
<A HREF="express.html#sizeof operator" tppabs="http://ccs.ucsd.edu/c/express.html#sizeof operator"><I>sizeof</I></A> operator to an
|
||||
<A HREF="express.html#rvalue expression" tppabs="http://ccs.ucsd.edu/c/express.html#rvalue expression">rvalue</A> operand.</P>
|
||||
|
||||
<HR>
|
||||
<P>See also the
|
||||
<B><A HREF="index.html#Table of Contents" tppabs="http://ccs.ucsd.edu/c/index.html#Table of Contents">Table of Contents</A></B> and the
|
||||
<B><A HREF="_index.html" tppabs="http://ccs.ucsd.edu/c/_index.html">Index</A></B>.</P>
|
||||
|
||||
<P><I>
|
||||
<A HREF="crit_pb.html" tppabs="http://ccs.ucsd.edu/c/crit_pb.html">Copyright</A> © 1989-1996
|
||||
by P.J. Plauger and Jim Brodie. All rights reserved.</I></P>
|
||||
|
||||
</BODY></HTML>
|
||||
BIN
study/Ref-docs/C/postfix.gif
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
BIN
study/Ref-docs/C/pragma.gif
Normal file
|
After Width: | Height: | Size: 805 B |
BIN
study/Ref-docs/C/prefix.gif
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
957
study/Ref-docs/C/preproc.html
Normal file
@@ -0,0 +1,957 @@
|
||||
<HTML><HEAD><TITLE>Preprocessing</TITLE></HEAD><BODY BGCOLOR="#FFFFFF">
|
||||
|
||||
<H1><A NAME="Preprocessing">Preprocessing</A></H1><HR>
|
||||
|
||||
<P><B>
|
||||
<A HREF="#Phases of Translation">Phases of Translation</A>
|
||||
· <A HREF="#White Space">White Space</A>
|
||||
· <A HREF="#Preprocessing Tokens">Preprocessing Tokens</A>
|
||||
· <A HREF="#Include Directives">Include Directives</A>
|
||||
· <A HREF="#Define Directives">Define Directives</A>
|
||||
· <A HREF="#Expanding Macros">Expanding Macros</A>
|
||||
· <A HREF="#Creating String Literals">Creating String Literals</A>
|
||||
· <A HREF="#Conditional Directives">Conditional Directives</A>
|
||||
· <A HREF="#Conditional Expressions">Conditional Expressions</A>
|
||||
· <A HREF="#Restrictions on Conditional Expressions">Restrictions on Conditional Expressions</A>
|
||||
· <A HREF="#Other Conditional Directives">Other Conditional Directives</A>
|
||||
· <A HREF="#Other Directives">Other Directives</A>
|
||||
· <A HREF="#Predefined Macros">Predefined Macros</A>
|
||||
</B></P>
|
||||
<HR>
|
||||
|
||||
<P>The translator processes each source file in a series of phases.
|
||||
<B>Preprocessing</B> constitutes the earliest phases, which produce a
|
||||
<B><A NAME="translation unit">translation unit</A></B>.
|
||||
Preprocessing treats a source file as a sequence of
|
||||
<A HREF="lib_file.html#text lines" tppabs="http://ccs.ucsd.edu/c/lib_file.html#text lines">text lines</A>. You can specify
|
||||
<B><A NAME="directives">directives</A></B> and
|
||||
<B><A NAME="macros">macros</A></B>
|
||||
that insert, delete, and alter source text.</P>
|
||||
|
||||
<P>This document describes
|
||||
the operations that you can perform during preprocessing. It shows
|
||||
how the translator parses the program as
|
||||
<A HREF="#White Space">white space</A> and
|
||||
<A HREF="#Preprocessing Tokens">preprocessing tokens</A>,
|
||||
carries out the directives that you specify, and expands the
|
||||
macros that you write in the source files.</P>
|
||||
|
||||
<H2><A NAME="Phases of Translation">Phases of Translation</A></H2>
|
||||
|
||||
<P>Preprocessing translates each source file in a series of distinct
|
||||
phases. The translator performs the following steps, in order:</P>
|
||||
|
||||
<OL>
|
||||
<LI>terminates each line with a newline character (<CODE><I>NL</I></CODE>),
|
||||
regardless of the external representation of a
|
||||
<A HREF="lib_file.html#text lines" tppabs="http://ccs.ucsd.edu/c/lib_file.html#text lines">text line</A>
|
||||
|
||||
<LI>converts <A HREF="charset.html#Trigraphs" tppabs="http://ccs.ucsd.edu/c/charset.html#Trigraphs">trigraphs</A>
|
||||
to their single-character equivalents
|
||||
|
||||
<LI><B><A NAME="line concatenation">concatenates each line</A></B>
|
||||
ending in a backslash (<CODE>\</CODE>) with the line following
|
||||
|
||||
<LI>replaces each
|
||||
<B><A NAME="comments">comment</A></B>
|
||||
(beginning with <CODE>/*</CODE> that is not inside a
|
||||
<A HREF="#character constant">character constant</A>, a
|
||||
<A HREF="#string literal">string literal</A>, or a
|
||||
<A HREF="lib_over.html#standard header" tppabs="http://ccs.ucsd.edu/c/lib_over.html#standard header">standard header</A>
|
||||
name and ending with a <CODE>*/</CODE>) with a
|
||||
<CODE><I>space</I></CODE> character
|
||||
|
||||
<LI>parses each resulting
|
||||
<B><A NAME="logical line">logical line</A></B>
|
||||
as preprocessing tokens and white space
|
||||
|
||||
<LI>recognizes and carries out directives (that are not skipped)
|
||||
and expands macros in all non-directive lines (that are not skipped)
|
||||
|
||||
<LI>replaces
|
||||
<A HREF="charset.html#Escape Sequences" tppabs="http://ccs.ucsd.edu/c/charset.html#Escape Sequences">escape sequences</A>
|
||||
within character constants and string
|
||||
literals with their single-character equivalents
|
||||
|
||||
<LI><A NAME="string-literal concatenation">concatenates</A>
|
||||
adjacent string literals
|
||||
|
||||
<LI>converts the remaining
|
||||
<A HREF="#Preprocessing Tokens">preprocessing tokens</A> to
|
||||
<A HREF="syntax.html#C Tokens" tppabs="http://ccs.ucsd.edu/c/syntax.html#C Tokens">C tokens</A> and discards any
|
||||
white space to form the
|
||||
<A HREF="#translation unit">translation unit</A>
|
||||
</OL>
|
||||
|
||||
<P>The remainder of the translator then parses the resulting
|
||||
<A HREF="#translation unit">translation unit</A>
|
||||
as one or more
|
||||
<A HREF="declare.html" tppabs="http://ccs.ucsd.edu/c/declare.html">declarations</A> and translates each one. At
|
||||
<B><A NAME="link time">link time</A></B>), you combine
|
||||
one or more separately processed
|
||||
<A HREF="#translation unit">translation units</A>,
|
||||
along with the
|
||||
<A HREF="index.html#Standard C Library" tppabs="http://ccs.ucsd.edu/c/index.html#Standard C Library">Standard C library</A>, to form the
|
||||
<B><A NAME="program">program</A></B>.</P>
|
||||
|
||||
<P>A <A HREF="#translation unit">translation unit</A>
|
||||
can contain entire
|
||||
<A HREF="#include file">include files</A>,
|
||||
which can contain entire
|
||||
<A HREF="#if-group">if-groups</A>,
|
||||
which can contain entire directives and macro invocations,
|
||||
which can contain entire comments,
|
||||
character constants, string literals, and other
|
||||
<A HREF="#Preprocessing Tokens">preprocessing tokens</A>.</P>
|
||||
|
||||
<P>You cannot write a comment inside a string literal, as in:</P>
|
||||
|
||||
<PRE>
|
||||
"hello /* ignored */" <B>comment is NOT ignored</B></PRE>
|
||||
|
||||
<P>You cannot write a macro to begin comments, as in:</P>
|
||||
|
||||
<PRE>
|
||||
#define BEGIN_NOTE /* <B>still inside comment</B></PRE>
|
||||
|
||||
<P>You cannot include a source file that contains an
|
||||
<A HREF="#if directive"><I>if</I> directive</A>
|
||||
without a balancing
|
||||
<A HREF="#endif directive"><I>endif</I> directive</A>
|
||||
within the same file. Nor can you include a source file
|
||||
that contains only part of a
|
||||
<A HREF="#macro invocation">macro invocation</A>.</P>
|
||||
|
||||
<P>You write a directive on one
|
||||
<A HREF="#logical line">logical line</A>.
|
||||
(Use <A HREF="#line concatenation">line concatenation</A>
|
||||
to represent a long directive on multiple source lines.)
|
||||
Every directive begins with a number character (<CODE>#</CODE>).
|
||||
You can write any number of <CODE><I>space</I></CODE>
|
||||
and <CODE><I>HT</I></CODE> characters (or comments)
|
||||
before and after the <CODE>#</CODE>.
|
||||
You cannot write <CODE><I>FF</I></CODE> or <CODE><I>VT</I></CODE>
|
||||
characters to separate tokens on a directive line. Every
|
||||
line that begins with a <CODE>#</CODE> must match one
|
||||
of the forms described in this document.</P>
|
||||
|
||||
<H2><A NAME="White Space">White Space</A></H2>
|
||||
|
||||
<P>Preprocessing parses each input line as
|
||||
<A HREF="#Preprocessing Tokens">preprocessing tokens</A>
|
||||
and <B>white space</B>. You use white space for one or more purposes.</P>
|
||||
|
||||
<UL>
|
||||
<LI>to separate two tokens that the translator might otherwise parse
|
||||
as a single token, as in:
|
||||
|
||||
<PRE>
|
||||
case 3:
|
||||
</PRE>
|
||||
|
||||
<LI>to separate the macro name and a macro definition that begins
|
||||
with a left parenthesis, to signal that there are no macro parameters,
|
||||
as in:
|
||||
|
||||
<PRE>
|
||||
#define neg_pi (-3.1415926535)
|
||||
</PRE>
|
||||
|
||||
<LI>to separate two tokens of a macro argument that you are using
|
||||
to create a string literal, to create a <CODE><I>space</CODE> in the string
|
||||
literal, as in:
|
||||
|
||||
<PRE>
|
||||
#define str(x) #x
|
||||
str(hello there) <B>which becomes "hello there"
|
||||
</PRE>
|
||||
|
||||
<LI>to improve readability
|
||||
</UL>
|
||||
|
||||
<P>White space takes one of three distinct forms:</P>
|
||||
|
||||
<UL>
|
||||
<LI><I>vertical white space</I> (the characters
|
||||
<CODE><I>FF</I></CODE> and <CODE><I>VT</I></CODE>),
|
||||
which you can use within any non-directive line:
|
||||
</UL>
|
||||
|
||||
<P><IMG SRC="vert_ws.gif" tppabs="http://ccs.ucsd.edu/c/gif/vert_ws.gif"></P>
|
||||
|
||||
<UL>
|
||||
<LI><I>horizontal white space</I> (comments and
|
||||
the characters <CODE><I>space</I></CODE> and <CODE><I>HT</I></CODE>),
|
||||
which you can use in any line:
|
||||
</UL>
|
||||
|
||||
<P><IMG SRC="horiz_ws.gif" tppabs="http://ccs.ucsd.edu/c/gif/horiz_ws.gif"></P>
|
||||
|
||||
<UL>
|
||||
<LI><I>end of line</I> (the character <CODE><I>NL</I></CODE>), which you use
|
||||
to terminate directives or to separate tokens on non-directive lines:
|
||||
</UL>
|
||||
|
||||
<P><IMG SRC="end_line.gif" tppabs="http://ccs.ucsd.edu/c/gif/end_line.gif"></P>
|
||||
|
||||
<P>For a directive, you can write horizontal white space wherever
|
||||
an arrow appears in its
|
||||
<A HREF="intro.html#Railroad-Track Diagrams" tppabs="http://ccs.ucsd.edu/c/intro.html#Railroad-Track Diagrams">railroad-track diagram</A>.</P>
|
||||
|
||||
<H2><A NAME="Preprocessing Tokens">Preprocessing Tokens</A></H2>
|
||||
|
||||
<P>A <B>preprocessing token</B> is the longest sequence of characters
|
||||
that matches one of the following patterns.</P>
|
||||
|
||||
<P>A <B><A NAME="name">name</A></B> is a sequence of letters,
|
||||
underscores, and digits that begins with a letter or underscore.
|
||||
<B><A NAME="distinct names">Distinct names</A></B>
|
||||
must differ within the first 31 characters.</P>
|
||||
|
||||
<P><IMG SRC="name.gif" tppabs="http://ccs.ucsd.edu/c/gif/name.gif"></P>
|
||||
|
||||
<P>Some valid names, all of which are distinct, are:</P>
|
||||
|
||||
<PRE>
|
||||
abc Version13 old_sum
|
||||
ABC _Abc X1_Y2_Z3</PRE>
|
||||
|
||||
<P>A <B><A NAME="preprocessing number">preprocessing number</A></B>
|
||||
subsumes all
|
||||
<A HREF="syntax.html#integer constant" tppabs="http://ccs.ucsd.edu/c/syntax.html#integer constant">integer</A> and
|
||||
<A HREF="syntax.html#floating-point constant" tppabs="http://ccs.ucsd.edu/c/syntax.html#floating-point constant">floating-point</A>
|
||||
constants, plus a number of other forms:
|
||||
|
||||
<P><IMG SRC="number.gif" tppabs="http://ccs.ucsd.edu/c/gif/number.gif"></P>
|
||||
|
||||
<P>Some valid preprocessing numbers are:</P>
|
||||
|
||||
<PRE>
|
||||
0 .123 3E
|
||||
123 123E0F 3e+xy
|
||||
123LU 0.123E-005 2for1</PRE>
|
||||
|
||||
<P>The third column shows several of the additional forms.
|
||||
You use the additional forms:</P>
|
||||
|
||||
<UL>
|
||||
<LI>to build string literals
|
||||
from macro arguments during macro expansion
|
||||
|
||||
<LI>to build other tokens by concatenating tokens during macro expansion
|
||||
|
||||
<LI>as part of text that you skip with
|
||||
<A HREF="#Conditional Directives">conditional directives</A>
|
||||
</UL>
|
||||
|
||||
<P>Some valid preprocessing numbers are:</P>
|
||||
|
||||
<PRE>
|
||||
314 3.14 .314E+1
|
||||
0xa5 .14E+ 1z2z</PRE>
|
||||
|
||||
<P>A <B><A NAME="character constant">character constant</A></B>
|
||||
consists of one or more multibyte
|
||||
characters enclosed in single quotes.
|
||||
A backslash (<CODE>\</CODE>) within a character constant
|
||||
begins an <A HREF="charset.html#Escape Sequences" tppabs="http://ccs.ucsd.edu/c/charset.html#Escape Sequences">escape sequence</A>.
|
||||
To make a
|
||||
<B><A NAME="wide-character constant">wide-character constant</A></B>,
|
||||
precede the character constant with an <CODE>L</CODE>.</P>
|
||||
|
||||
<P><IMG SRC="char_con.gif" tppabs="http://ccs.ucsd.edu/c/gif/char_con.gif"></P>
|
||||
|
||||
<P>Some valid character constants are:</P>
|
||||
|
||||
<PRE>
|
||||
'a' '\n' L'x'
|
||||
'abc' '\0' L'<$B0>'</PRE>
|
||||
|
||||
<P>A <B><A NAME="string literal">string literal</A></B>
|
||||
consists of zero or more
|
||||
<A HREF="charset.html#Multibyte Characters" tppabs="http://ccs.ucsd.edu/c/charset.html#Multibyte Characters">multibyte characters</A>
|
||||
enclosed in double quotes (<CODE>"</CODE>). To make a
|
||||
<B><A NAME="wide-character string literal">
|
||||
wide-character string literal</A></B>,
|
||||
precede the string literal with an <CODE>L</CODE>:</P>
|
||||
|
||||
<P><IMG SRC="str_lit.gif" tppabs="http://ccs.ucsd.edu/c/gif/str_lit.gif"></P>
|
||||
|
||||
<P>Some valid string literals are:</P>
|
||||
|
||||
<PRE>
|
||||
"" "Good Night!\n" L"Kon ban wa"
|
||||
"abc" "\5hello\0Hello" L"exit is <$B0>"</PRE>
|
||||
|
||||
<P>The following table lists all valid
|
||||
<B><A NAME="operator token">operator</A></B> or
|
||||
<B><A NAME="punctuator token">punctuator</A></B> tokens.
|
||||
Tokens in the rightmost column are added by
|
||||
<A HREF="lib_over.html#Amendment 1" tppabs="http://ccs.ucsd.edu/c/lib_over.html#Amendment 1">Amendment 1</A>:</P>
|
||||
|
||||
<PRE>
|
||||
... && -= >= ~ + ; ] <:
|
||||
<<= &= -> >> % , < ^ :>
|
||||
>>= *= /= ^= & - = { <%
|
||||
!= ++ << |= ( . > | %>
|
||||
%= += <= || ) / ? } %:
|
||||
## -- == ! * : [ # %:%:</PRE>
|
||||
|
||||
<P>Any character standing alone
|
||||
<B><A NAME="other token">other</A></B> than one from the
|
||||
<A HREF="charset.html#basic C character set" tppabs="http://ccs.ucsd.edu/c/charset.html#basic C character set">basic C character set</A>
|
||||
forms a preprocessing token by itself. For example,
|
||||
some other characters often found in character sets
|
||||
are <CODE>@</CODE> and <CODE>$</CODE>.</P>
|
||||
|
||||
<P>You use other characters for one of two purposes:</P>
|
||||
|
||||
<UL>
|
||||
<LI>to build string literals, when you create string literals from
|
||||
macro arguments during
|
||||
<A HREF="#Expanding Macros">macro expansion</A>
|
||||
|
||||
<LI>as part of text that you skip with
|
||||
<A HREF="#Conditional Directives">conditional directives</A>
|
||||
</UL>
|
||||
|
||||
<P>Thus, almost any form that you write will be recognized as a
|
||||
valid preprocessing token. Do not, however, write an unbalanced single
|
||||
or double quote alone on a source line and outside other enclosing
|
||||
quotes, as in:</P>
|
||||
|
||||
<PRE>
|
||||
#define str(x) #x
|
||||
char *name1 = str(O'Brien); <B>INVALID</B>
|
||||
char *name2 = "O'Brien"; <B>valid</B></PRE>
|
||||
|
||||
<H2><A NAME="Include Directives">Include Directives</A></H2>
|
||||
|
||||
<P>You include the contents of an
|
||||
<B><A NAME="include file">include file</A></B> --
|
||||
a standard header or another source file --
|
||||
in a translation unit by writing an
|
||||
<B><A NAME="include directive"><I>include</I> directive</A></B>.
|
||||
The contents of the specified
|
||||
<A HREF="lib_over.html#standard header" tppabs="http://ccs.ucsd.edu/c/lib_over.html#standard header">standard header</A> or
|
||||
<A HREF="charset.html#source file" tppabs="http://ccs.ucsd.edu/c/charset.html#source file">source file</A>
|
||||
replace the <I>include</I> directive:</P>
|
||||
|
||||
<P><IMG SRC="include.gif" tppabs="http://ccs.ucsd.edu/c/gif/include.gif"></P>
|
||||
|
||||
<P>Following the directive name <CODE>include</CODE>, write one of the
|
||||
following:</P>
|
||||
|
||||
<UL>
|
||||
<LI>a standard header name between angle brackets
|
||||
|
||||
<LI>a <A HREF="lib_over.html#filename" tppabs="http://ccs.ucsd.edu/c/lib_over.html#filename">filename</A> between double quotes
|
||||
|
||||
<LI>any other form that expands to one of the two previous forms
|
||||
after macro replacement
|
||||
</UL>
|
||||
|
||||
<P>Some examples are:</P>
|
||||
|
||||
<PRE>
|
||||
#include <stdio.h> <B>declare I/O functions</B>
|
||||
#include "mydecs.h" <B>and custom ones</B>
|
||||
#include MACHDEFS <B>MACHDEFS defined earlier</B></PRE>
|
||||
|
||||
<P>A standard header name:</P>
|
||||
|
||||
<UL>
|
||||
<LI>cannot contain a right angle bracket (<CODE>></CODE>)
|
||||
|
||||
<LI>should not contain the sequence that begins a comment (<CODE>/*</CODE>)
|
||||
</UL>
|
||||
|
||||
<P>A filename:</P>
|
||||
|
||||
<UL>
|
||||
<LI>cannot contain a double quote (<CODE>"</CODE>)
|
||||
|
||||
<LI>should not contain the sequence that begins a comment (<CODE>/*</CODE>)
|
||||
</UL>
|
||||
|
||||
<P>For maximum portability, filenames should consist of from one
|
||||
to six lowercase letters, followed by a dot (<CODE>.</CODE>), followed by
|
||||
a lowercase letter. Some portable filenames are:</P>
|
||||
|
||||
<PRE>
|
||||
"salary.c" "defs.h" "test.x"</PRE>
|
||||
|
||||
<H2><A NAME="Define Directives">Define Directives</A></H2>
|
||||
|
||||
<P>You define a macro by writing a
|
||||
<B><A NAME="define directive"><I>define</I> directive</A></B>.
|
||||
Following the directive name <CODE>define</CODE>,
|
||||
you write one of two forms:</P>
|
||||
|
||||
<UL>
|
||||
<LI>A name <I>not</I> immediately followed by a left parenthesis,
|
||||
followed by any sequence of preprocessing tokens -- to define a
|
||||
macro without parameters.
|
||||
|
||||
<LI>A name immediately followed by a left parenthesis with <I>no</I>
|
||||
intervening white space, followed by zero or more distinct
|
||||
<B><A NAME="macro parameter">macro parameter</A></B> names
|
||||
separated by commas, followed by a right parenthesis, followed
|
||||
by any sequence of preprocessing tokens -- to define a macro with
|
||||
as many parameters as names that you write inside the parentheses:
|
||||
</UL>
|
||||
|
||||
<P><IMG SRC="define.gif" tppabs="http://ccs.ucsd.edu/c/gif/define.gif"></P>
|
||||
|
||||
<P>Three examples are:</P>
|
||||
|
||||
<PRE>
|
||||
#define MIN_OFFSET (-17) <B>no parameters</B>
|
||||
#define quit() exit(0) <B>zero parameters</B>
|
||||
#define add(x, y) ((x) + (y)) <B>two parameters</B></PRE>
|
||||
|
||||
<P>Write a <I>define</I> directive that defines a name currently
|
||||
defined as a macro <I>only</I> if you write it with the identical
|
||||
sequence of preprocessing tokens as before. Where white space is present
|
||||
in one definition, white space must be present in the other. (The
|
||||
white space need not be identical.)</P>
|
||||
|
||||
<P>To remove a macro definition, write an
|
||||
<B><A NAME="undef directive"><I>undef</I> directive</A></B>:</P>
|
||||
|
||||
<P><IMG SRC="undef.gif" tppabs="http://ccs.ucsd.edu/c/gif/undef.gif"></P>
|
||||
|
||||
<P>You might want to remove a macro definition
|
||||
so that you can define it differently with a
|
||||
<A HREF="#define directive"><I>define</I> directive</A>
|
||||
or to
|
||||
<A HREF="lib_over.html#masking macro" tppabs="http://ccs.ucsd.edu/c/lib_over.html#masking macro">unmask</A>
|
||||
any other meaning given to the name.</P>
|
||||
|
||||
<P>The name whose definition you want to remove follows the directive
|
||||
name <CODE>undef</CODE>. If the name is not currently defined as a macro,
|
||||
the <I>undef</I> directive has no effect.</P>
|
||||
|
||||
<H3><A NAME="Expanding Macros">Expanding Macros</A></H3>
|
||||
|
||||
<P>Preprocessing <I>expands</I> macros in all non-directive lines
|
||||
and in parts of some directives that are not skipped as part of an
|
||||
if-group. In those places where macros are expanded, you
|
||||
<B><A NAME="macro invocation">invoke</A></B>
|
||||
a macro by writing one of the two forms:</P>
|
||||
|
||||
<UL>
|
||||
<LI>the name of a macro without parameters
|
||||
|
||||
<LI>the name of a macro with parameters, followed by a
|
||||
left parenthesis, followed by zero or more
|
||||
<B><A NAME="macro argument">macro arguments</A></B>
|
||||
separated by commas, followed by a right parenthesis.
|
||||
</UL>
|
||||
|
||||
<P>A macro argument consists of one or more preprocessing tokens.
|
||||
You must write parentheses only in balanced pairs within a macro argument.
|
||||
You must write commas only within these pairs of parentheses. For
|
||||
example, using the macros defined in the previous example, you can
|
||||
write:</P>
|
||||
|
||||
<PRE>
|
||||
if (MIN_OFFSET < x) <B>invokes MIN_OFFSET</B>
|
||||
x = add(x, 3); <B>invokes add</B></PRE>
|
||||
|
||||
<P>Following the name of a macro with parameters, you <I>must</I>
|
||||
write one macro argument for each parameter and you <I>must</I> write
|
||||
at least one preprocessing token for each macro argument. Following
|
||||
the name of a macro with parameters, you <I>must not</I> write any
|
||||
directives within the invocation and you <I>must not</I> write the
|
||||
invocation across more than one file. Following the name of a macro
|
||||
with parameters, you <I>can</I> write arbitrary white space before
|
||||
the left parenthesis and you <I>can</I> write the invocation across
|
||||
multiple source lines.</P>
|
||||
|
||||
<P>The translator expands a macro invocation by replacing the preprocessing
|
||||
tokens that constitute the invocation with a sequence of zero or more
|
||||
preprocessing tokens. It determines the replacement sequence in a
|
||||
series of steps. This example illustrates most of the steps:</P>
|
||||
|
||||
<PRE>
|
||||
#define sh(x) printf("n" #x "=%d, or %d\n",n##x,alt[x])
|
||||
#define sub_z 26
|
||||
sh(sub_z) <B>macro invocation</B></PRE>
|
||||
|
||||
<P>The steps, in order, are:</P>
|
||||
|
||||
<OL>
|
||||
<LI>The translator takes the replacement list from the sequence
|
||||
of any preprocessing tokens (and intervening white space) in the macro
|
||||
definition. It does not include leading and trailing white space as
|
||||
part of the list.
|
||||
|
||||
<PRE>
|
||||
printf("n" #x "=%d, or %d\n",n##x,alt[x])</PRE>
|
||||
|
||||
<LI>A macro parameter name must follow each <CODE>#</CODE> token
|
||||
(or <CODE>%:</CODE> token, with
|
||||
<A HREF="lib_over.html#Amendment 1" tppabs="http://ccs.ucsd.edu/c/lib_over.html#Amendment 1">Amendment 1</A>)
|
||||
in the replacement list. The translator replaces
|
||||
the <CODE>#</CODE> token and parameter name with a
|
||||
<A HREF="#Creating String Literals">created string literal</A>
|
||||
made from the corresponding (unexpanded) macro argument.
|
||||
|
||||
<PRE>
|
||||
printf("n" "sub_z" "=%d, or %d\n",n##x,alt[x])</PRE>
|
||||
|
||||
<LI>Preprocessing tokens must both precede and follow
|
||||
each <CODE>##</CODE> token (or <CODE>%:%:</CODE> token, with
|
||||
<A HREF="lib_over.html#Amendment 1" tppabs="http://ccs.ucsd.edu/c/lib_over.html#Amendment 1">Amendment 1</A>) in the replacement
|
||||
list. If either token is a macro parameter name, the translator replaces
|
||||
that name with the corresponding (unexpanded) macro argument. The
|
||||
translator then replaces the <CODE>##</CODE> token and its preceding and
|
||||
following tokens with a single preprocessing token that is the
|
||||
<B><A NAME="token concatenation">concatenation</A></B>
|
||||
of the preceding and following tokens. The result must be a valid
|
||||
preprocessing token.
|
||||
|
||||
<PRE>
|
||||
printf("n" "sub_z" "=%d, or %d\n",nsub_z,alt[x])</PRE>
|
||||
|
||||
<LI>For any remaining macro parameter names in the replacement list,
|
||||
the translator expands the corresponding macro argument. The translator
|
||||
replaces the macro parameter name in the replacement list with the
|
||||
resulting sequence.
|
||||
|
||||
<PRE>
|
||||
printf("n" "sub_z" "=%d, or %d\n",nsub_z,alt[26])</PRE>
|
||||
|
||||
<LI>The translator remembers not to further expand
|
||||
the macro (<CODE>sh</CODE> in the example) while it rescans
|
||||
the replacement list to detect macro invocations
|
||||
in the original replacement list or that it may have constructed
|
||||
as a result of any of these replacements. The replacement list can
|
||||
provide the beginning of an invocation of a macro with parameters,
|
||||
with the remainder of the invocation consisting of preprocessing tokens
|
||||
following the invocation.
|
||||
</OL>
|
||||
|
||||
<P>In the example shown, no further expansion occurs. After string
|
||||
literal concatenation, the resulting text is:</P>
|
||||
|
||||
<PRE>
|
||||
printf("nsub_z=%d, or %d\n",nsub_z,alt[26])</PRE>
|
||||
|
||||
<P>You can take advantage of rescanning by writing macros such as:</P>
|
||||
|
||||
<PRE>
|
||||
#define add(x, y) ((x) + (y))
|
||||
#define sub(x, y) ((x) - (y))
|
||||
#define math(op, a, b) op(a, b)
|
||||
math(add, c+3, d) <B>becomes ((c+3) + (d))</B></PRE>
|
||||
|
||||
<H3><A NAME="Creating String Literals">Creating String Literals</A></H3>
|
||||
|
||||
<P>The translator creates a
|
||||
<A HREF="#string literal">string literal</A> from a
|
||||
<A HREF="#macro argument">macro argument</A>
|
||||
(when its corresponding
|
||||
<A HREF="#macro parameter">macro parameter</A>
|
||||
follows a <CODE>#</CODE> token in the macro definition)
|
||||
by performing the following steps, in order:</P>
|
||||
|
||||
<OL>
|
||||
<LI>The translator discards leading and trailing white space.
|
||||
|
||||
<LI>Each preprocessing token in the macro argument appears in the
|
||||
string literal exactly as you spelled it, except that the translator
|
||||
adds a <CODE>\</CODE> before each <CODE>\</CODE> and <CODE>"</CODE>
|
||||
within a
|
||||
<A HREF="#character constant">character constant</A>
|
||||
or string literal.
|
||||
|
||||
<LI>Any white space between preprocessing tokens in the macro argument
|
||||
appears in the string literal as a <CODE><I>space</I></CODE> character.
|
||||
</OL>
|
||||
|
||||
<P>For example:</P>
|
||||
|
||||
<PRE>
|
||||
#define show(x) printf(#x "= %d\n", x)
|
||||
show(a +/* same as space */-1);
|
||||
<B>becomes:</B>
|
||||
printf("a + -1= %d\n", a + -1);</PRE>
|
||||
|
||||
<P>You can also create a
|
||||
<A HREF="#wide-character string literal">
|
||||
wide-character string literal</A>:</P>
|
||||
|
||||
<PRE>
|
||||
#define wcsl(x) L ## #x
|
||||
wcsl(arigato) <B>becomes L"arigato"</B></PRE>
|
||||
|
||||
<H2><A NAME="Conditional Directives">Conditional Directives</A></H2>
|
||||
|
||||
<P>You can selectively skip groups of lines within source files
|
||||
by writing <B>conditional</B> directives. The conditional directives
|
||||
within a source file form zero or more
|
||||
<B><A NAME="if-group">if-groups</A></B>:</P>
|
||||
|
||||
<P><IMG SRC="if_grp.gif" tppabs="http://ccs.ucsd.edu/c/gif/if_grp.gif"></P>
|
||||
|
||||
<P>Within an if-group, you write conditional directives
|
||||
to bracket one or more groups of lines, or
|
||||
<B><A NAME="line-group">line-groups</A></B>:</P>
|
||||
|
||||
<P><IMG SRC="line_grp.gif" tppabs="http://ccs.ucsd.edu/c/gif/line_grp.gif"></P>
|
||||
|
||||
<P>The translator retains no more than one line-group within an if-group.
|
||||
It skips all other line-groups. An if-group has the following general
|
||||
form:</P>
|
||||
|
||||
<UL>
|
||||
<LI>It begins with an
|
||||
<A HREF="#if directive"><I>if</I> directive</A>,
|
||||
<A HREF="#ifdef directive"><I>ifdef</I> directive</A>, or
|
||||
<A HREF="#ifndef directive"><I>ifndef</I> directive</A>,
|
||||
followed by the first line-group that you want to selectively skip.
|
||||
|
||||
<LI>Zero or more
|
||||
<A HREF="#elif directive"><I>elif</I> directives</A>,
|
||||
follow this first line-group, each followed by a line-group
|
||||
that you want to selectively skip.
|
||||
|
||||
<LI>An optional
|
||||
<A HREF="#else directive"><I>else</I> directive</A>,
|
||||
follows all line-groups controlled by <I>elif</I> directives,
|
||||
followed by the last line-group you want to selectively skip.
|
||||
|
||||
<LI>An if-group ends with an
|
||||
<A HREF="#endif directive"><I>endif</I> directive</A>.
|
||||
</UL>
|
||||
|
||||
<P>A <I>line-group</I> is zero or more occurrences
|
||||
of either an if-group or any line other than an <I>if, ifdef, ifndef,
|
||||
elif, else,</I> or <I>endif</I> directive. The translator retains no
|
||||
more than one alternative line-group:
|
||||
|
||||
<UL>
|
||||
<LI>If the condition is true in the leading <I>if, ifdef,</I> or
|
||||
<I>ifndef</I> directive, the translator retains the first line-group
|
||||
and skips all others.
|
||||
|
||||
<LI>Otherwise, if a condition is true in a subsequent <I>elif</I>
|
||||
directive, the translator retains its alternative line-group and skips
|
||||
all others.
|
||||
|
||||
<LI>Otherwise, if an <I>else</I> directive is present, the translator
|
||||
retains its alternative line-group.
|
||||
|
||||
<LI>Otherwise, the translator skips all line-groups within the if-group.
|
||||
</UL>
|
||||
|
||||
<P>For example, to retain a line-group in a header file at most
|
||||
once, regardless of the number of times the header is included:</P>
|
||||
|
||||
<PRE>
|
||||
#ifndef _SEEN
|
||||
#define _SEEN
|
||||
/* body of header */
|
||||
#endif</PRE>
|
||||
|
||||
<P>And to retain only one of three line-groups, depending on the
|
||||
value of the macro <CODE>MACHINE</CODE> defined earlier in the translation
|
||||
unit:</P>
|
||||
|
||||
<PRE>
|
||||
#if MACHINE == 68000
|
||||
int x;
|
||||
#elif MACHINE == 8086
|
||||
long x;
|
||||
#else /* all others */
|
||||
#error UNKNOWN TARGET MACHINE
|
||||
#endif</PRE>
|
||||
|
||||
<H3><A NAME="Conditional Expressions">Conditional Expressions</A></H3>
|
||||
|
||||
<P>For an
|
||||
<B><A NAME="if directive"><I>if</I> directive</A></B> (or an
|
||||
<A HREF="#elif directive"><I>elif</I> directive</A>),
|
||||
you write a
|
||||
<B><A NAME="conditional expression">conditional expression</A></B>
|
||||
following the directive name <CODE>if</CODE>:</P>
|
||||
|
||||
<P><IMG SRC="if.gif" tppabs="http://ccs.ucsd.edu/c/gif/if.gif"></P>
|
||||
|
||||
<P>If the expression you write has a nonzero value, then the
|
||||
translator retains as part of the translation unit the line-group
|
||||
immediately following the <I>if</I> directive. Otherwise, the translator
|
||||
skips this line-group.
|
||||
The translator evaluates the expression you write by performing
|
||||
the following steps. This example illustrates most of the steps, in
|
||||
order:</P>
|
||||
|
||||
<PRE>
|
||||
#define VERSION 2
|
||||
#if defined x || y || VERSION < 3</PRE>
|
||||
|
||||
<OL>
|
||||
<LI>The translator replaces each occurrence of the name
|
||||
<B><A NAME="defined operator"><CODE>defined</CODE></A></B>,
|
||||
followed by another name or by another name enclosed in parentheses.
|
||||
The replacement is <CODE>1</CODE> if the second name is defined as a macro;
|
||||
otherwise, the replacement is <CODE>0</CODE>.
|
||||
|
||||
<PRE>
|
||||
#if 0 || y || VERSION < 3</PRE>
|
||||
|
||||
<LI>The translator expands macros in the expression.
|
||||
|
||||
<PRE>
|
||||
#if 0 || y || 2 < 3</PRE>
|
||||
|
||||
<LI>The translator replaces each remaining name with <CODE>0</CODE>.
|
||||
|
||||
<PRE>
|
||||
#if 0 || 0 || 2 < 3</PRE>
|
||||
|
||||
<LI>The translator converts preprocessing tokens to
|
||||
<A HREF="syntax.html#C Tokens" tppabs="http://ccs.ucsd.edu/c/syntax.html#C Tokens">C tokens</A> and
|
||||
then parses and evaluates the expression.
|
||||
|
||||
<PRE>
|
||||
#if 1</PRE>
|
||||
</OL>
|
||||
|
||||
<P>Thus, in this example, the translator retains
|
||||
the line-group following the <I>if</I> directive.</P>
|
||||
|
||||
<H3><A NAME="Restrictions on Conditional Expressions">Restrictions on Conditional Expressions</A></H3>
|
||||
|
||||
<P>In the
|
||||
<B><A NAME="if expression">expression</A></B> part of an
|
||||
<A HREF="#if directive"><I>if</I> directive</A>,
|
||||
you write only
|
||||
<A HREF="express.html#integer constant expression" tppabs="http://ccs.ucsd.edu/c/express.html#integer constant expression">
|
||||
integer constant expressions</A>, with the following
|
||||
additional considerations:</P>
|
||||
|
||||
<UL>
|
||||
<LI>You cannot write the
|
||||
<A HREF="express.html#sizeof operator" tppabs="http://ccs.ucsd.edu/c/express.html#sizeof operator"><I>sizeof</I></A> or
|
||||
<A HREF="express.html#Type Cast" tppabs="http://ccs.ucsd.edu/c/express.html#Type Cast">type cast</A> operators.
|
||||
(The translator expands all macro names,
|
||||
then replaces each remaining name with 0,
|
||||
before it recognizes keywords.)
|
||||
|
||||
<LI>The translator may be able to represent a broader range of integers
|
||||
than the target environment.
|
||||
|
||||
<LI>The translator represents type <I>int</I> the same as <I>long,</I>
|
||||
and <I>unsigned int</I> the same as <I>unsigned long.</I>
|
||||
|
||||
<LI>The translator can translate
|
||||
<A HREF="#character constant">character constants</A>
|
||||
to a set of code values different from the set
|
||||
for the target environment.
|
||||
</UL>
|
||||
|
||||
<P>To determine the properties of the target environment by writing
|
||||
<A HREF="#if directive"><I>if</I> directives</A>,
|
||||
test the values of the macros defined in
|
||||
<A HREF="limits.html" tppabs="http://ccs.ucsd.edu/c/limits.html"><CODE><limits.h></CODE></A>.</P>
|
||||
|
||||
<H3><A NAME="Other Conditional Directives">Other Conditional Directives</A></H3>
|
||||
|
||||
<P>The <B><A NAME="ifdef directive"><I>ifdef</I> directive</A></B>
|
||||
tests whether a macro name is defined:</P>
|
||||
|
||||
<P><IMG SRC="ifdef.gif" tppabs="http://ccs.ucsd.edu/c/gif/ifdef.gif"></P>
|
||||
|
||||
<P>The directive:</P>
|
||||
|
||||
<PRE>
|
||||
#ifdef xyz</PRE>
|
||||
|
||||
<P>is equivalent to:</P>
|
||||
|
||||
<PRE>
|
||||
#if defined xyz</PRE>
|
||||
|
||||
<P>The <B><A NAME="ifndef directive"><I>ifndef</I> directive</A></B>
|
||||
tests whether a macro name is <I>not</I> defined:</P>
|
||||
|
||||
<P><IMG SRC="ifndef.gif" tppabs="http://ccs.ucsd.edu/c/gif/ifndef.gif"></P>
|
||||
|
||||
<P>The directive:</P>
|
||||
|
||||
<PRE>
|
||||
#ifndef xyz</PRE>
|
||||
|
||||
<P>is equivalent to:</P>
|
||||
|
||||
<PRE>
|
||||
#if !defined xyz</PRE>
|
||||
|
||||
<P>You can provide an alternative line-group
|
||||
within an if-group by writing an
|
||||
<B><A NAME="elif directive"><I>elif</I> directive</A></B>:</P>
|
||||
|
||||
<P><IMG SRC="elif.gif" tppabs="http://ccs.ucsd.edu/c/gif/elif.gif"></P>
|
||||
|
||||
<P>Following the directive name <CODE>elif</CODE>,
|
||||
you write an expression just as for an
|
||||
<A HREF="#if directive"><I>if</I> directive</A>.
|
||||
The translator retains the alternative
|
||||
line-group following the <I>elif</I> directive if the expression is
|
||||
true and if no earlier line-group has been retained
|
||||
in the same if-group.</P>
|
||||
|
||||
<P>You can also provide a last alternative line-group by writing an
|
||||
<B><A NAME="else directive"><I>else</I> directive</A></B>:</P>
|
||||
|
||||
<P><IMG SRC="else.gif" tppabs="http://ccs.ucsd.edu/c/gif/else.gif"></P>
|
||||
|
||||
<P>You terminate the last alternative line-group
|
||||
within an if-group by writing an
|
||||
<B><A NAME="endif directive"><I>endif</I> directive</A></B>:</P>
|
||||
|
||||
<P><IMG SRC="endif.gif" tppabs="http://ccs.ucsd.edu/c/gif/endif.gif"></P>
|
||||
|
||||
<H2><A NAME="Other Directives">Other Directives</A></H2>
|
||||
|
||||
<P>You alter the source
|
||||
<A HREF="#source line number">line number</A> and
|
||||
<A HREF="#source line number">filename</A> by writing a
|
||||
<B><A NAME="line directive"><I>line</I> directive</A></B>.
|
||||
The translator uses the line number and filename
|
||||
to alter the values of the predefined macros
|
||||
<A HREF="#__FILE__"><CODE>__FILE__</CODE></A> and
|
||||
<A HREF="#__LINE__"><CODE>__LINE__</CODE></A>:</P>
|
||||
|
||||
<P><IMG SRC="line.gif" tppabs="http://ccs.ucsd.edu/c/gif/line.gif"></P>
|
||||
|
||||
<P>Following the directive name <CODE>line</CODE>, write one of the following:</P>
|
||||
|
||||
<UL>
|
||||
<LI>a decimal integer (giving the new line number of the line following)
|
||||
|
||||
<LI>a decimal integer as before, followed by a string literal (giving
|
||||
the new line number and the new source filename)
|
||||
|
||||
<LI>any other form that expands to one of the two previous forms
|
||||
after macro replacement
|
||||
</UL>
|
||||
|
||||
<P>You generate an unconditional diagnostic message by writing an
|
||||
<B><A NAME="error directive"><I>error</I> directive</A></B>:</P>
|
||||
|
||||
<P><IMG SRC="error.gif" tppabs="http://ccs.ucsd.edu/c/gif/error.gif"></P>
|
||||
|
||||
<P>Following the directive name <CODE>error</CODE>, write any text
|
||||
that the translator can parse as preprocessing tokens. The translator
|
||||
writes a diagnostic message that includes this sequence of preprocessing
|
||||
tokens. For example:</P>
|
||||
|
||||
<PRE>
|
||||
#if !defined VERSION
|
||||
#error You failed to specify a VERSION
|
||||
#endif</PRE>
|
||||
|
||||
<P>You convey additional information to the translator by writing a
|
||||
<B><A NAME="pragma directive"><I>pragma</I> directive</A></B>:</P>
|
||||
|
||||
<P><IMG SRC="pragma.gif" tppabs="http://ccs.ucsd.edu/c/gif/pragma.gif"></P>
|
||||
|
||||
<P>Following the directive name <CODE>pragma</CODE>, write any text
|
||||
that the translator can parse as preprocessing tokens. Each translator
|
||||
interprets this sequence of preprocessing tokens in its own way and
|
||||
ignores those <I>pragma</I> directives that it does not understand.</P>
|
||||
|
||||
<P>You introduce comments or additional white space
|
||||
into the program by writing a
|
||||
<B><A NAME="null directive"><I>null</I> directive</A></B>:</P>
|
||||
|
||||
<P><IMG SRC="null.gif" tppabs="http://ccs.ucsd.edu/c/gif/null.gif"></P>
|
||||
|
||||
<P>The <I>null</I> directive is the only directive that does not
|
||||
have a directive name following the <CODE>#</CODE> token. For example:</P>
|
||||
|
||||
<PRE>
|
||||
#
|
||||
# /* this part for testing only */ <B>valid</B>
|
||||
#define comment /* comment only */
|
||||
#
|
||||
# comment <B>INVALID</B></PRE>
|
||||
|
||||
<H2><A NAME="Predefined Macros">Predefined Macros</A></H2>
|
||||
|
||||
<P>The translator predefines several macro names.</P>
|
||||
|
||||
<P>The macro
|
||||
<B><A NAME="__DATE__"><CODE>__DATE__</CODE></A></B>
|
||||
expands to a string literal that gives
|
||||
the date you invoked the translator.
|
||||
Its format is <CODE>"Mmm dd yyyy"</CODE>.
|
||||
The month name <CODE>Mmm</CODE> is the same as for dates
|
||||
generated by the library function
|
||||
<A HREF="time.html#asctime" tppabs="http://ccs.ucsd.edu/c/time.html#asctime"><CODE>asctime</CODE></A>.
|
||||
The day part <CODE>dd</CODE> ranges from <CODE>" 1"</CODE> to <CODE>"31"</CODE> (a leading <CODE>0</CODE>
|
||||
becomes a <CODE><I>space</I></CODE>).</P>
|
||||
|
||||
<P>The macro
|
||||
<B><A NAME="__FILE__"><CODE>__FILE__</CODE></A></B>
|
||||
expands to a string literal that gives the remembered
|
||||
<B><A NAME="source filename">filename</A></B>
|
||||
of the current source file. You can alter
|
||||
the remembered filename by writing a
|
||||
<A HREF="#line directive"><I>line</I> directive</A>.</P>
|
||||
|
||||
<P>The macro
|
||||
<B><A NAME="__LINE__"><CODE>__LINE__</CODE></A></B>
|
||||
expands to a decimal integer constant that gives the remembered
|
||||
<B><A NAME="source line number">line number</A></B>
|
||||
within the current source file.
|
||||
You can alter the remembered line number by writing a
|
||||
<A HREF="#line directive"><I>line</I> directive</A>.</P>
|
||||
|
||||
<P>The macro
|
||||
<B><A NAME="__STDC__"><CODE>__STDC__</CODE></A></B>
|
||||
expands to the decimal integer constant <CODE>1</CODE>.
|
||||
The translator should provide another value (or leave the
|
||||
macro undefined) when you invoke it for other than a Standard C environment.
|
||||
For example, you can write:</P>
|
||||
|
||||
<PRE>
|
||||
#if __STDC__ != 1
|
||||
#error NOT a Standard C environment
|
||||
#endif</PRE>
|
||||
|
||||
<P>The macro
|
||||
<B><A NAME="__STDC_VERSION__"><CODE>__STDC_VERSION__</CODE></A></B>
|
||||
expands to the decimal integer constant <CODE>199409L</CODE>.
|
||||
The translator should provide another value
|
||||
(or leave the macro undefined) when you invoke it for other than a
|
||||
Standard C environment that incorporates
|
||||
<A HREF="lib_over.html#Amendment 1" tppabs="http://ccs.ucsd.edu/c/lib_over.html#Amendment 1">Amendment 1</A>.</P>
|
||||
|
||||
<P>The macro
|
||||
<B><A NAME="__TIME__"><CODE>__TIME__</CODE></A></B>
|
||||
expands to a string literal that gives
|
||||
the time you invoked the translator. Its format is <CODE>"hh:mm:ss"</CODE>,
|
||||
which is the same as for times generated by the library function
|
||||
<A HREF="time.html#asctime" tppabs="http://ccs.ucsd.edu/c/time.html#asctime"><CODE>asctime</CODE></A>.</P>
|
||||
|
||||
<P>You cannot write these macro names, or the name
|
||||
<A HREF="#defined operator"><CODE>defined</CODE></A>, in an
|
||||
<A HREF="#undef directive"><I>undef</I> directive</A>.
|
||||
Nor can you redefine these names with a
|
||||
<A HREF="#define directive"><I>define</I> directive</A>.</P>
|
||||
|
||||
<HR>
|
||||
<P>See also the
|
||||
<B><A HREF="index.html#Table of Contents" tppabs="http://ccs.ucsd.edu/c/index.html#Table of Contents">Table of Contents</A></B> and the
|
||||
<B><A HREF="_index.html" tppabs="http://ccs.ucsd.edu/c/_index.html">Index</A></B>.</P>
|
||||
|
||||
<P><I>
|
||||
<A HREF="crit_pb.html" tppabs="http://ccs.ucsd.edu/c/crit_pb.html">Copyright</A> © 1989-1996
|
||||
by P.J. Plauger and Jim Brodie. All rights reserved.</I></P>
|
||||
|
||||
</BODY></HTML>
|
||||
BIN
study/Ref-docs/C/print.gif
Normal file
|
After Width: | Height: | Size: 1.9 KiB |
BIN
study/Ref-docs/C/proto_d.gif
Normal file
|
After Width: | Height: | Size: 1.3 KiB |