⑴ 大一C++問題 double類型的變數是否可以賦給整形變數字元型呢數據類型轉換的基本原則是什麼
樓主你好
數據類型的轉換規則為:
(1)從類型高(強調精度高)的轉換到類型低(強調精度低)的 這樣一般都會得到編譯器的警告
因為精度高的變為精度低的數據 會失去數據原本的精度 這樣容易丟失數據
例如double a=5.5
int b=a
這里b=5 失去了小數一位.5的精度
數據不精確 但是可以轉換
(2)從類型低的轉換到類型高的 會正常轉換 沒有警告
至於字元類型 是完全可以賦值給整型變數的
如果樓主知道 ASCII碼
那麼字元賦值給整型變數 就是講字元對應的ASCII碼(整型的)賦值給整型變數
(介於樓主是大一 可能才接觸c++ 就只講這么多了哈^_^)
希望能幫助你哈
⑵ 編譯原理
編譯原理是計算機專業的一門重要專業課,旨在介紹編譯程序構造的一般原理和基本方法。內容包括語言和文法、詞法分析、語法分析、語法制導翻譯、中間代碼生成、存儲管理、代碼優化和目標代碼生成。 編譯原理是計算機專業設置的一門重要的專業課程。編譯原理課程是計算機相關專業學生的必修課程和高等學校培養計算機專業人才的基礎及核心課程,同時也是計算機專業課程中最難及最挑戰學習能力的課程之一。編譯原理課程內容主要是原理性質,高度抽象[1]。
中文名
編譯原理[1]
外文名
Compilers: Principles, Techniques, and Tools[1]
領域
計算機專業的一門重要專業課[1]
快速
導航
編譯器
編譯原理課程
編譯技術的發展
編譯的基本流程
編譯過程概述
基本概念
編譯原理即是對高級程序語言進行翻譯的一門科學技術, 我們都知道計算機程序由程序語言編寫而成, 在早期計算機程序語言發展較為緩慢, 因為計算機存儲的數據和執行的程序都是由0、1代碼組合而成的, 那麼在早期程序員編寫計算機程序時必須十分了解計算機的底層指令代碼通過將這些微程序指令組合排列從而完成一個特定功能的程序, 這就對程序員的要求非常高了。人們一直在研究如何如何高效的開發計算機程序, 使編程的門檻降低。[2]
編譯器
C語言編譯器是一種現代化的設備, 其需要藉助計算機編譯程序, C語言編譯器的設計是一項專業性比較強的工作, 設計人員需要考慮計算機程序繁瑣的設計流程, 還要考慮計算機用戶的需求。計算機的種類在不斷增加, 所以, 在對C語言編譯器進行設計時, 一定要增加其適用性。C語言具有較強的處理能力, 其屬於結構化語言, 而且在計算機系統維護中應用比較多, C語言具有高效率的優點, 在其不同類型的計算機中應用比較多。[3]
C語言編譯器前端設計
編譯過程一般是在計算機系統中實現的, 是將源代碼轉化為計算機通用語言的過程。編譯器中包含入口點的地址、名稱以及機器代碼。編譯器是計算機程序中應用比較多的工具, 在對編譯器進行前端設計時, 一定要充分考慮影響因素, 還要對詞法、語法、語義進行分析。[3]
1 詞法分析[3]
詞法分析是編譯器前端設計的基礎階段, 在這一階段, 編譯器會根據設定的語法規則, 對源程序進行標記, 在標記的過程中, 每一處記號都代表著一類單詞, 在做記號的過程中, 主要有標識符、關鍵字、特殊符號等類型, 編譯器中包含詞法分析器、輸入源程序、輸出識別記號符, 利用這些功能可以將字型大小轉化為熟悉的單詞。[3]
2 語法分析[3]
語法分析是指利用設定的語法規則, 對記號中的結構進行標識, 這包括句子、短語等方式, 在標識的過程中, 可以形成特殊的結構語法樹。語法分析對編譯器功能的發揮有著重要影響, 在設計的過程中, 一定要保證標識的准確性。[3]
3 語義分析[3]
語義分析也需要藉助語法規則, 在對語法單元的靜態語義進行檢查時, 要保證語法規則設定的准確性。在對詞法或者語法進行轉化時, 一定要保證語法結構設置的合法性。在對語法、詞法進行檢查時, 語法結構設定不合理, 則會出現編譯錯誤的問題。前端設計對精確性要求比較好, 設計人員能夠要做好校對工作, 這會影響到編譯的准確性, 如果前端設計存在失誤, 則會影響C語言編譯的效果。[3]
⑶ C++類型轉換規則、何時發生隱式類型轉換及強制類型轉換適用場合
C++做為強類型語言,要求編譯期的類型聲明與檢查,要求表達式中各操作數的類型(包括賦值操作的左值和右值,以及形參和實參)具有一致性,但同時也允許一定的靈活性,允許類型在一定程度上的兼容,也就是允許類型遵循一定規則下的隱式轉換和強制轉換。
The type of the operand(s) determine whether an expression is legal and, if the expression is legal, determines the meaning of the expression. However, in C++ some types are related to one another. When two types are related, we can use an object or value of one type where an operand of the related type is expected. Two types are related if there is a conversion between them.
表達式是否合法取決於操作數的類型,而且合法的表達式其含義也由其操作數類型決定。但是,在 C++ 中,某些類型之間存在相關的依賴關系。若兩種類型相關,則可在需要某種類型的操作數位置上,使用該類型的相關類型對象或值。如果兩個類型之間可以相互 轉換 ,則稱這兩個類型相關。
1.1 The Arithmetic Conversions 算術轉換
The language defines a set of conversions among the built-in types. Among these, the most common are the arithmetic conversions , which ensure that the two operands of a binary operator, such as an arithmetic or logical operator, are converted to a common type before the operator is evaluated. That common type is also the result type of the expression.
C++ 語言為內置類型提供了一組轉換規則,其中最常用的是 算術轉換 。算術轉換保證在執行操作之前,將二元操作符(如算術或邏輯操作符)的兩個操作數轉換為同一類型,並使表達式的值也具有相同的類型。
The rules define a hierarchy of type conversions in which operands are converted to the widest type in the expression. The conversion rules are defined so as to preserve the precision of the values involved in a multi-type expression. For example, if one operand is of type long double, then the other is converted to type long double regardless of what the second type is.
算術轉換規則定義了一個類型轉換層次,該層次規定了操作數應按什麼次序轉換為表達式中最寬的類型。在包含多種類型的表達式中,轉換規則要確保計算值的精度。例如,如果一個操作數的類型是 long double,則無論另一個操作數是什麼類型,都將被轉換為 long double。
The simplest kinds of conversion are integral promotions . Each of the integral types that are smaller than int char, signed char, unsigned char, short, and unsigned shortis promoted to int if all possible values of that type fit in an int. Otherwise, the value is promoted to unsigned int. When bool values are promoted to int, a false value promotes to zero and true to one.
最簡單的轉換為 整型提升 :對於所有比 int 小的整型,包括 char、signed char、unsigned char、short 和 unsigned short,如果該類型的所有可能的值都能包容在 int 內,它們就會被提升為 int 型,否則,它們將被提升為 unsigned int。如果將 bool 值提升為 int ,則 false 轉換為 0,而 true 則轉換為 1。
需要注意的,上述所謂的轉換只是運算時的類型轉換,存儲時還會轉換為其聲明時的類型。
1.2 Conversions between Signed and Unsigned Types 有符號與無符號類型之間的轉換
When an unsigned value is involved in an expression, the conversion rules are defined to preserve the value of the operands. Conversions involving unsigned operands depend on the relative sizes of the integral types on the machine. Hence, such conversions are inherently machine dependent.
若表達式中使用了無符號( unsigned )數值,所定義的轉換規則需保護操作數的精度。unsigned 操作數的轉換依賴於機器中整型的相對大小,因此,這類轉換本質上依賴於機器。
In expressions involving shorts and ints, values of type short are converted to int. Expressions involving unsigned short are converted to int if the int type is large enough to represent all the values of an unsigned short. Otherwise, both operands are converted to unsigned int. For example, if shorts are a half word and ints a word, then any unsigned value will fit inside an int. On such a machine, unsigned shorts are converted to int.
包含 short 和 int 類型的表達式, short 類型的值轉換為 int 。如果 int 型足夠表示所有 unsigned short 型的值,則將 unsigned short 轉換為 int,否則,將兩個操作數均轉換為 unsigned int 。例如,如果 short 用半字表示而 int 用一個字表示,則所有 unsigned 值都能包容在 int 內,在這種機器上, unsigned short 轉換為 int。
The same conversion happens among operands of type long and unsigned int. The unsigned int operand is converted to long if type long on the machine is large enough to represent all the values of the unsigned int. Otherwise, both operands are converted to unsigned long.
long 和 unsigned int 的轉換也是一樣的。只要機器上的 long 型足夠表示 unsigned int 型的所有值,就將 unsigned int 轉換為 long 型,否則,將兩個操作數均轉換為 unsigned long 。
On a 32-bit machine, long and int are typically represented in a word. On such machines, expressions involving unsigned ints and longs are converted to unsigned long.
在 32 位的機器上,long 和 int 型通常用一個字長表示,因此當表達式包含 unsigned int 和 long 兩種類型,其操作數都應轉換為 unsigned long 型。
Conversions for expressions involving signed and unsigned int can be surprising. In these expressions the signed value is converted to unsigned. For example, if we compare a plain int and an unsigned int, the int is first converted to unsigned. If the int happens to hold a negative value, the result will be converted as described as belows, with all the attendant problems discussed there.
對於包含 signed 和 unsigned int 型的表達式,其轉換可能出乎我們的意料。表達式中的 signed 型數值會被轉換為 unsigned 型。例如,比較 int 型和 unsigned int 型的簡單變數,系統首先將 int 型數值轉換為 unsigned int 型,如果 int 型的值恰好為負數,其結果將以下述方法轉換,並帶來其所有副作用。
The compiler applies conversions for both built-in and class type objects as necessary. Implicit type conversions take place in the following situations:
編譯器在必要時將類型轉換規則應用到內置類型和類類型的對象上。在下列情況下,將發生隱式類型轉換:
In expressions with operands of mixed types, the types are converted to a common type:
在混合類型的表達式中,其操作數被轉換為相同的類型:
An expression used as a condition is converted to bool:
用作條件的表達式被轉換為 bool 類型:
Conditions occur as the first operand of the conditional (?:) operator and as the operand(s) to the logical NOT (!), logical AND (&&), and logical OR (||) operators. Conditions also appear in the if, while, for, and do while statements.
條件操作符(?:)中的第一個操作數以及邏輯非(!)、邏輯與(&&)和邏輯或(||)的操作數都是條件表達式。出現在 if、while、for 和 do while 語句中的同樣也是條件表達式。
An expression used to initialize or assign to a variable is converted to the type of the variable:
用一表達式初始化某個變數,或將一表達式賦值給某個變數,則該表達式被轉換為該變數的類型:
In addition,implicit conversions also occur ring function calls.
另外,在函數調用中也可能發生隱式類型轉換。
3.1 static_cast
Any type conversion that the compiler performs implicitly can be explicitly requested by using a static_cast:
編譯器隱式執行的任何類型轉換都可以由 static_cast 顯式完成:
Such casts are useful when assigning a larger arithmetic type to a smaller type. The cast informs both the reader of the program and the compiler that we are aware of and are not concerned about the potential loss of precision. Compilers often generate a warning for assignments of a larger arithmetic type to a smaller type. When we provide the explicit cast, the warning message is turned off.
當需要將一個較大的算術類型賦值給較小的類型時,使用強制轉換非常有用。此時,強制類型轉換告訴程序的讀者和編譯器:我們知道並且不關心潛在的精度損失。對於從一個較大的算術類型到一個較小類型的賦值,編譯器通常會產生警告。當我們顯式地提供強制類型轉換時,警告信息就會被關閉。
A static_cast is also useful to perform a conversion that the compiler will not generate automatically. For example, we can use a static_cast to retrieve a pointer value that was stored in a void* pointer:
如果編譯器不提供自動轉換,使用 static_cast 來執行類型轉換也是很有用的。例如,下面的程序使用 static_cast 找回存放在 void* 指針中的值:
When we store a pointer in a void* and then use a static_cast to cast the pointer back to its original type, we are guaranteed that the pointer value is preserved. That is, the result of the cast will be equal to the original address value.
可通過 static_cast 將存放在 void* 中的指針值強制轉換為原來的指針類型,此時我們應確保保持指針值。也就是說,強制轉換的結果應與原來的地址值相等。
3.2 const_cast
A const_cast, as its name implies, casts away the constness of its expression. For example, we might have a function named string_ that we are certain reads, but does not write, its single parameter of type char*. If we have access to the code, the best alternative would be to correct it to take a const char*. If that is not possible, we could call string_ on a const value using a const_cast:
const_cast ,顧名思義,將 轉換掉 表達式的 const 性質。例如,假設有函數 string_,只有唯一的參數,為 char* 類型,我們對該函數只讀不寫。在訪問該函數時,最好的選擇是修改它讓它接受 const char* 類型的參數。如果不行,可通過 const_cast 用一個 const 值調用 string_ 函數:
Only a const_cast can be used to cast away constness. Using any of the other three forms of cast in this case would result in a compile-time error. Similarly, it is a compile-time error to use the const_cast notation to perform any type conversion other than adding or removing const.
只有使用 const_cast 才能將 const 性質轉換掉。在這種情況下,試圖使用其他三種形式的強制轉換都會導致編譯時的錯誤。類似地,除了添加或刪除 const 特性,用 const_cast 符來執行其他任何類型轉換,都會引起編譯錯誤。
3.3 reinterpret_cast
A reinterpret_cast generally performs a low-level reinterpretation of the bit pattern of its operands.
reinterpret_cast 通常為操作數的位模式提供較低層次的重新解釋。
A reinterpret_cast is inherently machine-dependent. Safely using reinterpret_cast requires completely understanding the types involved as well as the details of how the compiler implements the cast.
reinterpret_cast 本質上依賴於機器。為了安全地使用 reinterpret_cast,要求程序員完全理解所涉及的數據類型,以及編譯器實現強制類型轉換的細節。
在引入命名的強制類型轉換操作符之前,顯式強制轉換用圓括弧將類型括起來實現:
The effect of this cast is the same as using the reinterpret_cast notation. However, the visibility of this cast is considerably less, making it even more difficult to track down the rogue cast.
效果與使用 reinterpret_cast 符號相同,但這種強制轉換的可視性比較差,難以跟蹤錯誤的轉換。
Depending on the types involved, an old-style cast has the same behavior as a const_cast, a static_cast, ora reinterpret_cast. When used where a static_cast or a const_cast would be legal, an old-style cast does the same conversion as the respective named cast. If neither is legal, then an old-style cast performs a reinterpret_cast. For example, we might rewrite the casts from the previous section less clearly using old-style notation:
舊式強制轉換依賴於所涉及的數據類型,具有與 const_cast、 static_cast 和 reinterpret_cast 一樣的行為。在合法使用 static_cast 或 const_cast 的地方,舊式強制轉換提供了與各自對應的命名強制轉換一樣的功能。如果這兩種強制轉換均不合法,則舊式強制轉換執行 reinterpret_cast 功能。例如,我們可用舊式符號重寫上一節的強制轉換:
By using a cast, the programmer turns off or dampens normal type-checking. We strongly recommend that programmers avoid casts and believe that most well-formed C++ programs can be written without relying on casts.
強制類型轉換關閉或掛起了正常的類型檢查。強烈建議程序員避免使用強制類型轉換,不依賴強制類型轉換也能寫出很好的 C++ 程序。
arithmetic conversion(算術轉換)
A conversion from one arithmetic type to another. In the context of the binary arithmetic operators, arithmetic conversions usually attempt to preserve precision by converting a smaller type to a larger type (e.g., small integral types, such as char and short, are converted to int).
算術類型之間的轉換。在使用二元算術操作符的地方,算術轉換通常將較小的類型轉換為較大的類型,以確保精度(例如,將小的整型 char 型和 short 型轉換為 int 型)。
dynamic_cast
Used in combination with inheritance and run-time type identification.
用於結合繼承和運行時類型識別。
implicit conversion(隱式類型轉換)
A conversion that is automatically generated by the compiler. Given an expression that needs a particular type but has an operand of a differing type , the compiler will automatically convert the operand to the desired type if an appropriate conversion exists.
編譯器自動實現的類型轉換。假設表達式需要某種特定類型的數值,但其操作數卻是其他不同的類型, 此時如果系統定義了適當的類型轉換 ,編譯器會自動根據轉換規則將該操作數轉換為需要的類型。
integral promotions(整型提升)
Subset of the standard conversions that take a smaller integral type to its most closely related larger type. Integral types (e.g. short, char, etc.) are promoted to int or unsigned int.
整型提升是標准類型轉換規則的子集,它將較小的整型轉換為最接近的較大數據類型。整型(如 short、char 等)被提升為 int 型或 unsigned int 型。
reinterpret_cast
Interprets the contents of the operand as a different type. Inherently machine-dependent and dangerous.
將操作數內容解釋為另一種不同的類型。這類強制轉換本質上依賴於機器,而且是非常危險的。
static_cast
An explicit request for a type conversion that the compiler would do implicitly. Often used to override an implicit conversion that the compiler would otherwise perform.
編譯器隱式執行的任何類型轉換都可以由 static_cast 顯式完成。我們常常使用 static_cast 取代由編譯器實現的隱式轉換。
-End-
⑷ C語言中無符號數和有符號數進行運算時會轉換為無符號還是有符號
首先,浮點類型都是有符號的,有無符號只是對於整形變數棚旦而言,每個無鏈敏擾符號類型的級別都與對應的帶符號類型相同,所以不能直接通過級數高低來轉換(級數高低是long double>double>float>long long>long>int>short>char,),但是如果帶符號類型的值域包含了無符號類型所表示的值,就把無符號轉化為有符號類型,否則,兩個操作數都轉化為對拿畝應的無符號類型。求採納~~
⑸ java 特殊符號輸出 絕對基礎
JAVA中轉義字元:
1.八進制轉義序列:\ + 1到3位5數字;范圍'\000'~'\377'
\0:空字元
2.Unicode轉義字元:\u + 四個十六進制數字;0~65535
\u0000:空字元
3.特殊字元:就3個
\":雙引號
\':單引號
\\:反斜線
4.控制字元:5個
\' 單引號字元
\\ 反斜杠字元
\r 回車
\n 換行
\f 走紙換頁
\t 橫向跳格
\b 退格
點的轉義:. ==> u002E
美元符號的轉義:$ ==> u0024
乘方符號的轉義:^ ==> u005E
左大括弧的轉義:{ ==> u007B
左方括弧的轉義:[ ==> u005B
左圓括弧的轉義:( ==> u0028
豎線的轉義:| ==> u007C
右圓括弧的轉義:) ==> u0029
星號的轉義:* ==> u002A
加號的轉義:+ ==> u002B
問號的轉義:? ==> u003F
反斜杠的轉義: ==> u005C
======================================================================
下面的程序使用了兩個Unicode的轉義字元,它們是用其十六進制代碼來表示Unicode字元。那麼,這個程序會列印什麼呢?
Java代碼
public class EscapeRout{
public static void main(String[] args){
// \u0022 是雙引號的Unicode轉義字元
System.out.println("a\u0022.length()
+\u0022b".length());
}
}
public class EscapeRout{
public static void main(String[] args){
// \u0022 是雙引號的Unicode轉義字元
System.out.println("a\u0022.length()
+\u0022b".length());
}
}
對該程序的一種很膚淺的分析會認為它應該列印出26,因為在由兩個雙引號"a\u0022.length()+\u0022b"標識的字元串之間總共有26個字元。
稍微深入一點的分析會認為該程序應該列印16,因為兩個Unicode轉義字元每一個在源文件中都需要用6個字元來表示,但是它們只表示字元串中的一個字元。因此這個字元串應該比它的外表看其來要短10個字元。 如果你運行這個程序,就會發現事情遠不是這么回事。它列印的既不是26也不是16,而是2。
理解這個謎題的關鍵是要知道:Java對在字元串字面常量中的Unicode轉義字元沒有提供任何特殊處理。編譯器在將程序解析成各種符號之前,先將Unicode轉義字元轉換成為它們所表示的字元[JLS 3.2]。因此,程序中的第一個Unicode轉義字元將作為一個單字元字元串字面常量("a")的結束引號,而第二個Unicode轉義字元將作為另一個單字元字元串字面常量("b")的開始引號。程序列印的是表達式"a".length()+"b".length(),即2。
如果該程序的作者確實希望得到這種行為,那麼下面的語句將要清楚得多:
Java代碼
System.out.println("a".length()+"b".length());
更有可能的情況是該作者希望將兩個雙引號字元置於字元串字面常量的內部。使用Unicode轉義字元你是不能實現這一點的,但是你可以使用轉義字元序列來實現[JLS 3.10.6]。表示一個雙引號的轉義字元序列是一個反斜杠後面緊跟著一個雙引號(\」)。如果將最初的程序中的Unicode轉義字元用轉義字元序列來替換,那麼它將列印出所期望的16(錯誤,應該是14,不知道是怎麼會出來16):
Java代碼
System.out.println("a\".length()+\"b".length());
許多字元都有相應的轉義字元序列,包括單引號(\')、換行(\n)、製表符(\t)和反斜線(\\)。你可以在字元字面常量和字元串字面常量中使用轉義字元序列。
實際上,你可以通過使用被稱為八進制轉義字元的特殊類型的轉義字元序列,將任何ASCII字元置於一個字元串字面常量或一個字元字面常量中,但是最好是盡可能地使用普通的轉義字元序列。
普通的轉義字元序列和八進制轉義字元都比Unicode轉義字元要好得多,因為與Unicode轉義字元不同,轉義字元序列是在程序被解析為各種符號之後被處理的。
ASCII是字元集的最小公共特性集,它只有128個字元,但是Unicode有超過65,000個字元。一個Unicode轉義字元可以被用來在只使用ASCII字元的程序中插入一個Unicode字元。一個Unicode轉義字元精確地等價於它所表示的字元。
Unicode轉義字元被設計為用於在程序員需要插入一個不能用源文件字元集表示的字元的情況。它們主要用於將非ASCII字元置於標識符、字元串字面常量、字元字面常量以及注釋中。偶爾地,Unicode轉義字元也被用來在看起來頗為相似的數個字元中明確地標識其中的某一個,從而增加程序的清晰度。
總之,在字元串和字元字面常量中要優先選擇的是轉義字元序列,而不是Unicode轉義字元。Unicode轉義字元可能會因為它們在編譯序列中被處理得過早而引起混亂。不要使用Unicode轉義字元來表示ASCII字元。在字元串和字元字面常量中,應該使用轉義字元序列;對於除這些字面常量之外的情況,應該直接將ASCII字元插入到源文件中。
⑹ ARM匯編中符號命名規則
特殊符號 ---- 對應指令 ---- 含義 ---- 示例
^ ---- MAP ---- 定義結構化內存表 ---- MAP 4096;內存表首地址為4096
# ---- FIELD ---- 定義內存表中的數據,結合MAP指令使用 ----
MAP 4096
STACKSVC FIELD 256;定義從4096開始的256位元組為SVC的堆棧空間。
% ---- SPACE ---- 分配一塊內存,並用「0」初始化 ---- DataStruc SPACE 280;分配280位元組內存並初始化
[|] ---- IF ELSE ENDIF ---- 條件編譯,有選擇的確定需要編譯的代碼IF,ELSE,ENDIF,可以嵌套使用 ----
IF 邏輯塵裂首表達式
指令或偽指令
ELSE
指令或偽指令
ENDIF
另外還有符號: $
如果在串變數前有一個$,則在匯編時編譯器將用該串變數的數值取代該串變數,如:
GBLS STR1
GBLS STR2
STR1 SETS 「pen.」
STR2 SETS 「This is a $STR1"
編譯後的結果是STR2的值為This is a pen.
如派數果$後是數字變數(與串變數區分),在匯編時編譯器將該數字變數的數值轉換成十六進制的串,然後用該十六進制的串取代$後的數字變數。
如果$後是邏輯變數,在匯編時編譯器將該邏輯變數替換成它的取值(T或者F)。
如果程序中需要$,則用$$來表示,編譯器將不進行變數替換。
GBLS STR1
GBLS B
GBLA NUM1
NUM1 SETA 14
B SETS 「CHANGED」
STR1 SETS 「abc$$B$NUM1」
編譯結果STR1的值為:abcB0000000E。
注意:在兩個豎線源碧「|」之間的$並不表示進行變數替換,但如果「|」是在雙引號內,則將進行變數替換。
使用點"."來表示變數名的結束。
GBLS STR1
GBLS STR2
STR1 SETS 「AAA」
STR2 SETS 「bbb$STR1.CCC"
編譯結果STR2值為bbbAAACCC
還有
⑺ java 特殊符號輸出絕對基礎
稍微深入一點的分析會認為該程序應該列印16,因為兩個Unicode轉義字元每一個在源文件中都需要用6個態正字元來表示,但是它們只表示字元串中的一個字元。因此這個字元串應該比它的外表看其來要短10個字元。 如果你運行這個程序,就會發現事情遠不是這么回事。它列印的既不是26也不是16,而是2。 理解這個謎題的關鍵是要知道:Java對在字元串字面常量中的Unicode轉義字元沒有提供任何特殊處理。編譯器在將程序解析成各種符號之前,先帆如悔將Unicode轉義字元轉換成為它們所表示的字元[JLS 3.2]。因此,程序中的第一個Unicode轉義字元將作為一個單字元字元串字面常量("a")的結束引號,而第二個Unicode轉義字元將作為另一個單字元字元串字面常量("b")的開始引號。程序列印的是橡塌表達式"a".length()+"b".length(),即2。
⑻ C語言隱式類型轉換規則。編譯器難道執行雙重標准嗎
(a+b==-1)?printf("a+b等盯輪握於-1\n"):printf("a+b不等於-1\n");/凱慶/此處輸出桐凳a+b等於-1;
-1也會提升為無符號,提升後值就是32位無符號最大值4294967295 ,所以就和a+b相等了,條件為真。
⑼ 靜態庫符號替換方法
靜態庫符號替換是指在編譯時燃侍,將程序中的函數名稱修改為它們在靜態庫中的實際函數名。通常情況下,編譯器會將函數名稱改為一個簡短的字元串,以便提高程序的效率。符號替換過程中,編譯器會把這些簡短的字元串替換成它們在靜態庫中實際的函數名稱,這樣程序就可以正確地找到所需的函數了。
一般可以通過兩種方式來實現:
1、使用編譯器提供的符號替換選項,如gcc中的-fPIC,-fpic參數,這種方法可以在編譯時完成符號替換,但是會降低程序的性能。
2、使用符號替換工具,如GNU的nm工具,該工具皮攔吵可以在編譯完成後實現符號替換,但是這種方法要求每個庫都必須是衡納相對獨立的,即不可以引用其他庫中的符號。
⑽ 編譯器怎麼編譯整數類型的呢
編譯器是以整型存儲整數的,C語言中atoi,_ttoi等函數就可以實現字元串數值到整形數值的轉換,自己可以按照以下演算法實現:
BYTE HexChar2Number(char c)
{
if('0' <= c && c <= '9')
{
return (BYTE)(c - '0');
}
if('A' <= c && c <= 'F')
{
return (BYTE)(c - 'A' + 10);
}
if('a' <= c && c <= 'f')
{
return (BYTE)(c - 'a' + 10);
}
printf("error char: %c\n", c);
return 0;
}
逐字元識別,識別多位數時自己乘以進制權值。