#CPlusCPlus

2025-05-07

Rust does seem to have a lot of nice features. My biggest blocker for me going to Rust from C++ is that C++ has much better support for generic programming. And now that Concepts have landed, I'm not aware of any language that can compete in this area.

#rust #cpp #CPlusCplus #programming #compsci

Revista Occam's RazorRevistaOccamsRazor@masto.es
2025-04-25

Alguna vez te has preguntado como implementa los objetos el compilador de #C++ ? En este artículo os lo contamos a través de un curioso ejemplo

#programming #programacion #POO #CPlusCplus #ASM #C #fenomenoextranos #ROOR09

ibolcode.net/roor/2025-04-el-a

Shafik Yaghmourshafik@hachyderm.io
2025-04-08

What is the stock markets least favorite qualifier?
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
volatile 🥁

#CPlusCplus

Shafik Yaghmourshafik@hachyderm.io
2025-03-20

What kind of member functions don't bankers like?
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Defaulted ones 🥁

#CPlusCplus

Shafik Yaghmourshafik@hachyderm.io
2025-02-11

What You Need to Know when Optimizations Changes the Behavior of Your C++ 😱: shafik.github.io/c++/undefined

#CPlusCplus

It is often said by those who have been around C++ for a long time that:

“If the behavior of your program changes when using some level of optimization, then it is likely you have undefined behavior”.

This is not to say that there are no compiler bugs they do happen but chances are what you are seeing is likely not a compiler bug. While this is all true, there is a catch here. If someone suspects they may have undefined behavior, how do they find it? It feels like one of those punchlines to a joke, “Sure everything you told me is true but I am no better off than I was before I asked!”.

It is a great question and sadly, I don’t have one simple answer to catch them all. What I can do is give you a set of approaches that for a good number of cases should help you prove or get you closer to eliminating the possibility of undefined behaviors being the cause of your problem.
2025-01-19

My little daisyseed synth project is currently stalling on the whole "C++ is just the WORST language" problem.

There's a class in the DaisySP library which is *almost* what I want. So I should be able to just subclass it and work from there, right?

Well, no, because none of the functions that I want to override are declared "virtual", so I'd have to edit and re-build the library.

I'm sure this is all in the service of runtime efficiency, at some level. But, you know - it's a 480MHz ARM processor. I think a little indirection wouldn't be a huge deal.

I will just write the whole thing from scratch, all 100 lines or so of it. But it's *IRRITATING*, you know?

#daisyseed #CPlusCplus #embedded #synthdiy #synth

Oriel Jutty :hhHHHAAAH:barubary@infosec.exchange
2025-01-07

"The only way to learn a new programming language is by writing programs in it."
– Dennis Ritchie

Therefore C++ is not a programming language.

#CPlusCplus

Shafik Yaghmourshafik@hachyderm.io
2024-12-28

Books titles ostensibly not about C++ but could be

#CPlusCplus

Book with the title POD which is plain old data type in C++
Alfonso Urdanetaaeu@hachyderm.io
2024-12-20

As I was going through and working on some puzzles I noticed that an inordinately large amount of the problems on leetcode all have Permutations at their core.

After a little bit of research, it turns out that I had been generating permutations suboptimally this entire time.

The most efficient implementation is something called Heap's Algorithm, which I have to admit I had never heard of. So, here it is.

github.com/aeu/legible-algorit

#programming #cpp #CPlusCplus #algorithms

2024-12-17

ArkScript December 2024 update is here!

lexp.lt/posts/arkscript_update

Quite a long read because there was a lot of changes. I’m now thinking I should maybe do a 2024 article wrap?
Or people can just read lexp.lt/categories/arkscript/ if they want to see everything 🤔

#compiler #cpp #cpluscplus #opensource #pldev #ArkScript

Shafik Yaghmourshafik@hachyderm.io
2024-12-06

Cursed code

Using emoji with static_assert

See the output from various compilers: godbolt.org/z/GTKn99cKW

#CPlusCplus

int main() {
   static_assert( false, "🐔🧟‍♂️🌽💩") ;   
}Output from various compilers:

clang:

<source>:2:19: error: static assertion failed: 🐔🧟‍♂️🌽💩
    2 |    static_assert( false, "🐔🧟<U+200D>♂️🌽💩") ;   
      |                   ^~~~~
1 error generated.
Compiler returned: 1

gcc:

<source>: In function 'int main()':
<source>:2:19: error: static assertion failed: 🐔🧟‍♂️🌽💩
    2 |    static_assert( false, "🐔🧟‍♂️🌽💩") ;
      |                   ^~~~~
Compiler returned: 1

msvc:

example.cpp
<source>(2): error C2338: ???????????
Compiler returned: 2

edg:

"<source>", line 2: error: static assertion failed with "?????????????????????????"
     static_assert( false, "🐔🧟‍♂️🌽💩") ;   
     ^

1 error detected in the compilation of "<source>".
Compiler returned: 2
Shafik Yaghmourshafik@hachyderm.io
2024-10-17

New Blog post

"Triaging clang C++ frontend bugs": shafik.github.io/c++/llvm/2024

Everything you wanted to know about triaging clang frontend bugs but were afraid to ask.

#CPlusCplus
#llvm

The clang frontend usually gets several new bugs a day and it is important to our users to at least do and initial assessment of each bug in a timely manner. Bugs are going to fall into one of many categories (not exhaustive list):

It is not a bug, this is rare but it does happen and often we need to walk the user through why that is the case and possibly any workarounds to address their issue.
Undefined behavior, this is kind of category of “not a bug” but sometimes the compilers behavior around UB can be unintuitive or downright not desirable. Often there are good workarounds but sometimes not.
Regressions, we have regular release of clang and sometimes we break things that worked in the previous release. These are important to flag early and fix.
Crashes, unfortunately the complier can crash usually giving a dreaded backtrace but sadly sometimes not.
Different compilers obtain different behavior. These bugs vary a lot. Sometimes it is just a bug in clang or another implementation. Sometimes the C++ standard is not clear or it has a wording bug.
We have a diagnostic that has a false positive or false negative.
We don’t support an extension the same way another compiler does. We support many GNU and MSVC extensions and sometimes our behaviors don’t line up.
Futurist :vivaldi_red:markoo@vivaldi.net
2024-10-04

By introducing the Rust language in Android development and following the best practices that this language provides in terms of memory-safety, Google was able to reduce memory-safety issues, which accounted for 76 per cent of Android vulnerabilities in 2019 to the current 24 per cent.

#Rust #rustlang #Android #google #CPlusCplus #kotlin #OpenSource #vulnerability #MemorySafety #Security

security.googleblog.com/2024/0

Shafik Yaghmourshafik@hachyderm.io
2024-09-07

TIL (well ok, recently at least) variadic unions are a thing

template <size_t I, typename T, typename... Types>
union v<I,T,Types...> {
T head ;
v<I+1, Types...> tail ;
} ;

More complete version here: godbolt.org/z/9zPxEjrYd

#CPlusCplus

#include <cstdio>
template ‹size_t index, typename... Types>
union var ;
template ‹size_t index>
 union var<index> t ;
 template < size t index, typename T, typename. union var<index, T, Types...> {
static constexpr size_t index_ = index ;
T head ;
var<index+1, Types...> tail ;
} ;void foo() {
    var<0, int, double, char> v ;

    
    v.head = 1 ;
    printf( "%d\n", v.head ) ;
    
    v.tail.head = 2.0 ;
    printf( "%f\n", v.tail.head) ;

    v.tail.tail.head = 'A' ;
    printf( "%d\n", v.tail.tail.head ) ;
 }
Shafik Yaghmourshafik@hachyderm.io
2024-07-18

Cursed C++ of the day

#CPlusCplus

godbolt sceen shot

Code:

template <>
template <>
template <>
template <>
template <>
template <typename T>
void f(T){}

Output:

<source>:1:1: warning: extraneous template parameter list in template specialization
    1 | template <>
      | ^~~~~~~~~~~
    2 | template <>
      | ~~~~~~~~~~~
    3 | template <>
      | ~~~~~~~~~~~
    4 | template <>
      | ~~~~~~~~~~~
    5 | template <>
      | ~~~~~~~~~~~
1 warning generated.
Compiler returned: 0
Shafik Yaghmourshafik@hachyderm.io
2024-07-04

Some early design influences of C++

From "The Design and Evolution of C++"

#CPlusCplus

they specify constraints on a solution.
At the time I was there, the Cambridge Computing Laboratory was headed by Maurice Wilkes. I received my main technical guidance from my supervisor, David Wheeler, and from Roger Needham. My background in operating systems and my interest in modularization and communication had permanent effects on C++. The C++ model of protection, for example, is based on the notion of granting and transferring access rights; the distinction between initialization and assignment has its root in thoughts about transferring capabilities; C++'s notion of const is derived from hardware read/write access protection mechanisms; and the design of C++'s exception handling mechanism was influenced by work on fault-tolerant systems done by Brian Randell's group in Newcastle during the seventies.
Shafik Yaghmourshafik@hachyderm.io
2024-07-01

From "The Design and Evolution of C++" and on page 159 and 160

Alternative tokens were born out of character set incompatibilities.

#CPlusCplus

The ASCII special characters [, ], {, }, |, and \ occupy character set positions designated by ISO. In most European national ISO-646 character sets these positions are occupied by letters not found in the English alpha characeter set.
For example, the Danition ambunce et uses these value ogline abra.
e d. and D. No programmer it of cap can to white i brithe voi
then. This eares Dandle full & bit character he unpleasant choice of acting tom. pret seme to ative language, or note set, uch ae 150.859 ng ang
hot ovel of their nace the same aler not us This. Speakers of French, of usin, Somith talian, etc. Spaceil sanco mereties. This has ben a notable ban Eera tie
se i in Europe, especially is commercial settings (such as banking) where to tie o 7. it national character sets is pervasive in many countries.
For example, consider this innocent-looking ANSI C and C++ program:Naturally, the real solution to this problem is for C and C++ programmers to buy equipment that supports both the  native languages sets for character needed by c as well. Unfortunately, this a appears to be infeasible for some and the introduction of new equipment can be a very slow process. To help programmers stuck with such equipment and thereby help C++, the c++ standards committee decided to provide a more readable alternative.
The following keywords and digraphs are provided as equivalents to operators containing national characters:
Shafik Yaghmourshafik@hachyderm.io
2024-07-01

Just a reminder this is valid C++: godbolt.org/z/5nrEG4zda

#CPlusCplus

Godbolt screen shot.

Code:

int and x = 1;

struct A {
   compl A(); 
} a;

Result:

Compiler returned: 0

Client Info

Server: https://mastodon.social
Version: 2025.04
Repository: https://github.com/cyevgeniy/lmst