GNU format attributes
__attribute__ format(printf, 2, 3)
a variadic logger
Saturday, December 8, 2018
Sunday, November 25, 2018
11/25/2018:
1. C++ sanitizers:
2. C++ open source codes:
3. C++ website:
3.1) Compiler Explorer
3.2) Cpp insights
4. CppCon 2015: Chandler Carruth "Tuning C++: Benchmarks, and CPUs, and Compilers! Oh My!"
1. C++ sanitizers:
- ubsan: undefined behavior sanitizer
- asan: address sanitizer
- tsan: thread sanitizer
- msan: memory sanitizer
2. C++ open source codes:
- {fmt}
- spdlog
3. C++ website:
3.1) Compiler Explorer
3.2) Cpp insights
4. CppCon 2015: Chandler Carruth "Tuning C++: Benchmarks, and CPUs, and Compilers! Oh My!"
Thursday, November 8, 2018
Sunday, June 3, 2018
Variadic template pack expansion
#include <iostream>
template <typename T>
void bar(T t) { std::cout << t << '\n'; }
template <typename... Args>
void foo2(Args&&... args)
{
__attribute__((unused)) int dummy[] = { 0, ((void) bar(std::forward<Args>(args)),0)... };
}
int main()
{
foo2();
foo2 (1, 2, 3, "30");
}
One of the places where a pack expansion can occur is inside a braced-init-list. You can take advantage of this by putting the expansion inside the initializer list of a dummy array:
template<typename... Args>
static void foo2(Args &&... args)
{
int dummy[] = { 0, ( (void) bar(std::forward<Args>(args)), 0) ... };
}
To explain the content of the initializer in more detail:
{ 0, ( (void) bar(std::forward<Args>(args)), 0) ... };
| | | | |
| | | | --- pack expand the whole thing
| | | |
| | --perfect forwarding --- comma operator
| |
| -- cast to void to ensure that regardless of bar()'s return type
| the built-in comma operator is used rather than an overloaded one
|
---ensure that the array has at least one element so that we don't try to make an
illegal 0-length array when args is empty
C++17: Fold expressions
template<typename ...Args> auto sum(Args ...args)
{
return (args + ... + 0);
}
// or even:
template<typename ...Args> auto sum2(Args ...args)
{
return (args + ...);
}
Tuesday, December 20, 2016
Tuesday, June 9, 2015
Thursday, May 14, 2015
Linux PCIE & DMA tutorials
1. http://en.wikipedia.org/wiki/PCI_configuration_space
2. https://www.kernel.org/doc/Documentation/DMA-API-HOWTO.txt
3. http://linuxgazette.net/156/jangir.html
4. http://www.tldp.org/LDP/tlk/dd/pci.html
5. https://lkml.org/
6. http://bbs.chinaunix.net/forum.php?mod=forumdisplay&fid=227&page=1
1. http://en.wikipedia.org/wiki/PCI_configuration_space
2. https://www.kernel.org/doc/Documentation/DMA-API-HOWTO.txt
3. http://linuxgazette.net/156/jangir.html
4. http://www.tldp.org/LDP/tlk/dd/pci.html
5. https://lkml.org/
6. http://bbs.chinaunix.net/forum.php?mod=forumdisplay&fid=227&page=1
Subscribe to:
Posts (Atom)