The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,861 other subscribers

Archive for the ‘C’ Category

LD_PRELOAD: preload a Linux library, for instance to obtain more information on a segmentation fault

Posted by jpluimers on 2020/06/11

Not being a proficient Linux programmer, I wondered what other means than learning gdb intrinsics I had to get more information about a segmentation fault.

A while back, pip list 2> /dev/null would cause a segmentation fault on my system (see [WayBack] Bug 1084812 – [aarch64] IPv4 DNS leading to segfaults).

It turns out that LD_PRELOAD was my friend (like TERM=xterm was a friend before):

LD_PRELOAD=libSegFault.so pip list 2> /dev/null

It indicated that the problem was in libc, which on opensuse is implemented by glibc.

This meant that the originally diagnosed problem was already accurately describing the symptoms.

Searching for glibc libSegFault.so didn’t reveal many useful links, so I’ve included the one making most sense to me here:

The cool thing: most of the links above come from [WayBack] segmentation fault – Can you get any program in Linux to print a stack trace if it segfaults? – Server Fault which I found when searching for linux find segmentation fault stack trace

That link explains both the LD_PRELOAD steps and gdb steps (:

An alternative is to use gdb directly: [WayBack] command line arguments – How do I run a program with commandline args using gdb within a bash script? – Stack Overflow:

gdb -ex=run --args pip list

--jeroen

Posted in *nix, C, Development, gcc, Linux, Power User, Software Development | Leave a Comment »

Why Is SQLite Coded In C

Posted by jpluimers on 2020/06/04

Old, but still an interesting read: [WayBack] Why Is SQLite Coded In C and [WayBack] Appropriate Uses For SQLite.

TL;DR: SQLite – mainly competing with fopen has few dependencies and uses C in a boring way. I think that’s good.

Via: [WayBack] Why Is SQLite Coded In C – ThisIsWhyICode – Google+

–jeroen

Posted in C, Database Development, Development, Software Development, SQLite | Leave a Comment »

The Invention of C++ – Nice bit of net lore

Posted by jpluimers on 2020/04/30

This is a nice joke: [WayBackThe Invention of C++ – Nice bit of net lore.

But the actual interview linked from the article is quite nice: [WayBack: The Real Stroustrup Interview]

By the name, I found the actual (hopefully still online when this gets out of the blog post queue) version at [WayBack] Stroustrup: Interviews under [WayBackstroustrup.com/ieee_interview.pdf

–jeroen

Via: [WayBack] The invention of C++ – Thomas Mueller (dummzeuch) – Google+

Posted in C, C++, Development, History, Software Development | Leave a Comment »

Flexible and Economical UTF-8 Decoder

Posted by jpluimers on 2019/12/25

For my link archive: [Archive.is] Flexible and Economical UTF-8 Decoder.

Be sure to read the whole article there as the explanation of the initial algorithm is important and final algorithm is towards the end.

The foundation is a state machine combined with a lookup table to find the initial state and proceed to subsequent states.

Related (and reminder to check what David did):

–jeroen

Read the rest of this entry »

Posted in C, C++, Delphi, Development, Software Development | 1 Comment »

Teach Yourself C++ in 21 days…

Posted by jpluimers on 2019/10/10

[WayBackAbtruse Goose: Teach Yourself C++ in 21 days…

Via: [WayBack] “How to learn programming in 21 Days” – CodeProject – Google+

Read the rest of this entry »

Posted in C, C++, Development, Fun, Software Development | Leave a Comment »

This is why I try to avoid C, as it means handling code from others that shoot in foots

Posted by jpluimers on 2019/08/07

Via [WayBack] Hello, I’m translating some C code to Delphi and found something that surprise me…is it logical that this code compiles ? – Paul TOTH – Google+

Maintaining C means you need to be aware that other people like shooting at foots (yes, that is a grammar error by intent):

#include 
#include 

void test();

void test2() {
  test();
}

void test(char *msg) {
  printf("test called '%s' (%d)\n", msg, strlen(msg));
}

void main() {
  test2();
}

Of course!? with gcc under Ubuntu the result is

test called 'test' (4)

Code is derived from [Archive.isgit hub user fogleman project Craft search db_worker_start

The thread has some nice comments.

–jeroen

Posted in C, Development, Software Development | Leave a Comment »

Design Patterns & Refactoring

Posted by jpluimers on 2019/07/16

Design Patterns and Refactoring articles and guides. Design Patterns video tutorials for newbies. Simple descriptions and full source code examples in Java, C++, C#, PHP and Delphi.

Source: [WayBackDesign Patterns & Refactoring.

And indeed a lot of examples in Delphi too; few sites have that: Delphi site:sourcemaking.com.

–jeroen

Via: [WayBack] I stumbled upon this yesterday, very informative, accessible and also with Delphi examples – among other languages. – Steffen Nyeland – Google+

Posted in .NET, C, C#, C++, Delphi, Design Patterns, Development, Java, Java Platform, PHP, Scripting, Software Development | Leave a Comment »

Calculating CRC with a tiny (32 entry) lookup-table | Lentz family blog

Posted by jpluimers on 2019/06/27

For my archive:

I happened to notice that the Arduino OneWire library uses a 256 entry lookup table for its CRC calculations.

I did some research on this topic in 1992-1993, while working on Bulletin Board Systems, FidoNet code and file transfer protocols.

These days memory is not at a premium on most computers, however on Arduino and microcontroller environments it definitely is, and I happen to know that table-lookup CRC can be done using two 16-entry tables!

So I’ve dug up my documentation and code from the time, and applied it to the CRC-8 calculation for the Maxim (Dallas Semiconductor) OneWire bus protocol.

I think this provides a neat trade-off between code size and speed.

License For any of the below code, apply the following license (2-clause “simplified” BSD license), which should suffice for any use. If you do require another license, just ask.

Source: [WayBack/Archive.isCalculating CRC with a tiny (32 entry) lookup-table | Lentz family blog

The example on the page is for the CRC-8 implementation used in the [WayBack] 1-Wire Communication protocol – Wikipedia.

The generator works for CRC-8, CRC-16 and CRC-32 polynomials and can be downloaded here:

–jeroen

 

Posted in Algorithms, C, Development, Software Development | Leave a Comment »

WouterVanNifterick/C-To-Delphi: C To Delphi converter

Posted by jpluimers on 2019/06/25

For my link archive: [WayBack] WouterVanNifterick/C-To-Delphi: C To Delphi converter

Via: [WayBack] Does anyone know of a C/C++ to Delphi converter? – Michael Riley – Google+

–jeroen

Posted in C, Delphi, Development, Software Development | 2 Comments »

How to Design Early Returns in C++ (Based on Procedural Programming) – Fluent C++

Posted by jpluimers on 2019/05/15

One more thing to take away from Procedural Programming: It’s Back? It Never Went Away – Kevlin Henney [ACCU 2018] – YouTube was explained in [WayBack] How to Design Early Returns in C++ (Based on Procedural Programming) – Fluent C++.

Though in C++, it applies to all programming languages that stem from a procedural background (Pascal, C#, Java, golang, to name just a few).

The article is about keeping an if/else-if/else tree, even when they can be removed becomes some of their bodies perform an early return, as

In C++, as well as in other languages, the return keyword has two responsibilities:

  • interrupting control flow,
  • yielding a value.

It basically comes down to this argument:

Essentially, the argument for Code is that you need to know less to understand the structure of the code.

Indeed, if we fold away the contents of the if statements, Code becomes this:

The structure of the code is very clear. There are 4 different paths based on the year, they’re independent from each other, and each path will determine the boolean result of the function (if it doesn’t throw an exception).

Now let’s see how Code looks like when we fold away the if statements:

And now we know much less. Do the if statements contain a return? Maybe.

Do they depend on each other? Potentially.

Do some of them rely on the last return false of the function? Can’t tell.

With Code you need to look inside of the if statement to understand the structure of the function. For that reason, Code requires a reader to know less to understand the structure. It gives away information more easily than Code .

–jeroen

via [WayBack] Kevlin Henney – Google+: How to Design Early Returns in C++ (Based on Procedural Programming) – Fluent C++

Posted in .NET, C, C#, C++, Conference Topics, Conferences, Delphi, Development, Event, Software Development | Leave a Comment »