<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          C++核心準(zhǔn)則?Pro.safety:類型安全準(zhǔn)則群組

          Pro.safety: Type-safety profile

          Pro.safety:類型安全準(zhǔn)則群組


          This profile makes it easier to construct code that uses types correctly and avoids inadvertent type punning. It does so by focusing on removing the primary sources of type violations, including unsafe uses of casts and unions.

          此群組使程序員可以更容易地構(gòu)建類型正確的代碼,并且避免了無意的類型調(diào)整。它的重點是消除類型違規(guī)的主要根源,包括不安全使用強制類型轉(zhuǎn)換和聯(lián)合。

          For the purposes of this section, type-safety is defined to be the property that a variable is not used in a way that doesn't obey the rules for the type of its definition. Memory accessed as a type?T?should not be valid memory that actually contains an object of an unrelated type?U. Note that the safety is intended to be complete when combined also with?Bounds safety?and?Lifetime safety.

          在本節(jié)中,類型安全性的含義是:變量的屬性沒有以違反該變量被定義時的類型規(guī)則的方式被使用。作為類型T訪問的內(nèi)存不應(yīng)是包含實際上是無關(guān)類型U的對象的有效內(nèi)存。請注意,將安全性與“邊界”安全性和“生命周期”安全性結(jié)合使用時,應(yīng)確保其安全性。

          An implementation of this profile shall recognize the following patterns in source code as non-conforming and issue a diagnostic.

          Type safety profile summary:

          此規(guī)則群組的實現(xiàn)應(yīng)將源代碼中的以下模式識別為不合格,并發(fā)出診斷信息。

          類型安全群組概要:

          • Type.1:?Avoid casts:?a.?Don't use?reinterpret_cast; A strict version of?Avoid casts?and?prefer named casts.?b.?Don't use?static_cast?for arithmetic types; A strict version of?Avoid casts?and?prefer named casts.?c.?Don't cast between pointer types where the source type and the target type are the same; A strict version of?Avoid casts.?d.?Don't cast between pointer types when the conversion could be implicit; A strict version of?Avoid casts.

            類型1:避免強制轉(zhuǎn)換:不要使用reinterpret_cast;避免使用強制轉(zhuǎn)換的嚴(yán)格版本,最好使用命名轉(zhuǎn)換。b.不要將static_cast用于算術(shù)類型;避免使用強制轉(zhuǎn)換的嚴(yán)格版本,最好使用命名轉(zhuǎn)換。C。不要在源類型和目標(biāo)類型相同的指針類型之間進行強制轉(zhuǎn)換;避免使用強制轉(zhuǎn)換的嚴(yán)格版本。d。當(dāng)轉(zhuǎn)換可能是隱式的時,不要在指針類型之間進行轉(zhuǎn)換;避免使用強制轉(zhuǎn)換的嚴(yán)格版本。

          • Type.2: Don't use?static_cast?to downcast:?Use dynamic_cast instead.

            類型2:請勿使用static_cast進行下轉(zhuǎn)換:請使用dynamic_cast

          • Type.3: Don't use?const_cast?to cast away?const?(i.e., at all):?Don't cast away const.

            類型3:請勿使用const_cast舍棄const(即完全取消):請勿舍棄const。

          • Type.4: Don't use C-style?(T)expression or functional T(expression) casts: Prefer?construction?or?named casts?or?T{expression}.

            Type.4:請勿使用C樣式(T)表達式或函數(shù)型T(expression)強制類型轉(zhuǎn)換:構(gòu)造命名強制類型轉(zhuǎn)換或T {expression}更好。

          • Type.5: Don't use a variable before it has been initialized:?always initialize.

            Type.5:初始化之前不要使用變量:始終初始化

          • Type.6: Always initialize a member variable:?always initialize, possibly using?default constructors?or?default member initializers.

            Type.6:始終初始化成員變量:始終初始化,可能使用默認構(gòu)造函數(shù)默認成員初始化器。

          • Type.7: Avoid naked union:?Use?variant?instead.

            類型7:避免暴露的聯(lián)合體:改用標(biāo)準(zhǔn)庫variant類型。

          • Type.8: Avoid varargs:?Don't use?va_arg?arguments.

            Type.8:避免使用varargs:不要使用va_arg參數(shù)


          Impact(影響)

          With the type-safety profile you can trust that every operation is applied to a valid object. An exception can be thrown to indicate errors that cannot be detected statically (at compile time). Note that this type-safety can be complete only if we also have?Bounds safety?and?Lifetime safety. Without those guarantees, a region of memory could be accessed independent of which object, objects, or parts of objects are stored in it.

          使用類型安全規(guī)則群組,您可以相信每個操作都將應(yīng)用于有效對象。可以引發(fā)異常以指示無法靜態(tài)(在編譯時)檢測到的錯誤。請注意,只有在我們同時確保邊界安全性和生命周期安全性的情況下,才能b此類型安全性。如果沒有這些保證,則可以任意訪問存儲區(qū)域,而與存儲在其中的個別對象,全體對象或部分對象無關(guān)。


          原文鏈接

          https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#prosafety-type-safety-profile


          新書介紹

          《實戰(zhàn)Python設(shè)計模式》是作者最近出版的新書,拜托多多關(guān)注!

          本書利用Python 的標(biāo)準(zhǔn)GUI 工具包tkinter,通過可執(zhí)行的示例對23 個設(shè)計模式逐個進行說明。這樣一方面可以使讀者了解真實的軟件開發(fā)工作中每個設(shè)計模式的運用場景和想要解決的問題;另一方面通過對這些問題的解決過程進行說明,讓讀者明白在編寫代碼時如何判斷使用設(shè)計模式的利弊,并合理運用設(shè)計模式。

          對設(shè)計模式感興趣而且希望隨學(xué)隨用的讀者通過本書可以快速跨越從理解到運用的門檻;希望學(xué)習(xí)Python GUI 編程的讀者可以將本書中的示例作為設(shè)計和開發(fā)的參考;使用Python 語言進行圖像分析、數(shù)據(jù)處理工作的讀者可以直接以本書中的示例為基礎(chǔ),迅速構(gòu)建自己的系統(tǒng)架構(gòu)。




          覺得本文有幫助?請分享給更多人。

          關(guān)注微信公眾號【面向?qū)ο笏伎肌枯p松學(xué)習(xí)每一天!

          面向?qū)ο箝_發(fā),面向?qū)ο笏伎迹?/span>



          瀏覽 27
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          評論
          圖片
          表情
          推薦
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  亚洲高清在线 | 欧美成人手机在线看片 | 免费AV黄色 | 鸡巴操穴视频 | 一级无码爱爱片免费 |