cc65-7.html
来自「cc65 的编译器文档」· HTML 代码 · 共 228 行
HTML
228 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><HTML><HEAD> <META NAME="GENERATOR" CONTENT="LinuxDoc-Tools 0.9.20"> <TITLE>cc65 Users Guide: #pragmas</TITLE> <LINK HREF="cc65-8.html" REL=next> <LINK HREF="cc65-6.html" REL=previous> <LINK HREF="cc65.html#toc7" REL=contents></HEAD><BODY><A HREF="cc65-8.html">Next</A><A HREF="cc65-6.html">Previous</A><A HREF="cc65.html#toc7">Contents</A><HR><H2><A NAME="pragmas"></A> <A NAME="s7">7.</A> <A HREF="cc65.html#toc7">#pragmas</A></H2><P>The compiler understands some pragmas that may be used to change codegeneration and other stuff.</P><H2><A NAME="ss7.1">7.1</A> <A HREF="cc65.html#toc7.1"><CODE>#pragma bssseg (<name>)</CODE></A></H2><P>This pragma changes the name used for the BSS segment (the BSS segmentis used to store uninitialized data). The argument is a string enclosedin double quotes.</P><P>Note: The default linker configuration file does only map the standardsegments. If you use other segments, you have to create a new linkerconfiguration file.</P><P>Beware: The startup code will zero only the default BSS segment. If youuse another BSS segment, you have to do that yourself, otherwiseuninitialized variables do not have the value zero.</P><P>Example:<BLOCKQUOTE><CODE><PRE> #pragma bssseg ("MyBSS") </PRE></CODE></BLOCKQUOTE></P><H2><A NAME="ss7.2">7.2</A> <A HREF="cc65.html#toc7.2"><CODE>#pragma charmap (<index>, <code>)</CODE></A></H2><P>Each literal string and each literal character in the source is translatedby use of a translation table. This translation table is preset when thecompiler is started depending on the target system, for example to mapISO-8859-1 characters into PETSCII if the target is a commodore machine.</P><P>This pragma allows to change entries in the translation table, so thetranslation for individual characters, or even the complete table may beadjusted.</P><P>Both arguments are assumed to be unsigned characters with a valid range of1-255.</P><P>Beware of two pitfalls:</P><P><UL><LI>The character index is actually the code of the character in theC source, so character mappings do always depend on the sourcecharacter set. This means that <CODE>#pragma charmap</CODE> is not portable- it depends on the build environment.</LI><LI>While it is possible to use character literals as indices, theresult may be somewhat unexpected, since character literals areitself translated. For this reason I would suggest to avoidcharacter literals and use numeric character codes instead.</LI></UL></P><P>Example:<BLOCKQUOTE><CODE><PRE> /* Use a space wherever an 'a' occurs in ISO-8859-1 source */ #pragma charmap (0x61, 0x20); </PRE></CODE></BLOCKQUOTE></P><H2><A NAME="pragma-checkstack"></A> <A NAME="ss7.3">7.3</A> <A HREF="cc65.html#toc7.3"><CODE>#pragma checkstack (on|off)</CODE></A></H2><P>Tells the compiler to insert calls to a stack checking subroutine to detectstack overflows. The stack checking code will lead to somewhat larger andslower programs, so you may want to use this pragma when debugging yourprogram and switch it off for the release version. If a stack overflow isdetected, the program is aborted.</P><P>If the argument is "off", stack checks are disabled (the default), otherwisethey're enabled.</P><H2><A NAME="ss7.4">7.4</A> <A HREF="cc65.html#toc7.4"><CODE>#pragma codeseg (<name>)</CODE></A></H2><P>This pragma changes the name used for the CODE segment (the CODE segmentis used to store executable code). The argument is a string enclosed indouble quotes.</P><P>Note: The default linker configuration file does only map the standardsegments. If you use other segments, you have to create a new linkerconfiguration file.</P><P>Example:<BLOCKQUOTE><CODE><PRE> #pragma codeseg ("MyCODE") </PRE></CODE></BLOCKQUOTE></P><H2><A NAME="ss7.5">7.5</A> <A HREF="cc65.html#toc7.5"><CODE>#pragma dataseg (<name>)</CODE></A></H2><P>This pragma changes the name used for the DATA segment (the DATA segmentis used to store initialized data). The argument is a string enclosed indouble quotes.</P><P>Note: The default linker configuration file does only map the standardsegments. If you use other segments, you have to create a new linkerconfiguration file.</P><P>Example:<BLOCKQUOTE><CODE><PRE> #pragma dataseg ("MyDATA") </PRE></CODE></BLOCKQUOTE></P><H2><A NAME="ss7.6">7.6</A> <A HREF="cc65.html#toc7.6"><CODE>#pragma rodataseg (<name>)</CODE></A></H2><P>This pragma changes the name used for the RODATA segment (the RODATAsegment is used to store readonly data). The argument is a stringenclosed in double quotes.</P><P>Note: The default linker configuration file does only map the standardsegments. If you use other segments, you have to create a new linkerconfiguration file.</P><P>Example:<BLOCKQUOTE><CODE><PRE> #pragma rodataseg ("MyRODATA") </PRE></CODE></BLOCKQUOTE></P><H2><A NAME="ss7.7">7.7</A> <A HREF="cc65.html#toc7.7"><CODE>#pragma regvaraddr (on|off)</CODE></A></H2><P>The compiler does not allow to take the address of register variables.The regvaraddr pragma changes this. Taking the address of a registervariable is allowed after using this pragma with "on" as argument.Using "off" as an argument switches back to the default behaviour.</P><P>Beware: The C standard does not allow taking the address of a variabledeclared as register. So your programs become non-portable if you usethis pragma. In addition, your program may not work. This is usually thecase if a subroutine is called with the address of a register variable,and this subroutine (or a subroutine called from there) uses itselfregister variables. So be careful with this #pragma.</P><P>Example:<BLOCKQUOTE><CODE><PRE> #pragma regvaraddr(1) /* Allow taking the address * of register variables */ </PRE></CODE></BLOCKQUOTE></P><H2><A NAME="pragma-signedchars"></A> <A NAME="ss7.8">7.8</A> <A HREF="cc65.html#toc7.8"><CODE>#pragma signedchars (on|off)</CODE></A></H2><P>Changes the signedness of the default character type. If the argument is"on", default characters are signed, otherwise characters are unsigned.The compiler default is to make characters unsigned since this creates alot better code. This default may be overridden by the <CODE>--signed-chars</CODE>command line option.</P><H2><A NAME="pragma-staticlocals"></A> <A NAME="ss7.9">7.9</A> <A HREF="cc65.html#toc7.9"><CODE>#pragma staticlocals (on|off)</CODE></A></H2><P>Use variables in the bss segment instead of variables on the stack. Thispragma changes the default set by the compiler option <CODE>-Cl</CODE>. If theargument is "on", local variables are allocated in the BSS segment,leading to shorter and in most cases faster, but non-reentrant code.</P><H2><A NAME="ss7.10">7.10</A> <A HREF="cc65.html#toc7.10"><CODE>#pragma zpsym (<name>)</CODE></A></H2><P>Tell the compiler that the - previously as external declared - symbol withthe given name is a zero page symbol (usually from an assembler file).The compiler will create a matching import declaration for the assembler.</P><P>Example:<BLOCKQUOTE><CODE><PRE> extern int foo; #pragma zpsym ("foo"); /* foo is in the zeropage */ </PRE></CODE></BLOCKQUOTE></P><HR><A HREF="cc65-8.html">Next</A><A HREF="cc65-6.html">Previous</A><A HREF="cc65.html#toc7">Contents</A></BODY></HTML>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?