Merry Christmas
24, Dec, 2020to everyone and to everyone who is reading it.
- Posted by michal in
- 6 comments
sudo su
16, Dec, 2020security or insanity?
because su was too short?
- Posted by michal in
- 13 comments
use boost
1, Dec, 2020to boost your building environment maintenance time
- Posted by michal in
- 11 comments
…
6, Nov, 2020The variadic arguments don’t have a way to check the number of arguments or at least to check if the va_list is exhausted. So, here is my question:
How the va_copy is implemented?!
- Posted by michal in
- 7 comments
results are outmoded?!
30, Oct, 2020posix:
pthread_join(pthread_t, void **result);
std-c:
int thrd_join(thrd_t, int *result);
std-c++:
void std::thread::join();
- Posted by michal in
- 14 comments
there is no spoon
27, Oct, 2020The code is given:
#include <stdio.h>
int main() {
struct A {} a;
printf("%dn", sizeof(a));
return 0;
}
C:
0
C++:
1
- Posted by michal in
- 2 comments
slow init vs init slow
15, Sep, 2020The way of initialization may result in quite interesting bottlenecks..
The first way needs separate allocation:
void *data = malloc(); load(data); glBufferStorage(target, sz, data, GL_MAP_READ_BIT | GL_MAP_WRITE_BIT | GL_DYNAMIC_STORAGE_BIT); free(data);
which can be avoided using the second way:
glBufferStorage(target, sz, NULL, GL_MAP_READ_BIT | GL_MAP_WRITE_BIT | GL_DYNAMIC_STORAGE_BIT); void *data = glMapBufferRange(target, 0, sz, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); load(data); glUnmapBuffer(target);
However, the second way resulted in 30% slowdown comparing to first on every draw call with this buffer.
- Posted by michal in
- 1431 comments
***, frak you!
14, Sep, 2020The GL_MAP_PERSISTENT_BIT passed to the glBufferStorage was responsible for 4x slowdown. Even when glMapBufferRange was not used persistently. Only on one gfx card vendor.
- Posted by michal in
- 14 comments
Worst case
3, Sep, 2020A gui library hit back with performance issue. On object list everything went well until we inserted all things at once. At ~100 items all went uninteractive. Normally it is going with thousands. So what happend? Of course list was sorted, and I bet quick sorted. We hit penalty because incoming list also was sorted. Hack of the day - unsort ;)
- Posted by michal in
- 11 comments
locale dependent bug
27, Aug, 2020gettext("")
In one language that function returned a random string.
- Posted by michal in
- 14 comments
shortsignedness
27, Aug, 2020
enum {
THE = 0x8000
};
short val = THE;
if (THE == val) {
/* nope */
}
- Posted by michal in
- Add a comment
safe API?
18, Aug, 2020char *strncat(char *dst, char const *src, size_t num );
num - Maximum number of characters to be appended.
- Posted by michal in
- Add a comment
C++ constructors misdesign..
4, Aug, 2020
class Channel {
Channel(char *name, int port); // server
Channel(char *address, int port); // client
}
And yes, everybody knows the named constructor pattern, but why constructors are not named by default?
- Posted by michal in
- Add a comment
Language (d)evolution
31, Jul, 2020A few days ago my colleague sent me an article on new C standard. I read it without any hope. The author admired inclusion of nullptr as an typesafe miracle (not noting that any decent C lib defines it as (void*)0, not C++’s 0). Maybe he like to be more verbose? The standardization of compiler’s custom attributes looks that the committee is really being bored. The most important defer feature is still absent, and the 20+ years of typeof operator life in several compilers is to less to be acknowledged.
There was also a note that K&R declarations (sic!) will not be supported any more. It really does not bother me, I accustomed to prototypes. But, I got inspired and searched for first real C standard. The C Programming Language by Kernighan and Ritchie. How, it look like back then?
It was simpler. Only 5 types char, short, int, float and double. And pointers to them, which also were notation to arrays. Structures cannot be accessed (moved) by value, but by reference or primitive member. The int type was default type (now at best you have warning when omitting) and pointers have the same size as int. There was no problem with casting pointer to int, there were no problem of implicit function declaration returning pointer, there was no problem with passing pointers into varargs or other non-prototype functions. There were no prototypes, there were no need for them in that language. The default promotions were really no-ops, and these were helpful, not esoteric. There were no UB, aliasing, volatile, restricted, void and other clowns. It was powerful assembly macro language. Even goto was safer as all parameters were initialized on the begin of function (no jump through uninitialized variable to clean_at_end: label). And it is really funny that somebody likes brevity of anonymous function arguments of a “new” standard:
int main(int, char *[]) {
return 0;
}
Back then you might just written:
main() {
}
(implicit int return type, unspecified arguments, and default return).
The many people talks about evolution of the languages (C, C - -, …). But, is there an real evolution? Evolution means there is a natural selection. Do unuseful features disappear? Do we type less to get the same goal? Do we have language that does not make us surprised in debugger, looking on another corner case?
- Posted by michal in
- Add a comment
When insertion sort is faster than qsort()?
27, May, 2020So, lets measure:
But, I little tricked it. Be aware that it is only for ints. Not so much for strings:

- Posted by michal in
- Add a comment