.\" $Header$ .nr ID 4 .de hd 'sp 2 'tl ''-%-'' 'sp 3 .. .de fo 'bp .. .tr ~ . TITLE .de TL .sp 15 .ce \\fB\\$1\\fR .. . AUTHOR .de AU .sp 15 .ce by .sp 2 .ce \\$1 .. . DATE .de DA .sp 3 .ce ( Dated \\$1 ) .. . INSTITUTE .de VU .sp 3 .ce 4 Wiskundig Seminarium Vrije Universteit De Boelelaan 1081 Amsterdam .. . PARAGRAPH .de PP .sp .ti +\n(ID .. .nr CH 0 1 . CHAPTER .de CH .nr SH 0 1 .bp .in 0 \\fB\\n+(CH.~\\$1\\fR .PP .. . SUBCHAPTER .de SH .sp 3 .in 0 \\fB\\n(CH.\\n+(SH.~\\$1\\fR .PP .. . INDENT START .de IS .sp .in +\n(ID .. . INDENT END .de IE .in -\n(ID .sp .. .de PT .ti -\n(ID .ta \n(ID .fc " @ "\\$1@"\c .fc .. . DOUBLE INDENT START .de DS .sp .in +\n(ID .ll -\n(ID .. . DOUBLE INDENT END .de DE .ll +\n(ID .in -\n(ID .sp .. . EQUATION START .de EQ .sp .nf .. . EQUATION END .de EN .fi .sp .. . ITEM .de IT .sp .in 0 \\fB~\\$1\\fR .ti +5 .. .de CS .br ~-~\\ .. .br .fi .TL "Ack-C reference manual" .AU "Ed Keizer" .DA "September 12, 1983" .VU .wh 0 hd .wh 60 fo .CH "Introduction" The C frontend included in the Amsterdam Compiler Kit translates UNIX-V7 C into compact EM code [1]. The language accepted is described in [2] and [3]. This document describes which implementation dependent choices were made in the Ack-C frontend and some restrictions and additions. .CH "The language" .PP Under the same heading as used in [2] we describe the properties of the Ack-C frontend. .IT "2.2 Identifiers" External identifiers are unique up to 7 characters and allow both upper and lower case. .IT "2.3 Keywords" The word \fBvoid\fP is also reserved as a keyword. .IT "2.4.3 Character constants" The ASCII-mapping is used when a character is converted to an integer. .IT "2.4.4 Floating constants" To prevent loss of precision the compiler does not perform floating point constant folding. .IT "2.6 Hardware characteristics" The size of objects of the several arithmetic types and pointers depend on the EM-implementation used. The ranges of the arithmetic types depend on the size used, the C-frontend assumes two's complement representation for the integral types. All sizes are multiples of bytes. The calling program \fIack\fP[4] passes information about the size of the types to the compiler proper. .br However, a few general remarks must be made: .sp 1 .IS .PT (a) The size of pointers is a multiple of (or equal to) the size of an \fIint\fP. .PT (b) The following relations exist for the sizes of the types mentioned: .br .ti +5 \fIchar<=short<=int<=long\fP .PT (c) Objects of type \fIchar\fP use one 8-bit byte of storage, although several bytes are allocated sometimes. .PT (d) All sizes are in multiples of bytes. .PT (e) Most EM implementations use 4 bytes for floats and 8 bytes for doubles, but exceptions to this rule occur. .IE .IT "4 What's in a name" The type \fIvoid\fP is added. Objects of type void do not exist. Functions declared as returning void, do not return a value at all. .IT "6.1 Characters and integers" Objects of type \fIchar\fP are unsigned and do not cause sign-extension when converted to \fIint\fP. The range of characters values is from 0 to 255. .IT "6.3 Floating and integral" Floating point numbers are truncated towards zero when converted to the integral types. .IT "6.4 Pointers and integers" When a \fIlong\fP is added to or subtracted from a pointer and longs are larger then pointers the \fIlong\fP is converted to an \fIint\fP before the operation is performed. .IT "7.2 Unary operators" It is allowed to cast any expression to the type \fIvoid\fP. .IT "8.2 Type specifiers" One type is added to the type-specifiers: .br .IS void .IE .IT "8.5 Structure and union declarations" The only type allowed for fields is \fIint\fP. Fields with exactly the size of \fIint\fP are signed, all other fields are unsigned. .br The size of any single structure must be less then 4096 bytes. .IT "8.6 Initialization" Initialization of structures containing bit fields is not allowed. There is one restriction when using an 'address expression' to initialize an integral variable. The integral variable must have the same size as a pointer. Conversions altering the size of the address expression are not allowed. .IT "9.10 Return statement" Return statements of the form: .IS return ; .IE are the only form of return statement allowed in a function of type function returning void. .IT "10.1 External function definitions" The total amount for storage used for parameters in any function must be less then 4096 bytes. The same holds for the total amount of storage occupied by the automatic variables declared inside any function. .sp Using formal parameters whose size is smaller the the size of an int is less efficient on several machines. At procedure entry these parameters are converted from integer to the declared type, because the compiler doesn't know where the least significant bytes are stored in the int. .IT "11.2 Scope of externals" Most C compilers are rather lax in enforcing the restriction that only one external definition without the keyword \fIextern\fP is allowed in a program. The Ack-C frontend is very strict in this. The only exception is that declarations of arrays with a missing first array bounds expression are regarded to have an explicit keyword \fIextern\fP. .IT "14.4 Explicit pointer conversions" Pointers may be larger the ints, thus assigning a pointer to an int and back will not always result in the same pointer. The process mentioned above works with integrals of the same size or larger as pointers in all EM implementations having such integrals. When converting pointers to an integral type or vice-versa, the pointers is seen as an unsigned int. .br EM guarantees that any object can be placed at a word boundary, this allows the C-programs to use \fIint\fP pointers as pointers to objects of any type not smaller than an \fIint\fP. .CH "Frontend options" The C-frontend has a few options, these are controlled by flags: .IS .PT -V This flag is followed by a sequence of letters each followed by positive integers. Each letter indicates a certain type, the integer following it specifies the size of objects of that type. One letter indicates the wordsize used. .IS .sp 1 .TS center tab(:); l l16 l l. letter:type:letter:type w:wordsize:i:int s:short:l:long f:float:d:double p:pointer:: .TE .sp 1 All existing implementations use an integer size equal to the wordsize. .IE The calling program \fIack\fP[4] provides the frontend with this flag, with values depending on the machine used. .sp 1 .PT -l The frontend normally generates code to keep track of the line number and source file name at runtime for debugging purposes. Currently a pointer to a string containing the filename is stored at a fixed place in memory at each function entry and the line number at the start of every expression. At the return from a function these memory locations are not reset to the values they had before the call. Most library routines do not use this feature and thus do not ruin the current line number and filename when called. However, you are really unlucky when your program crashes due to a bug in such a library function, because the line number and filename do not indicate that something went wrong inside the library function. .br Providing the flag -l to the frontend tells it not to generate the code updating line number and file name. This is, for example, used when translating the stdio library. .br When the \fIack\fP[4] is called with the -L flag it provides the frontend with this flag. .sp 1 .PT -Xp When this flag is present the frontend generates a call to the function \fBprocentry\fP at each function entry and a call to \fBprocexit\fP at each function exit. Both functions are provided with one parameter, a pointer to a string containing the function name. .br When \fIack\fP is called with the -p flag it provides the frontend with this flag. .IE .CH References .IS .PT [1] A.S. Tanenbaum, Hans van Staveren, Ed Keizer and Johan Stevenson \fIDescription of a machine architecture for use with block structured languages\fP Informatica report IR-81. .sp 1 .PT [2] B.W. Kernighan and D.M. Ritchie, \fIThe C Programming language\fP, Prentice-Hall, 1978 .PT [3] D.M. Ritchie, \fIC Reference Manual\fP .sp .PT [4] UNIX manual ack(I).