Merry Christmas

24, Dec, 2020

to everyone and to everyone who is reading it.

Xmas emotions

24, Dec, 2020

It’s simple:

sudo pacman -Syu

sudo su

16, Dec, 2020

security or insanity?
because su was too short?

use boost

1, Dec, 2020

to boost your building environment maintenance time

…

6, Nov, 2020

The 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?!

results are outmoded?!

30, Oct, 2020

posix:

pthread_join(pthread_t, void **result);

std-c:

int thrd_join(thrd_t, int *result);

std-c++:

void std::thread::join();

there is no spoon

27, Oct, 2020

The code is given:

#include <stdio.h>

int main() {
    struct A {} a;

    printf("%dn", sizeof(a));

    return 0;
}

C:

0

C++:

1

slow init vs init slow

15, Sep, 2020

The 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.

***, frak you!

14, Sep, 2020

The 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.

Worst case

3, Sep, 2020

A 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 ;)

locale dependent bug

27, Aug, 2020
gettext("")

In one language that function returned a random string.

shortsignedness

27, Aug, 2020
enum {
  THE = 0x8000
};

short val = THE;

if (THE == val) {
  /* nope */
}

safe API?

18, Aug, 2020
char *strncat(char *dst, char const *src, size_t num );

num - Maximum number of characters to be appended.

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?

Language (d)evolution

31, Jul, 2020

A 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?

When insertion sort is faster than qsort()?

27, May, 2020

So, lets measure:
iq.png But, I little tricked it. Be aware that it is only for ints. Not so much for strings:
iqs.png