ADL is the abbreviation for Argument-dependent lookup
, which in Chinese translates to 参数依赖查找. ADL is useful for avoiding verbose code, but it can also cause some ambiguity.
TC++PL4E Chinese and English Edition Errata
最近在读The C++ Programming Language Fourth Edition(简称TC++PL4E),由于我入的实体书是中译本(原版好贵),所以我是对照着英文版PDF看的,发现了一些原版和中译本中的勘误,还有一些我觉得书中歧义的地方,查阅标准(ISO/IEC 14882:2014(E))之后的定义也一并贴出,汇总在这里列出来。
Some excerpts from the C/C++ standard
There are countless resources on C/C++ available online, but I often find that, after reading some articles, it seems the authors themselves don’t fully understand what they wrote (looking back at my own earlier articles, my perspective was too one-sided and superficial at that time). Therefore, for C/C++ materials, I believe it’s essential to refer directly to the standard documentation, as standards do not introduce ambiguities. One should not blindly search the internet and trust second-hand digested materials.
I think consulting these four documents is enough for understanding the features of the C/C++ languages (click to preview online or download):
- ISO/IEC 9899:1999 (E) (C99 standard)
- The C Programming Language Second Edition (The major work of C language creators Dennis Ritchie and Brian Kernighan)
- ISO/IEC 14882:2014(E) (C++14 standard)
- The C++ Programming Language Fourth Edition (Written by the father of C++, based on the C++11 standard)
The reason the C language standard does not follow the latest C11 standard is that the current C++ standard (C++14) references ISO/IEC 9899:1999 in its Normative references
, which means TCPL and TC++PL can serve as applicable descriptions for the C/C++ standards and can corroborate each other.
For more about C++ Normative references
, refer to ISO/IEC 14882:2014(E) §1.2 Normative references.
I will gradually extract some commonly ambiguous language features from the standard norms here to ensure that what I write is backed by the standard documentation.
Some interesting questions and analysis of CppQuiz
CppQuiz is a simple online quiz that you can use to test your knowledge of the C++ programming language.
It’s quite interesting; I wrote down a few questions I encountered today. I’ll add more here whenever I have time. In fact, many questions in CppQuiz can be explained by “Deep Exploration of C++ Object Model”… If you find yourself struggling with many questions, I recommend buying a copy of “Deep Exploration of C++ Object Model” and reading it thoroughly!
In addition, I will try to find relevant descriptions in the C++ standard (ISO/IEC 14882:2014) while answering questions.
Automatically deploy Github/Coding Pages blog using Travis CI
This blog has switched to Github Action for automated deployment.
Using Hexo to generate a static blog and then deploying it to Github/Coding Pages is currently how my blog is hosted. It’s quite enjoyable to use, but there are several issues:
- The environment configuration for Hexo is too cumbersome; it’s almost impossible to update the blog when changing to a new computer.
- Each time I modify an article, I have to regenerate everything.
- Additionally, the number of command executions for submitting the blog source files is too high (mainly the first step).
I wasted a lot of time submitting articles, so I optimized the process to almost achieve fully automated submissions.
Boost source code analysis notes
Recently, I’ve been reading the Boost code and writing some analyses on the usage and implementation of useful modules in the Boost libraries, with updates to come periodically.
Configure SublimeText for Boost dev-environment
Recently, I would like to study the Boost library. Most tutorials available online are based on using IDEs (such as VS/Code::Blocks), but I find it frustrating to have to open a bloated IDE just to write some test code. Today, I fiddled around and managed to compile/link code that uses the Boost library in SublimeText. I also organized the process/tools I worked with, so if others have similar needs and happen to see this article, they can save some time.
2016.11.01 Update
I used the latest version of MinGW64-GCC6.2 (x86_64-6.2.0-posix-seh-rt_v5-rev1) to compile LLVM/Clang 3.9, and then I used the compiled Clang to compile Boost1.62. The error messages that occurred when linking the Boost library in Clang are gone now.
Note: When compiling Boost with Clang, it is best to ensure that the current version of clang is compiled from the version of gcc in the current system; otherwise, when linking the static libraries produced by clang, strange issues might arise.
You can download my compiled versions here: MinGW62-GCC6.2(x86_64-6.2.0-posix-seh-rt_v5-rev1), LLVM/Clang3.9 compiled with GCC6.2 (above MinGW version), and Boost(MinGW64-GCC6.2/LLVM3.9/VC14-ALL). You can choose the version of the linked library (debug/release/static, etc.) as needed.
You can download the full compilation toolchain here.
Deploy shadowsocks service using Docker
Using Git for version control in UE4
The Source Control provided in Unreal Editor allows you to implement basic functions such as version submission/version comparison/reverting changes through Git for blueprint projects, which is far less powerful than Git Bash, but the Diff between BluePrints is still very useful.
Git Quick Start Guide
no hostkey alg
When connecting to the SSH Server, if this prompt appears, it is due to the SSH version being used; the remote SSHD version is too high while the local SSH version is too low.
1 | OpenSSH_5.1p1, OpenSSL 0.9.8i 15 Sep 2008 |
UE updated the client’s SSH version in the 4.27 engine: Replace Windows ssh and rsync from DeltaCopy with new version from cw…
If the engine version is earlier than 4.27, upgrading to MacOS13+ will encounter this problem during remote builds. ## detected dubious ownership in repository at
1 | $ git remote set-url origin https://git.woa.com/xxxx/UnrealEngine.git |
If you switch to a new account, you will encounter the error message above for repositories pulled using the previous account.
The solution is to add all paths to the safe directory:
1 | git config --global --add safe.directory "*" |
Note: This command must be executed in the new account.
Warning: the ECDSA host key
When you encounter the warning while submitting to GitHub: Warning: the ECDSA host key for 'github.com' differs from the key for the IP address '192.30.255.112'
, it means your SSH client has authenticated another host matching the target IP address.
To resolve this issue, please follow these steps:
1. Remove the old key from the known_hosts file:
Open the ~/.ssh/known_hosts
file with a text editor (Windows users should find the file at %UserProfile%\.ssh\known_hosts
) and locate the corresponding entry (referring to the IP address and hostname), then delete the corresponding line.
For example, find the following entry in the known_hosts
file:
1 | github.com,192.30.255.112 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hX ... |
Delete that line.
2. Confirm GitHub’s SSH host fingerprint:
Confirm the currently valid transport layer security (TLS) public key fingerprint and SSH public key fingerprint from the GitHub official documentation.
3. Reconnect via SSH and add the new host key:
Execute the following command in the terminal or command prompt:
1 | ssh -T -oStrictHostKeyChecking=accept-new git@github.com |
This will automatically add the new github.com
host key.
If prompted with “Hi username! You’ve successfully authenticated, but GitHub does not provide shell access.”, it means the SSH authentication is successful and the issue has been resolved.
Now, you should be able to submit code to GitHub normally, and the warning message should no longer appear.
pull/push prompts for password every time
You can execute the following command:
1 | git config --global credential.helper store |
Get the latest commit information of the current repository
To get the latest commit ID of the current repository, you can use the following command:
1 | $ git rev-parse HEAD |
If you want to see branch and commit information, you can use the command below:
1 | $ git log -1 --pretty=oneline |
The -1
argument lists only the most recent commit.
If you add --decorate
, you can see the branch information (this also depends on the git version; newer versions display branch information by default):
1 | $ git log -1 --pretty=oneline --decorate |
SSH login with key failed
If you receive the following error when connecting via SSH:
1 | lipengzha@192.168.31.55: Permission denied (publickey,password,keyboard-interactive). |
You can modify the server-side SSH configuration (/etc/ssh/sshd_config
):
1 | RSAAuthentication yes |
Then restart the SSHD service.
Check the last modifier of a specific line of code
To view the last commit person for code at lines n~m
of a file:
1 | git blame filename -L n,m |
It will output:
1 | e74836f557b (lipengzha 2024-01-10 09:43:02 +0800 541) TArray<FString> FoundShaderLibs = UFlibShaderCodeLibraryHelper::FindCookedShaderLibByPlatform(PlatformName,SavePath,false); |
1 | git blame -L 541,541 --incremental --minimal Plugins\\HotPatcher\\HotPatcher\\Source\\HotPatcherCore\\Private\\CreatePatch\\PatcherProxy.cpp |
Output:
1 | e74836f557bc5ddf01de3f5f8d3b797107d9a767 541 541 1 |
Clear all history records
To clear all history records in a Git repository, keeping only the latest commit, you can follow these steps:
Create a new branch:
First, ensure you are in a clean working directory (no uncommitted changes), then create a new branch.1
git checkout --orphan latest_branch
This command creates a new branch without any history.
Add all files:
Add all files to the new branch.1
git add -A
Commit changes:
Commit all files.1
git commit -am "Initial commit with latest state"
Delete the old branch:
Switch back to the main branch and delete the old branch.1
git branch -D main
Rename the new branch to main:
Rename the new branch to the main branch.1
git branch -m main
Force push to the remote repository:
Finally, force push the changes to the remote repository. Note: This will overwrite all history in the remote repository.1
git push -f origin main
This will clear all history records, keeping only the latest commit. This operation is irreversible; all historical records will be permanently deleted, so please ensure you really do not need these historical records before executing this operation.
Differences in line endings between Win and Linux
Windows uses carriage return and line feed (CRLF, \r\n
), while Linux uses line feed (LF, \n
). If you create or modify files on Windows and then view them on Linux, Git may recognize changes due to the differences in line endings.
The solution is to configure how Git handles line endings. Use the following commands to set Git to automatically convert line endings:
1 | git config --global core.autocrlf true # Windows |
- Use a
.gitattributes
file to specify how line endings should be treated for specific files, for example:
1 | * text=auto |
Note: After I set this, I found that changes in files could not be displayed in real-time in the working directory. You can delete this configuration in
C:\User\[USER_NAME]\.gitconfig
.
Batch convert line endings
I wrote a Python script to implement this: git_eol_normalize.py
1 | python3 git_eol_normalize.py --repo_Dir REPO_ROOT_DIR --eol LF |
You can modify the list of text formats in g_text_exts
as needed.
UPDATE
CheatSheet
Reference Articles
Explanation of Git Remote Operations
Creating and Merging Branches
Reversing Branch Deletion in Git
Reverting Changes with git checkout Command
Using git diff to Compare Two Branches