What is enable_shared_from_this in cpp

Problem class C : public enable_shared_from_this<C> { public: std::shared_ptr<C> func() { std::shared_ptr<C> local_sp_a(this); return local_sp_a; } }; int main() { C c; auto a = c.func(); return 0; } // Output: // ./a.out // double free or corruption (out) // fish: Job 1, './a.out' terminated by signal SIGABRT (Abort) Why it is because when a shared_ptr was created, the control block was build up too, and there are three methods can create control block ...

July 3, 2023 · 1 min · hengist

Gentoo Install

I. Prepare Disk #disk wipe sgdisk --zap-all /dev/sda #partition disk cfdisk -z /dev/sda mkfs.vfat -F 32 /dev/sda1 mkfs.btrfs/ext4/xfs/.... /dev/sda3 mkswap /dev/sda2 swapon /dev/sda2 #then mount them II. Installing stage3 Download the stage3 from Gentoo’s website and put it in the /mnt/gentoo # unpack it tar xpvf stage3-*.tar.xz --xattrs-include='*.*' --numeric-owner # get the portage config from my own git repo # and set fstab genfstab -U /mnt/gentoo >> /mnt/gentoo/etc/fstab # then config repos.conf: mkdir --parents /mnt/gentoo/etc/portage/repos.conf cp /mnt/gentoo/usr/share/portage/config/repos.conf /mnt/gentoo/etc/portage/repos.conf/gentoo.conf # Copy DNS info cp --dereference /etc/resolv.conf /mnt/gentoo/etc/ # Mounting the necessary filesystems mount --types proc /proc /mnt/gentoo/proc mount --rbind /sys /mnt/gentoo/sys mount --make-rslave /mnt/gentoo/sys mount --rbind /dev /mnt/gentoo/dev mount --make-rslave /mnt/gentoo/dev mount --bind /run /mnt/gentoo/run mount --make-slave /mnt/gentoo/run # chroot chroot /mnt/gentoo /bin/bash source /etc/profile export PS1="(chroot) ${PS1}" # make sure all partition are mounted correct emerge --sync #set profle eselect profile list eselect profile set X # config ccache before this step emerge -auvDN --with-bdeps=y --autounmask-write @world add ccache ...

July 2, 2023 · 2 min · hengist

Link Load Lib

Chap I Chap II Preprocessing gcc -E src.c -o src.i This operation did several things. processing all the instructions begin with ‘#’, delete all of them except ‘#pragma’, and process the ‘#include’ recursively. delete all comments. add line number and file name identifiers Compile to assembly code gcc -S src.i -o src.s # or gcc -S src.c -o src.s # or ccl src.c Assembly to machine code as src.s -o src.o # or gcc -c src.s -o src.o # or gcc -c src.c -o src.o Link to executable program ...

July 2, 2023 · 1 min · hengist