On 24/02/2011, at 3:11 AM, Kari Laitinen wrote: > A classic book about the C programming language > begins with a program that contains the statement > > printf("hello, world"); > > It has been said, however, that the printf function > that is used in the above statement does not > belong to the language itself but it is a library > function.
We can draw a parallel to open class and closed class words in a natural language. Pronouns, determiners, conjunctions, prepositions; these are not wholly unlike keywords in a language. (Indeed, keywords are often prepositions, and I do not believe this is accidental.) Variable and function names are not wholly unlike open class words. Would you say that open class words are not part of a language? If you came across a sentence written using English syntax and closed-class words but Japanese open class words, would it still be English? I say that a type, variable, or function "belongs to the language" if it is specified in the best available description of the language. By that criterion, printf is definitely part of the C language. A C compiler (like gcc) is fully within its rights to look at a call of printf() and exploit information in the standard but not in the type of the identifier to check that the format string makes sense and agrees with the actual parameters. > To me, this raises questions: Why > begin a book about a programming language by > showing something that does not belong to the language? Because the claim that it does not is false. At a minimum, a programming language must provide - constants - variables - user defined functions - built in functions - combining forms One important criterion is whether an operation could be provided in the language if it were not in the standard. Take fopen() as an example. Given only the rest of C, fopen() would not be definable. Out of putc(), fwrite(), and fprintf(), at least one of them must be provided in the language; given any one of them the others are definable. -- The Open University is incorporated by Royal Charter (RC 000391), an exempt charity in England & Wales and a charity registered in Scotland (SC 038302).