跳到主要內容

發表文章

目前顯示的是 2022的文章

C++ 明確樣板具現化 (C++ Explicit Template Instantiation)

C++ 明確樣板具現化 (C++ Explicit Template Instantiation) 基本 C++ 裡面,樣板在編譯期時才會被具現化 (instantiated),例如 template < typename T > struct Foo { Foo ( T t ) : t_ ( t ) { } T t_ ; } ; // Foo<int> 在下一行被具現化 void g ( ) { Foo < int > f ( 123 ) ; } 明確具現化,則是站在設計樣板函示庫者的角度,提供用戶具現化樣板,將明確具現化的類別放在標頭檔如下 // --- foo.h 標頭檔內容 template < typename T > struct Foo { /* ... */ } ; // 明確具現化宣告,引入此標頭檔的編譯單元不會嘗試具現化 Foo<int> 及 Foo<double> extern template struct Foo < int > ; extern template struct Foo < double > ; 並將具現化類別定義放在實作檔案 // --- foo.cc # include "foo.h" // 明確具現化定義 template struct Foo < int > ; template struct Foo < double > ; 這與一般分割宣告與定義相同,差別只在多了樣板的語法。這個做法用意在於提供常用的具現化樣板類別,這樣多個轉譯單元 (translation unit) 在編譯時不必每遇到 Foo<int> 都具現化一次,從而減少編譯時間。 動態連結 (Dynamic Linking) 跟一般的動態函示庫相同,當樣板類別被明確具現化後,也需要被匯出 (export) 才能夠透過動態繫結使用。下面是一份常見的匯出輔助標頭檔: // export.h # pragma once # if defined...

Migrate OSes of AMD drivers to Non-AMD Hardware

Migrate OSes of AMD drivers to Non-AMD Hardware Scenario A bootable disk of GRUB multi-boot configuration for Ubuntu Desktop 20.04 and Windows 10. Migrate the disk from machine A to B, where, Machine A has AMD APU A10 5800K and AMD RX570 graphics card installed as well as related drivers. Machine B has Intel i5 CPU and Nvidia 3060 graphics card installed. Issue Both Windows 10 and Ubuntu failed to boot normally. Ubuntu displayed black screen and Windows 10 displayed BSOD within AODDriver2.sys errors. Solution The main goal is removing the problematic driver. Thus we need to boot without loading the driver. Following are steps for both OSes. Ubuntu Select Advanced Options for Ubuntu . Select latest kernel version of (recovery mode) suffix. Select Enable network (may not necessary, I did it anyway). Select resume . Such that Ubuntu successfully boots into desktop environment without loading the problematic graphics driver. For now screen resolution...