Re: Top 10 most common hard skills listed on resumes...

Liste des GroupesRevenir à cl c  
Sujet : Re: Top 10 most common hard skills listed on resumes...
De : antispam (at) *nospam* fricas.org (Waldek Hebisch)
Groupes : comp.lang.c
Date : 09. Sep 2024, 02:29:01
Autres entêtes
Organisation : To protect and to server
Message-ID : <vblfgb$2dkij$1@paganini.bofh.team>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
User-Agent : tin/2.6.2-20221225 ("Pittyvaich") (Linux/6.1.0-9-amd64 (x86_64))
Bart <bc@freeuk.com> wrote:
On 08/09/2024 19:13, Waldek Hebisch wrote:
Bart <bc@freeuk.com> wrote:
 
Like being able define anonymous structs always anywhere, or allowing
multiple declarations of the same module-level variables and functions.
 
Look at this C code:
 
void
do_bgi_add(unsigned int * dst, int xlen, unsigned int * xp,
      int ylen, unsigned int * yp) {
     if (ylen < xlen) {
         int tmp = xlen;
         xlen = ylen;
         ylen = tmp;
         unsigned int * tmpp = xp;
         xp = yp;
         yp = tmpp;
     }
     unsigned int xext = (unsigned int)(((int)(xp[xlen - 1])) >> 31);
     unsigned int yext = (unsigned int)(((int)(yp[ylen - 1])) >> 31);
     unsigned int c = 0;
     int i = 0;
     while(i < xlen) {
         unsigned long long pp = (unsigned long long)(xp[i])
                               + (unsigned long long)(yp[i])
                               + (unsigned long long)c;
         dst[i] = pp;
         c = (pp >> (32ULL));
         i++;
     }
     while(i < ylen) {
         unsigned long long pp = (unsigned long long)xext
                               + (unsigned long long)(yp[i])
                               + (unsigned long long)c;
         dst[i] = pp;
         c = (pp >> (32ULL));
         i++;
     }
     {
         unsigned long long pp = (unsigned long long)xext
                               + (unsigned long long)yext
                               + (unsigned long long)c;
         dst[i] = pp;
     }
}
 
 
I claim that is is better than what could be done in early Pascal.
Temporary variables are declared exactly in scopes where they are
needed, I reuse the same name for 'pp' but scoping makes clear
that different 'pp' are different variables.  All variables
are initialised at declaration time with sensible values.  Only
parameters, 'i' and 'c' are common to various stages, they have
to.  Note that 'xext' and 'yext' are declared at point where I
can compute initial value.  Also note that among ordinary
variables only 'i' and 'c' are reassigned (I need to swap parameters
to simplify logic and 'dst' array entries are assigned as part of
function contract).  Fact that variables are not reassigned could
be made clearer by declaring them as 'const'.
 
I had a problem with this code because it was so verbose. The first
thing I did was to define aliases u64 and u32 for those long types:
 
 typedef unsigned long long u64;
 typedef unsigned long u32;

This code runs in 33 bit i386, 32 bit ARM and 64 bit x86-64, in
all cases under Linux.  As Keith noticed, most popular of those
has 64-bit long.  So your definition would break it.  You need

typedef unsigned int u32;

Then I removed some casts that I thought were not necessary.

I want to be warned about mixing signed and unsigend when
I do not intend so.  Casts make clear to compiler (and reader)
that I really want this.

The first
result looks like this:
 
---------------------------
void do_bgi_add(u32 * dst, int xlen, u32 * xp, int ylen, u32 * yp) {
    u32 xext, yext, c;
    u64 pp;
    int i;
 
    if (ylen < xlen) {
        int tmp = xlen;
        xlen = ylen;
        ylen = tmp;
        u32 * tmpp = xp;
        xp = yp;
        yp = tmpp;
    }
 
    xext = ((int)(xp[xlen - 1])) >> 31;
    yext = ((int)(yp[ylen - 1])) >> 31;
 
    c = 0;
    i = 0;
    while(i < xlen) {
        pp = (u64)(xp[i]) + (u64)yp[i] + c;
        dst[i] = pp;
        c = pp >> 32;
        i++;
    }
 
   while(i < ylen) {
        pp = (u64)xext  + (u64)yp[i]  + c;
        dst[i] = pp;
        c = pp >> 32;
        i++;
    }
    pp = (u64)xext + (u64)yext + c;
    dst[i] = pp;
}
---------------------------
 
Things actually fit onto one line! It's easier now to grasp what's going
on. There are still quite a few casts; it would be better if xext/yext/c
were all u64 type instead of u32.

No.  It is essential for efficiency to have 32-bit types.  On 32-bit
machines doing otherwise would add useless instructions to object
code.  More precisly, really stupid compiler will generate useless
intructions even with my declarations, really smart one will
notice that variables fit in 32-bits and optimize accordingly.
But at least some gcc versions needed such declarations.  Note
also that my version makes clear that there there is
symmetry (everything should be added using 64-bit precision),
you depend on promotion rules which creates visual asymetry
are requires reasoning to realize that meaning is symetric.

pp seems to used for the same purpose throughout, so I can't see the
point in declaring three separate versions of the same thing.

My version can be checked for correctenss in one resonably fast
pass other source.  Your changes require multiple passes or much
slower single pass (because with single pass you need to keep
more info in your head compared to my version).

Your version obscures important fact that there is truncation
is assigment

    dst[i] = pp;

In my version type of pp is clearly visible, together with casts
this gives string hint what is happening: this is 32-bit addition
producing carry in 'c'.  And this is version of code intended for
32-bit machines, so everthing can be done using 32-bit instructions
(and on 32-bit machine there is no need for real shift).  Your
remark above indicates that you missed this, but I think that
this is much easier to infer from my version than from your
changed one.

Another thing, I gave this example because most my functions
are very short.  This one was longer and in longer function
benfits of keeping variable local are bigger.  And that
function happend to have casts, but casts are actually
were a distraction to my main point.

Also, note that I plan to change this code so that it uses
64-bit arithmetic on 64-bit machines.  Then I will have
something like 'host_word' (unsigned 32-bit on 32-bit
machine and 64-bit on 64-bit machine), 'signed_host_word'
(the same number of bit, but signed) and 'double_host_word'
(128-bit on 64-bit machine, 64-bit on 32-bit machine).
I wait with this change because ATM there is still piece of
code elsewere which can not handle 64-bit parts.  So, while
your u64 and u32 change is acceptable for current version
it would be misleading about future intent.

Note, I did not intend to post a trap for you, but in your
egerness to shorten the code you removed important information.
And while this code is unlikely to change much (basically
upgrade to 64-bit version on 64-bit machines in the only likely
change), normally code evolves and your version is harder
to change.

More generally, my aim is to make code obviously correct
(I not saying that I was fully successful in this case).
I consider your version worse, because with your version
reader has more work checking correctness (even taking into
account that you lowered number of lines).

Anyway, I illustrated to you how I use declarations in the middle
of a function.  There is nothing chaotic about this, type is
declared when variable first time gets its value.  And in most
cases variable scope is tiny.  AFAICS neither early Pascal nor
your language allows me to write programs in this way.  And if
you do not see benefits, well, this your loss.

--
                              Waldek Hebisch

Date Sujet#  Auteur
24 Aug 24 * Top 10 most common hard skills listed on resumes...406John Forkosh
24 Aug 24 +* Re: Top 10 most common hard skills listed on resumes...3Lawrence D'Oliveiro
24 Aug 24 i`* Re: Top 10 most common hard skills listed on resumes...2Keith Thompson
24 Aug 24 i `- Re: Top 10 most common hard skills listed on resumes...1Lawrence D'Oliveiro
24 Aug 24 +* Re: Top 10 most common hard skills listed on resumes...8David Brown
25 Aug 24 i`* Re: Top 10 most common hard skills listed on resumes...7John Forkosh
25 Aug 24 i +- Re: Top 10 most common hard skills listed on resumes...1Michael S
25 Aug 24 i +* Re: Top 10 most common hard skills listed on resumes...3James Kuyper
25 Aug 24 i i+- Re: Top 10 most common hard skills listed on resumes...1Michael S
26 Aug 24 i i`- Re: Top 10 most common hard skills listed on resumes...1Vir Campestris
25 Aug 24 i `* Re: Top 10 most common hard skills listed on resumes...2David Brown
25 Aug 24 i  `- Re: Top 10 most common hard skills listed on resumes...1Chris M. Thomasson
24 Aug 24 `* Re: Top 10 most common hard skills listed on resumes...394Bonita Montero
24 Aug 24  `* Re: Top 10 most common hard skills listed on resumes...393Bart
24 Aug 24   +* Re: Top 10 most common hard skills listed on resumes...2Vir Campestris
24 Aug 24   i`- Re: Top 10 most common hard skills listed on resumes...1Thiago Adams
25 Aug 24   +* Re: Top 10 most common hard skills listed on resumes...359John Forkosh
25 Aug 24   i+* Re: Top 10 most common hard skills listed on resumes...356James Kuyper
25 Aug 24   ii+* Re: Top 10 most common hard skills listed on resumes...271fir
25 Aug 24   iii+* Re: Top 10 most common hard skills listed on resumes...269Bart
25 Aug 24   iiii+* Re: Top 10 most common hard skills listed on resumes...2Michael S
25 Aug 24   iiiii`- Re: Top 10 most common hard skills listed on resumes...1Bart
25 Aug 24   iiii+* Re: Top 10 most common hard skills listed on resumes...7tTh
25 Aug 24   iiiii`* Re: Top 10 most common hard skills listed on resumes...6Bart
28 Aug 24   iiiii `* Re: Top 10 most common hard skills listed on resumes...5Michael S
28 Aug 24   iiiii  +- Re: Top 10 most common hard skills listed on resumes...1Bonita Montero
28 Aug 24   iiiii  +* Re: Top 10 most common hard skills listed on resumes...2Bart
29 Aug 24   iiiii  i`- Re: Top 10 most common hard skills listed on resumes...1David Brown
30 Aug 24   iiiii  `- Re: Top 10 most common hard skills listed on resumes...1Lawrence D'Oliveiro
26 Aug 24   iiii`* Re: Top 10 most common hard skills listed on resumes...259Lawrence D'Oliveiro
26 Aug 24   iiii `* Re: Top 10 most common hard skills listed on resumes...258Bart
26 Aug 24   iiii  +* Re: Top 10 most common hard skills listed on resumes...256Ben Bacarisse
26 Aug 24   iiii  i+* Re: Top 10 most common hard skills listed on resumes...244Bart
26 Aug 24   iiii  ii+* Re: Top 10 most common hard skills listed on resumes...2Keith Thompson
26 Aug 24   iiii  iii`- Re: Top 10 most common hard skills listed on resumes...1Tim Rentsch
28 Aug 24   iiii  ii`* Re: Top 10 most common hard skills listed on resumes...241Ben Bacarisse
28 Aug 24   iiii  ii `* Re: Top 10 most common hard skills listed on resumes...240Bart
28 Aug 24   iiii  ii  `* Re: Top 10 most common hard skills listed on resumes...239Ben Bacarisse
28 Aug 24   iiii  ii   `* Re: Top 10 most common hard skills listed on resumes...238Bart
29 Aug 24   iiii  ii    +* Re: Top 10 most common hard skills listed on resumes...236Ben Bacarisse
29 Aug 24   iiii  ii    i`* Re: Top 10 most common hard skills listed on resumes...235Bart
29 Aug 24   iiii  ii    i `* Re: Top 10 most common hard skills listed on resumes...234Ben Bacarisse
29 Aug 24   iiii  ii    i  `* Re: Top 10 most common hard skills listed on resumes...233Bart
29 Aug 24   iiii  ii    i   `* Re: Top 10 most common hard skills listed on resumes...232Ben Bacarisse
29 Aug 24   iiii  ii    i    `* Re: Top 10 most common hard skills listed on resumes...231Kaz Kylheku
29 Aug 24   iiii  ii    i     `* Re: Top 10 most common hard skills listed on resumes...230Ben Bacarisse
29 Aug 24   iiii  ii    i      `* Re: Top 10 most common hard skills listed on resumes...229Kaz Kylheku
29 Aug 24   iiii  ii    i       +* Re: Top 10 most common hard skills listed on resumes...227Ben Bacarisse
29 Aug 24   iiii  ii    i       i+* Re: Top 10 most common hard skills listed on resumes...218Bart
29 Aug 24   iiii  ii    i       ii+* Re: Top 10 most common hard skills listed on resumes...5Keith Thompson
29 Aug 24   iiii  ii    i       iii`* Re: Top 10 most common hard skills listed on resumes...4Bart
30 Aug 24   iiii  ii    i       iii `* Re: Top 10 most common hard skills listed on resumes...3Keith Thompson
30 Aug 24   iiii  ii    i       iii  `* Re: Top 10 most common hard skills listed on resumes...2Bart
30 Aug 24   iiii  ii    i       iii   `- Re: Top 10 most common hard skills listed on resumes...1Keith Thompson
30 Aug 24   iiii  ii    i       ii+* Re: Top 10 most common hard skills listed on resumes...56Ben Bacarisse
30 Aug 24   iiii  ii    i       iii`* Re: Top 10 most common hard skills listed on resumes...55Kaz Kylheku
30 Aug 24   iiii  ii    i       iii +* Re: Top 10 most common hard skills listed on resumes...42Tim Rentsch
30 Aug 24   iiii  ii    i       iii i`* Re: Top 10 most common hard skills listed on resumes...41Keith Thompson
31 Aug 24   iiii  ii    i       iii i +* Re: Top 10 most common hard skills listed on resumes...10Kaz Kylheku
31 Aug 24   iiii  ii    i       iii i i+* Re: Top 10 most common hard skills listed on resumes...2James Kuyper
31 Aug 24   iiii  ii    i       iii i ii`- Re: Top 10 most common hard skills listed on resumes...1Keith Thompson
1 Sep 24   iiii  ii    i       iii i i`* Re: Top 10 most common hard skills listed on resumes...7Tim Rentsch
1 Sep 24   iiii  ii    i       iii i i `* Re: Top 10 most common hard skills listed on resumes...6Keith Thompson
1 Sep 24   iiii  ii    i       iii i i  +* Re: Top 10 most common hard skills listed on resumes...4Kaz Kylheku
1 Sep 24   iiii  ii    i       iii i i  i+* Re: Top 10 most common hard skills listed on resumes...2James Kuyper
1 Sep 24   iiii  ii    i       iii i i  ii`- Re: Top 10 most common hard skills listed on resumes...1Tim Rentsch
1 Sep 24   iiii  ii    i       iii i i  i`- Re: Top 10 most common hard skills listed on resumes...1Tim Rentsch
1 Sep 24   iiii  ii    i       iii i i  `- Re: Top 10 most common hard skills listed on resumes...1Tim Rentsch
31 Aug 24   iiii  ii    i       iii i `* Re: Top 10 most common hard skills listed on resumes...30Bart
31 Aug 24   iiii  ii    i       iii i  +- Re: Top 10 most common hard skills listed on resumes...1Kaz Kylheku
31 Aug 24   iiii  ii    i       iii i  +- Re: Top 10 most common hard skills listed on resumes...1James Kuyper
1 Sep 24   iiii  ii    i       iii i  +* Re: Top 10 most common hard skills listed on resumes...3Tim Rentsch
1 Sep 24   iiii  ii    i       iii i  i`* Re: Top 10 most common hard skills listed on resumes...2Bart
1 Sep 24   iiii  ii    i       iii i  i `- Re: Top 10 most common hard skills listed on resumes...1Tim Rentsch
1 Sep 24   iiii  ii    i       iii i  `* Re: Top 10 most common hard skills listed on resumes...24Keith Thompson
1 Sep 24   iiii  ii    i       iii i   `* Re: Top 10 most common hard skills listed on resumes...23Bart
1 Sep 24   iiii  ii    i       iii i    +* Re: Top 10 most common hard skills listed on resumes...3Keith Thompson
1 Sep 24   iiii  ii    i       iii i    i`* Re: Top 10 most common hard skills listed on resumes...2Tim Rentsch
1 Sep 24   iiii  ii    i       iii i    i `- Re: Top 10 most common hard skills listed on resumes...1Keith Thompson
1 Sep 24   iiii  ii    i       iii i    +* Re: Top 10 most common hard skills listed on resumes...17Kaz Kylheku
1 Sep 24   iiii  ii    i       iii i    i`* Re: Top 10 most common hard skills listed on resumes...16Tim Rentsch
8 Sep 24   iiii  ii    i       iii i    i `* Re: Top 10 most common hard skills listed on resumes...15Janis Papanagnou
8 Sep 24   iiii  ii    i       iii i    i  +* Re: Top 10 most common hard skills listed on resumes...10James Kuyper
8 Sep 24   iiii  ii    i       iii i    i  i`* Re: Top 10 most common hard skills listed on resumes...9Janis Papanagnou
9 Sep 24   iiii  ii    i       iii i    i  i +* Re: Top 10 most common hard skills listed on resumes...5David Brown
9 Sep 24   iiii  ii    i       iii i    i  i i`* Re: Top 10 most common hard skills listed on resumes...4James Kuyper
9 Sep 24   iiii  ii    i       iii i    i  i i `* Re: Top 10 most common hard skills listed on resumes...3David Brown
9 Sep 24   iiii  ii    i       iii i    i  i i  `* Re: Top 10 most common hard skills listed on resumes...2James Kuyper
17 Sep14:46   iiii  ii    i       iii i    i  i i   `- Re: Top 10 most common hard skills listed on resumes...1Tim Rentsch
9 Sep 24   iiii  ii    i       iii i    i  i `* Re: Top 10 most common hard skills listed on resumes...3Kaz Kylheku
9 Sep 24   iiii  ii    i       iii i    i  i  +- Re: Top 10 most common hard skills listed on resumes...1James Kuyper
17 Sep14:56   iiii  ii    i       iii i    i  i  `- Re: Top 10 most common hard skills listed on resumes...1Tim Rentsch
17 Sep15:57   iiii  ii    i       iii i    i  `* Re: Top 10 most common hard skills listed on resumes...4Tim Rentsch
17 Sep19:02   iiii  ii    i       iii i    i   `* Re: Top 10 most common hard skills listed on resumes...3Janis Papanagnou
18 Sep01:26   iiii  ii    i       iii i    i    `* Re: Top 10 most common hard skills listed on resumes...2Tim Rentsch
18 Sep17:28   iiii  ii    i       iii i    i     `- Re: Top 10 most common hard skills listed on resumes...1antispam
1 Sep 24   iiii  ii    i       iii i    +- Re: Top 10 most common hard skills listed on resumes...1James Kuyper
7 Sep 24   iiii  ii    i       iii i    `- Re: Top 10 most common hard skills listed on resumes...1Waldek Hebisch
2 Sep 24   iiii  ii    i       iii `* Re: Top 10 most common hard skills listed on resumes...12Ben Bacarisse
2 Sep 24   iiii  ii    i       iii  `* Re: Top 10 most common hard skills listed on resumes...11Bart
2 Sep 24   iiii  ii    i       iii   `* Re: Top 10 most common hard skills listed on resumes...10Ben Bacarisse
30 Aug 24   iiii  ii    i       ii+- Re: Top 10 most common hard skills listed on resumes...1Tim Rentsch
5 Sep 24   iiii  ii    i       ii`* Re: Top 10 most common hard skills listed on resumes...155Waldek Hebisch
29 Aug 24   iiii  ii    i       i`* Re: Top 10 most common hard skills listed on resumes...8James Kuyper
30 Aug 24   iiii  ii    i       `- Re: Top 10 most common hard skills listed on resumes...1Tim Rentsch
29 Aug 24   iiii  ii    `- Re: Top 10 most common hard skills listed on resumes...1Michael S
26 Aug 24   iiii  i`* Re: Top 10 most common hard skills listed on resumes...11Keith Thompson
26 Aug 24   iiii  `- Re: Top 10 most common hard skills listed on resumes...1Lawrence D'Oliveiro
26 Aug 24   iii`- Re: Top 10 most common hard skills listed on resumes...1Lawrence D'Oliveiro
25 Aug 24   ii+* Re: Top 10 most common hard skills listed on resumes...83Bonita Montero
25 Aug 24   ii`- Re: Top 10 most common hard skills listed on resumes...1Janis Papanagnou
25 Aug 24   i+- Re: Top 10 most common hard skills listed on resumes...1Bonita Montero
25 Aug 24   i`- Re: Top 10 most common hard skills listed on resumes...1David Brown
25 Aug 24   `* Re: Top 10 most common hard skills listed on resumes...31Janis Papanagnou

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal