⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ifsizeof.ct.html

📁 this is a mirrored site c-faq. thought might need offline
💻 HTML
字号:
<html><!-- Mirrored from c-faq.com/cpp/ifsizeof.ct.html by HTTrack Website Copier/3.x [XR&CO'2008], Sat, 14 Mar 2009 08:00:35 GMT --><head><title></title></head><body>From: Chris Torek<br>Subject: Re: sizeof in define<br>Date: 1999/11/26<br>Newsgroups: comp.lang.c<br>Message-ID: &lt;81n9la$hhl$1@elf.bsdi.com&gt;<p>The C89 standard divides translation into eight ``phases''.C99 keeps the same phases and just adds Unicode and the like.  Iwill quote an old C99 draft below (with some small edits for textrepresentation).  Read footnote 5 carefully, and then consider thefact that ``<TT>#if</TT>'' happens in phase 4, but pp-tokens are not convertedto regular tokens until phase 7.  Since the ``sizeof'' keyword is aregular token rather than a pp-token, that makes it impossible for``<TT>#if</TT>'' to recognize it.  In fact, the line:<p><pre>	# if ((sizeof aszColors / sizeof *aszColors) != COLOR_NB)</pre><p>must (in the absence of various <TT>#define</TT>s) behave as if it read:<p><pre>	# if ((0 0 / 0 *0) != 0)</pre><p>so a diagnostic is required (because ``0 0'' is a syntax error).<p>(Once the required diagnostic has been emitted, of course, a compileris free to do anything it likes, including go back and discoverthat the ``0''s came from ``sizeof'', work out the sizes, examine theenumeration constant, and so on.  For a compiler to do this, however,its phase-4 code must be able to peek at phase-7 data, such asenumeration constant values and array sizes.  That in turns requiresan integrated compiler -- preprocessing cannot occur in a separateprogram the way it does in, e.g., gcc.  That in turn makes usingmultiple CPUs, e.g., via ``<TT>cpp | cc1</TT>'', much harder -- so it may bea good idea to retain this sequencing, and footnote 5.)<p>[excerpt from c9x.n2620.txt below]<p><blockquote>Working Draft, 1997-11-21, WG14/N794 J11/97-158<br>5.1.1.2  Translation phases<p>[#1] The precedence among the syntax rules of translation isspecified by the following phases.[footnote 5]<dl><dt>1.</dt><dd>Physical source file multibyte characters are mappedto the source character set (introducing new-linecharacters for end-of-line indicators) if necessary.Any multibyte source file character not in the basicsource character set is replaced by the universal-character-namethat designates that multibytecharacter.[6]  Then, trigraph sequences are replaced bycorresponding single-character internalrepresentations.</dd><dt>2.</dt><dd>Each instance of a backslash character immediatelyfollowed by a newline character is deleted, splicingphysical source lines to form logical source lines.Only the last backslash on any physical source lineshall be eligible for being part of such a splice.A source file that is not empty shall end in a new-linecharacter, which shall not be immediately preceded bya backslash character before any such splicing takesplace.</dd><dt>3.</dt><dd>The source file is decomposed into preprocessingtokens[7] and sequences of white-space characters(including comments).  A source file shall not end ina partial preprocessing token or comment.  Eachcomment is replaced by one space character.  New-linecharacters are retained.  Whether each nonemptysequence of white-space characters other than new-lineis retained or replaced by one space character isimplementation-defined.</dd><dt>4.</dt><dd>Preprocessing directives are executed, macroinvocations are expanded, and pragma unary operatorexpressions are executed.  If a character sequencethat matches the syntax of a universal-character-nameis produced by token concatenation (6.8.3.3), thebehavior is undefined.  A <TT>#include</TT> preprocessingdirective causes the named header or source file to beprocessed from phase 1 through phase 4, recursively.All preprocessing directives are then deleted.</dd><dt>5.</dt><dd>Each source character set member, escape sequence, anduniversal-character-name in character constants andstring literals is converted to a member of theexecution character set.</dd><dt>6.</dt><dd>Adjacent character string literal tokens areconcatenated and adjacent wide string literal tokensare concatenated.</dd><dt>7.</dt><dd>White-space characters separating tokens are no longersignificant.  Each preprocessing token is convertedinto a token.  The resulting tokens are syntacticallyand semantically analyzed and translated as atranslation unit.</dd><dt>9.</dt><dd>All external object and function references areresolved.  Library components are linked to satisfyexternal references to functions and objects notdefined in the current translation.  All suchtranslator output is collected into a program imagewhich contains information needed for execution in itsexecution environment.</dd></dl><p>__________[footnotes 5 through 7]<p><dl><dt>5.</dt><dd>Implementations must behave as if these separate phasesoccur, even though many are typically folded together inpractice.</dd><dt>6.</dt><dd>The process of handling extended characters is specifiedin terms of mapping to an encoding that uses only thebasic source character set, and, in the case ofcharacter literals and strings, further mapping to theexecution character set.  In practical terms, however,any internal encoding may be used, so long as an actualextended character encountered in the input, and thesame extended character expressed in the input as auniversal-character-name (i.e., using the <TT>\U</TT> or <TT>\u</TT>notation), are handled equivalently.</dd><dt>7.</dt><dd>As described in 6.1, the process of dividing a sourcefile's characters into preprocessing tokens is context-dependent.For example, see the handling of <TT>&lt;</TT> within a<TT>#include</TT> preprocessing directive.</dd></dl></blockquote><p>--<br>In-Real-Life: Chris Torek, Berkeley Software Design Inc<br>El Cerrito, CA  Domain: torek@bsdi.com&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+1&nbsp;510&nbsp;234&nbsp;3167<br><a href="http://claw.bsdi.com/torek/">http://claw.bsdi.com/torek/</a>&nbsp;&nbsp;(not always up)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;I report spam to abuse@.</body><!-- Mirrored from c-faq.com/cpp/ifsizeof.ct.html by HTTrack Website Copier/3.x [XR&CO'2008], Sat, 14 Mar 2009 08:00:35 GMT --></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -