CONTENTS Title Page Copyright Page Preface 1 Developing PDP-11 C Programs 1.1 DCL Commands for Program Development 1.2 Creating a PDP-11 C Program 1.2.1 Using EDT 1.2.2 Using VAXTPU 1.2.3 Using KED 1.3 Compiling a PDP-11 C Program 1.3.1 The Compile Command 1.3.1.1 Compiling a Program on RSX Systems 1.3.1.2 Compiling a Program on RSTS/E Systems 1.3.1.3 Compiling a Program on RT-11 Systems 1.3.1.4 Compiling a Program on VMS Systems 1.3.2 Prompt Mode 1.3.3 Indirect Command Files 1.3.4 The PDP-11 C Command Qualifiers 1.3.5 Compiler Error Messages 1.3.6 Compiler Listings 1.4 Copying Files Among Target Environments 1.4.1 File Transfer (FIT) Program 1.4.2 File Transfer Utility (FLX) 1.4.3 VMS EXCHANGE Utility 1.5 Linking a PDP-11 C Program 1.5.1 PDP-11 C Run-Time System Object Libraries 1.5.2 Invoking the Task Builder on RSX Systems 1.5.3 Linking on RSTS/E Systems 1.5.3.1 Invoking the RSX Task Builder on RSTS/E 1.5.3.2 Invoking the RT-11 Linker on RSTS/E 1.5.4 Linking on RT-11 Systems 1.5.5 Linking Using VAX-11 RSX on VMS Systems 1.5.6 Task Builder Command-Line Elements 1.5.6.1 Creating CMD and ODL Files for Task Building 1.5.6.2 Command-Line Elements in CMD Files 1.5.6.3 Task Builder Qualifiers 1.5.7 Task Builder Error Messages 1.6 Running a PDP-11 C Program 1.7 Library Usage on RSX and RSTS/E Systems 1.7.1 Library Usage on RSX Systems 1.7.2 Library Usage with TKB on RSTS/E Systems 1.8 Overlays 1.9 Debugging a PDP-11 C Program 2 Program Structure 2.1 C Programming Language Background 2.2 The PDP-11 C Programming Language 2.3 Writing a Program 2.4 Producing Input/Output 2.5 Controlling Program Flow 2.5.1 Testing for a Condition (if Statement) 2.5.2 Testing for Multiple Conditions (switch Statement) 2.5.3 Loops 2.6 Values, Addresses, and Pointers 2.7 Function Definitions 2.7.1 Main Function and Function Identifiers 2.7.2 Parameter List Declarations 2.7.3 Function-Return Data Types 2.7.4 Variable-Length Parameter Lists 2.8 Function Declarations 2.8.1 Function Prototypes 2.9 Using Parameters and Arguments 2.9.1 Function and Array Identifiers as Arguments 2.9.2 Passing Arguments to the Function Main 2.10 Identifiers 2.11 Keywords 2.12 Blocks 2.13 Comments 2.14 Lexical Continuation 2.15 String Literal Concatenation 2.16 Trigraphs 3 Statements 3.1 The Labeled Statement 3.2 Compound Statement 3.3 The Null Statement 3.4 The Expression Statement 3.5 Selection Statements 3.5.1 The if Conditional Statement 3.5.2 The switch Statement 3.6 Iteration Statements (Looping) 3.6.1 The while Statement 3.6.2 The for Statement 3.6.3 The do Statement 3.7 Jump Statements 3.7.1 The goto Statement 3.7.2 The continue Statement 3.7.3 The break Statement 3.7.4 The return Statement 4 Expressions and Operators 4.1 Addresses (lvalues) and Objects (rvalues) of Variables 4.2 Overview of the PDP-11 C Operators 4.3 Primary Expressions and Operators 4.3.1 Parenthetical Expressions 4.3.2 Function Calls 4.3.3 Array References 4.3.4 Structure and Union References 4.4 Unary Operators 4.4.1 Negating Arithmetic and Logical Expressions 4.4.2 Incrementing and Decrementing Variables 4.4.3 Computing Addresses and Dereferencing Pointers (& * ) 4.4.4 Calculating a One's Complement ( ~ ) 4.4.5 Forcing Conversions to a Specific Type (Cast Operator) 4.4.6 Calculating Sizes of Variables and Data Types (sizeof) 4.5 Binary Operators 4.5.1 Additive Operators (+ -) 4.5.2 Multiplication Operators ( * / %) 4.5.3 Equality Operators (= = !=) 4.5.4 Relational Operators (< > <= >=) 4.5.5 Bitwise Operators (& | ^) 4.5.6 Logical Operators (&& | | ) 4.5.7 Shift Operators (<< >>) 4.6 Conditional Operator (?:) 4.7 Assignment Expressions and Operators 4.8 Comma Expression and Operator ( , ) 4.9 Data Type Conversions 4.9.1 Converting Operands 4.9.2 Converting Function Arguments 5 Data Types and Declarations 5.1 Constants 5.2 Variables 5.2.1 Classification of Variables 5.2.1.1 Data Type Keywords 5.2.1.2 Format of a Variable Declaration 5.3 Integers (int, long, short, char, signed, unsigned) 5.3.1 Integer Constants 5.3.2 Character Constants 5.3.3 Escape Sequences 5.4 Floating-Point Numbers (float, double) 5.5 Pointers 5.6 Enumerated Types (enum) 5.7 Arrays ([ ]) 5.7.1 Initialization of Arrays 5.8 Character-String Variables and Constants (char * , char[ ]) 5.9 Structures and Unions (struct, union) 5.9.1 Declaring a Structure or Union 5.9.2 Referencing Members of Structures or Unions 5.9.3 Initialization of Structures and Unions 5.9.4 Variant Structures and Unions 5.9.5 Bit-Fields 5.10 Aggregates 5.10.1 Arrays and Character Strings 5.10.2 Structures and Unions 5.11 The void Keyword 5.12 The typedef Keyword 5.13 Interpreting Declarations 6 Scope, Storage Classes, and Allocation 6.1 The Scope of an Identifier 6.1.1 The Compilation and Linking Process 6.1.2 Position of the Declaration 6.1.3 Lexical Scope and Link-Time Scope 6.1.4 Program Example 6.2 Storage Allocation 6.3 Internal Storage Class 6.3.1 Defining a Variable for Automatic Storage Allocation (auto) 6.3.2 Defining a Variable for Placement in a Machine Register (register) 6.4 Static Storage Class 6.5 Global Storage Class 6.5.1 Global Names on PDP-11 Systems 6.5.2 Global Definitions 6.6 Defining Global Definitions (globaldef) and References (globalref) 6.7 Defining Global Values (globalvalue) 6.8 Explicit psect Control 6.8.1 Reducing Storage Requirements in Overlaid Tasks 6.8.2 Data Sharing Using psects 6.9 Data Type Qualifiers 6.9.1 The const Qualifier 6.9.2 The volatile Qualifier 6.10 Storage-Class Specifiers 7 Preprocessor Directives 7.1 Token Definitions (#define, #undef) 7.1.1 Object-Like Macros 7.1.2 Canceling Definitions (#undef) 7.1.3 Function-Like Macros 7.1.3.1 Stringizing Preprocessing Operator ( # ) 7.1.3.2 Token Concatenation Preprocessing Operator (##) 7.1.4 Listing Substituted Lines 7.2 Conditional Compilation (#if, #ifdef, #ifndef, #else, #elif, #endif) 7.2.1 The #error Directive 7.2.2 The defined Operator 7.3 File Inclusion (#include) 7.3.1 Inclusion Using Angle Brackets ( <> ) 7.3.2 Inclusion Using Quotation Marks ( " " ) 7.3.3 Token Substitution in #include Directives 7.4 Specification of Line Numbers (#line, #) 7.5 Specification of Module Name and Identification (#module) 7.6 Implementation-Specific Preprocessor Directive (#pragma) 7.6.1 #pragma charset 7.6.2 #pragma psect 7.6.3 #pragma module 7.6.4 #pragma list 7.6.5 #pragma linkage 7.6.6 #pragma [no]standard 7.7 Predefined Macros 7.7.1 PDP-11 C Predefined Macros 7.7.2 Digital Extension Macros 7.7.3 The _ _DATE_ _ Macro 7.7.4 The _ _TIME_ _ Macro 7.7.5 The _ _FILE_ _ Macro 7.7.6 The _ _LINE_ _ Macro 7.7.7 The _ _STDC_ _ Macro 7.7.8 The _ _RAD50 and _ _RAD50L Macros 8 PDP-11 C Implementation Notes 8.1 Use of Memory Management Functions 8.2 Compilation Performance and Capacity on PDP-11 Host Systems 8.2.1 Data Caching 8.2.2 PDP-11 C Work File 8.3 PDP-11 C Run-Time Psects 8.4 Overlaying Tasks 8.5 RT-11 User Service Routine (USR) Load Area 8.6 Event Flags 8.7 Argument Passing Using Linkages 8.8 Defining Your Own Locales A PDP-11 C Compiler Messages A.1 Introduction A.2 Compiler Messages ALC_TEMPOVERFLOW . . . CLP_INPUT_LINE_LONG CLP_INV_FILENAME . . . CLP_MISS_VALUE CLP_MODE_INCONSIST . . . LEX_CLOSE_FAILED LEX_CMT_UNCLOSED . . . LEX_IFEVALSTACK LEX_IFSYNTAX . . . LEX_INVALIDIF LEX_INVDEFNAME . . . LEX_IOEXISTS LEX_IOFNF . . . LEX_MESCHARSETDEF LEX_MESCHARSETREF . . . LEX_PASTEATEND LEX_PASTEUPFRONT . . . LEX_TOOMANYMACPARM LEX_UNDEFIFMAC . . . MIO_STACKOVERFLOW MRF_CLOSE . . . OGN_NO_OBJ_PRODUCED OGN_NO_ROOM_FOR_FILE . . . OVL_ROOT OVL_ROOT2 . . . SYN_BADPSECT SYN_BITWINTREQ . . . SYN_DUPMAINFUNC SYN_DUPMEMBER . . . SYN_ILLFUNCPARAM SYN_ILLFUNCTYPE . . . SYN_INVBREAK SYN_INVCASEEXPR . . . SYN_INVFUNCCLASS SYN_INVFUNCDECL . . . SYN_INVREL SYN_INVSTORCLASS . . . SYN_LREM_INT SYN_MAIN02PARAMS . . . SYN_SHIFTINTREQ SYN_SIZEOFOBJ . . . SYN_UNDEFSTRUCT SYN_UNOTSCALREQ . . . WF_UNEXPECTED B PDP-11 C Header Files C PDP-11 C Internationalization C.1 Compiler Internationalization C.2 Run-Time Internationalization C.2.1 Set Locale Function (setlocale) C.2.2 Defining a Locale Structure (localeconv) C.2.3 Character Handling Functions D Language Summary D.1 Data Type Keywords D.2 Precedence of Operators D.3 Statements D.4 Conversion Rules D.5 PDP-11 C Escape Sequences D.6 Preprocessor Directives Glossary additive operator . . . asterisk ( ) auto storage class . . . compound statement conditional operator . . . elements enumerated type . . . function prototype fundamental type . . . lexical scope lifetime . . . module multiplication operator . . . pointer portability . . . rvalue scalar . . . storage class storage class qualifiers . . . value variable . . . work file EXAMPLES 1-1 Default Compiler Listing 1-2 Compiler Listing Options 2-1 Simple Addition in PDP-11 C 2-2 Output of Information 2-3 Output Using the Newline Character 2-4 Conditional Execution Using the if Statement 2-5 Conditional Execution Using the switch Statement 2-6 Looping Using the do Statement 2-7 Looping Using the for Statement 2-8 Case Conversion Program 2-9 Including <stdarg.h> in a Parameter List 2-10 Declaring Functions 2-11 Declaring Functions Passed as Arguments 2-12 Echo Program Using Command-Line Arguments 2-13 Scope of Variable Declarations in Nested Blocks 3-1 Counting Blanks, Tabs, and Newlines Using the switch Statement 5-1 Initializing an Array of Structures 5-2 Character String Constants and Arrays 5-3 Single Storage Allocation of Unions 5-4 Structures 6-1 Scope and Externally Defined Variables 6-2 Reinitializing Two auto Variables 6-3 Using the globalvalue Specifier 7-1 Nested Substitution Directives 7-2 Using _ _RAD50 and _ _RAD50L Macros 8-1 Setting Up Your Own Locale Tables C-1 Sample Program Using localeconv C-2 Using the Macro and Function Versions of isalnum FIGURES 1-1 DCL Commands for Developing Programs 2-1 rvalues, lvalues, and Assigning Pointers 2-2 The Indirection Operator in Assignments 4-1 Boolean Algebra and the Bitwise Operators 4-2 Shift Operators 5-1 Alignment of Structure Members TABLES 1-1 Copying Files Among Operating Systems 2-1 PDP-11 C Keywords 2-2 VAX C Keywords 2-3 Trigraph Sequences and Equivalence Characters 4-1 PDP-11 C Operators 4-2 Precedence of PDP-11 C Operators 5-1 PDP-11 C Data Type Keywords 5-2 Size and Range of PDP-11 C Integers 5-3 PDP-11 C Escape Sequences 6-1 PDP-11 C Storage Classes and Storage-Class Specifiers 6-2 Scope and the Storage-Class Specifiers 6-3 Location, Lifetime, and the Storage-Class Keywords 7-1 Logical Names for PDP-11 C Include Files 7-2 PDP-11 Character Sets 7-3 Psect Types and Associated Data Types 8-1 PDP-11 RTL Psects B-1 PDP-11 C Standard Library Header Files B-2 PDP-11 C FCS Extension Library Header Files B-3 PDP-11 C RMS Extension Library Header Files B-4 PDP-11 C System Interface Header Files D-1 Data Type Keywords D-2 Precedence of Operators