📄 p2c.man
字号:
.TP.B StrlapFunctionFunctions on this list are structured functions as above, but with theability to work in-place; that is, the same pointer may be passed as both thereturn value area and a regular parameter..TP.B DeterministicFunctions on this list have no side effects or side dependencies.An example is the.I sinfunction in the standard math library; two calls with the same parametervalues produce the same result, and have no effects other than returninga value..I P2ccan make use of this knowledge when optimizing code for efficiency orreadability. Functions on this list are also assumed to be relativelyfast, so that it is acceptable to duplicate a call to the function..TP.B LeaveAloneFunctions on this list are not subjected to the normal built-in translationrules that.I p2cwould otherwise use. For example, adding.I writelnto this list would translate.I writelnstatements blindly into calls to a C.I writeln()function, rather than being translated into equivalent.I printfcalls. The built-in translation is also suppressed if the function has a.BR FuncMacro ..TP.B BufferedFile.I P2cnormally assumes binary files will use.I read/write,not.I get/put/^notation.A file buffer variable will only be created for a file if buffer notationis used for it. For global file variables this may be detected too late(a declaration without buffers may already have been written). Such filescan be listed in.B BufferedFileto force.I p2cto allocate buffers for them; do this if you get a warningmessage that says it is necessary. Set.BR BufferedFile =1to buffer all files, in which case.B UnBufferedFileallows you to force certain files.I notto have buffers..TP.B StructFilesIf.I p2cstill can't translate your file operations correctly, you can set.BR StructFiles =1to cause Pascal files to translate into structs which include the usual C.I FILEpointer, as well as file buffer and file name fields. While the resultingcode doesn't look as much like native C, the file structs will allow.I p2cto do a correct translation in many more cases..TP.B CheckFileEOFNormally only file-open operations are checked for errors. Additionalerror checking, such as read-past-end-of-file, can be enabled withparameters like.BR CheckFileEOF .These checks can make the code very ugly! If I/O checking is enabledby the program.RB ( "$iocheck on$"in HP Pascal;.B {$I+}in Turbo; this is always the default state),these checks will generate fatal errors unless enclosed in an HP Pascal.BR try - recoverconstruct. If I/O checking is disabled, these will cause the globalvariable.I P_ioresultto be set zero or nonzero according to the outcome. The default for mostof these options is to check only when I/O checking is enabled..SH ISSUES.B Integer size..I P2cnormally generates code to work with either 16 or 32 bit ints.If you know your C integers will be 16 or 32 bits, set.B IntSizeappropriately. In particular setting.BR IntSize =32will generate much cleaner code:.I p2cno longer must carefully cast function arguments between int and long.These casts also will be unnecessary if ANSI prototypes are available.To disable int/long casting because you know at least one of thesecases will hold, set.BR CastLongArgs =0.(The.B CastArgsparameter similarly controls other types of casts, such as between intsand doubles.)The.B Integer16parameter controls whether Pascal integers are interpreted as 16 or 32bits, or translated as native C integers. The default value depends on the.B Languageselected..PP.B Signed/unsigned chars.Pascal characters are normally "weakly" interpreted as unsigned; thisis controlled by.BR UnsignedChar .The default is "either," so that C's native.B chartype may be used even if its signed-ness is unknown. Code that usescharacters outside of the range 0-127 may need a different setting.Alternatively, you can use the types.B {SIGNED} charand.B {UNSIGNED} charin the few cases where it really matters. These comments are controlledby the.B SignedCommentand.B UnsignedCommentparameters. (The type.B {UNSIGNED} integeris also recognized.) The.B SignedCharparameter tells whether C characters are signed or unsigned (default is"unknown"). The.B HasSignedCharparameter tells whether the phrase "signed char" is legal in the output.If it is not,.I p2cmay have to translate Pascal signed bytes into C shorts..PP.B Special types..I P2cunderstands the following predefined Pascal type names:.BR integer ,signed integers depending on.BR Integer16 ;.BR longint ,signed 32-bit integers;.BR unsigned ,unsigned 32-bit integers;.BR sword ,signed 16-bit integers;.BR word ,unsigned 16-bit integers;.BR c_int ,signed native C integers;.BR c_uint ,unsigned native C integers;.BR sbyte ,signed 8-bit integers;.BR byte ,unsigned 8-bit integers;.BR real ,floating-point numbers depending on.BR DoubleReals ;.BR single ,single-precision floats;.BR longreal ,.BR double ,and.BR extended ,double-precision floats;.B pointerand.BR anyptr ,generic pointers (assignment-compatible with any pointer type);.BR string ,generic string of length.B StringDefault(normally 255);also, the usual Pascal types.BR char ,.BR boolean ,and.BR text .(If your Pascal uses different names for these concepts, the.B Synonymoption will come in handy.).PP.B Embedded code.It is possible to write a Pascal comment containing C code tobe embedded into the output. See the descriptions of.B EmbedCommentand its relatives in the system.I p2crcfile. These techniques are helpful if you plan to do repeated translationsof code that is still being maintained in Pascal. See the description of.B ReplaceBeforefor an example use of embedded code..PP.B Comments and blank lines..I P2ccollects the comments in a procedure into a list. All comments and statementsare stamped with serial numbers which are used to reattach comments tostatements even after code has been added, removed, or rearranged duringtranslation. "Orphan" comments attached to statements that have been lostare attached to nearby statements or emitted at the end of the procedure.Blank lines are treated as a kind of comment, so.I p2cwill also reproduce your usage of blank lines. If the comment mechanismgoes awry, you can disable comments with.B EatCommentsor disable their being attached to code with.BR SpitComments ..PP.B Indentation..I P2chas a number of parameters to govern indentation of code. The defaultvalues produce the GNU Emacs standard indentation style, although.I p2ccan do a better job since it knows more about the code it is indenting.Indentation works by applying "indentation deltas," which are eitherabsolute numbers (which override the previous indentation), or signedrelative numbers (which augment the previous indentation). A delta of"+0" specifies no change in indentation. All of the indentationoptions are described in the standard.I p2crcfile..PP.B Line breaking..I P2cuses an algorithm similar to the TeX typesetter's paragraph formatterfor breaking long statements into multiple lines. A "penalty" is assignedto various undesirable aspects of all possible line breaks; the "badness"of a set of line breaks is approximately the sum of all the penalties.Chief among these are serious penalties for overrunning the desired maximumline length (default 78 columns),an infinite penalty for overrunning the absolutemaximum line length (default 90), and progressively greater penalties forbreaking at operators deeply nested in expressions. Parameters such as.B OpBreakPenaltycontrol the relative weights of various choices..B BreakArithand its neighbors control whether the operator at a line break should beplaced at the end of the previous line or at the beginning of the next.If you don't want any oversize lines, define.BR MaxLineWidth =78..PPUnlike TeX,.IR p2c 'sline breaker must actually try all possible sets of break points. Toavoid excessive computation, the total penalty contributed at each decisionpoint must sum to a nonnegative value; negative values are clipped up to zero.This allows.I p2cto prune away obviously undesirable alternatives in advance. The.B MaxLineBreakTriesparameter (default 5000) controls how many alternatives to try beforegiving up and using the best so far..PP.B PASCAL_MAIN..I P2cgenerates a call to this function at the front of the main program.In the (unmodified) run-time library all this does is save argc and argvaway because in both HP and Turbo these are accessed as global variables.If you do not wish to use this feature, define.B ArgCNameto be.I argc,.B ArgVNameto be.I argv,and.B MainName(normally "PASCAL_MAIN") to be blank. This will work if argc and argvare never accessed outside of your main program..SH BUGS.I P2cwas designed with the idea that clean, readable output in most cases isworth more than guaranteed correct output in extreme cases..I P2cis.I nota compiler! However, ideally the "extreme" cases would include only thosewhich never arise in real life. Thus if.I p2cactually generates incorrect code I will consider it a bug, but I will notapologize for it. :-) Below are the major remaining cases where this isknown to occur..PPCertain kinds of conformant array parameters (including multi-dimensionalconformant arrays) produce code that declares variable-length arrays in C.Only a few C compilers, such as the GNU C compiler, support this languageextension. Otherwise some hand re-coding will be required..PPHP Pascal.BR try - recoverstructures are translated into calls to.I TRYand.I RECOVERmacros, which are defined to simulate the construct using.I setjmpand.I longjmp.If this emulation does not work, define the symbol.B FAKE_TRYto cause these macros to become "inert." (In cases where theerror is detected by code physically within the body of the.B trystatement, a C.B gototo the.B recoversection is always generated.) Also, local file variables in scopes whichare destroyed by an.B escapeare not closed..PPNon-local GOTO's and.BR try - recoverstatements are each implemented, but mayconflict if both are used at once. Non-local GOTO's are fairly carefulabout closing files that go out of scope but may fail to do so in the presenceof recursion..PPArrays containing files are not initialized to NULL as other files are.In some cases, such as file variables allocated by NEW, the file isinitialized but not automatically closed by DISPOSE..PPLINK variables allowing sub-procedures access to their parents' variablesare occasionally omitted by mistake, if the access is too indirect for.I p2cto notice. If this happens, you can add an explicit reference to a parentvariable in the sub-procedure. A statement of the form "a:=a" will countas a reference but then be optimized away by.I p2c..PPMany aspects of Modula-2 are translated only superficially. For example,the type-compatibility properties of the.I WORDand.I ARRAY OF WORDtypes are only roughly modelled, as are the scope rules concerning modules..PPParts of VAX Pascal are still untreated. In particular, the.I [UNSAFE]attribute and a few others are not fully supported,nor are the semantics of the.I OPENprocedure..PPTurbo and VAX Pascal's.I double, quadruple,and.I extendedreal types all translate to the C.B doubletype. Turbo's.I computationaltype is not supported at all..PPBecause Pascal strings (with length bytes) are translated into C strings(with null terminators), certain Pascal string tricks will not work inthe translated code. For example the assignment.I s[0]:=chr(x)is translated to.I s[x]=0on the assumption that the string is being shortened. If.I xis actually greater than the current length, but not of a recognizableform like.I ord(s[0])+n,then the generated code will not work. In VAX Pascal this correspondsto performing arithmetic on the.I LENGTHfield of a varying-length string..PPTurbo Pascal's automatic clipping of strings is not supported. InTurbo, if a ten character string is assigned to a.I string[8]variable, the last two characters are silently removed. The codeproduced by.I p2cgenerally will overrun the target string instead! The.B StringTruncLimitparameter (80 by default if.BR Language = Turbo )specifies a string size which should be considered "short"; assignmentsof potentially-long strings to short string variables will cause a warningbut will not automatically truncate. The cure is to use.I copyin the Pascal source to truncate the strings explicitly..SH FILES.ta \w'--INCDIR--/p2c.h 'ufile.\fIxxx\fR Pascal source files.brfile.c resulting C source file.brmodule.h resulting C header file.brp2crc local configuration file.br\&.p2crc alternate local configuration file.br--HOMEDIR--/p2crc system-wide configuration file.br--HOMEDIR--/system.imp declarations for predefined functions.br--HOMEDIR--/system.m2 analogous declarations for Modula-2.br--HOMEDIR--/*.imp interface text for standard modules.br--INCDIR--/p2c.h header file for translated programs.br--LIBDIR--/libp2c.a run-time library.SH AUTHORDave Gillespie, daveg@synaptics.com..PPMany thanks to William Bader, Steven Levi, Rick Koshi, Eric Raymond,Magne Haveraaen, Dirk Grunwald, David Barto, Paul Fisher, Tom Schneider,Dick Heijne, Guenther Sawitzki,and many others whose suggestions and bug reports have helped improve.I p2cin countless ways.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -