Masthash

#CPP

Sean Murthy
3 hours ago

Related exercise from my C++ intro course asking students to implement isdigit(char) when characters are encoded in a fictional SASSY scheme.

Obvious to many here, this exercise is designed to help students realize that character encodings for digits, etc. don't have to be contiguous (unlike in ASCII).

PS: Students were asked to assign random codes to digit chars not in the table.

[Tweet redux, but reworded for this conversation]

#cpp #cplusplus #programming #education #learning #encoding

A slide from "CPP-1 Intro to C++" course. A slide title, 2 main bullet points, and a table with some characters and their encoding. Black text on white background.

Title: Exercise 7.14: Work with SASSY Characters

* Assume character data is encoded using SASSY scheme, parts of which are shown in the table below
* Write a function isdigit to test if a given character corresponds to a digit
  - Do not embed integral SASSY codes in the function

<a table with some character encodings with the following salient values>

Character: Code
0: 95
1: 32
2: 20
3: 11
4: 5
8: 122
9: 57
Somē
7 hours ago

Hoopla just completed Day 4 of #adventofcode2023. The hoops I had to jump through to get part 2 to work for loops in C++ is 😵 But here it is! https://github.com/somecho/aoc23.cpp/blob/main/src/day_4_2.cpp

#cpp #aoc #adventofcode #codingchallenge #functionalprogramming

CLion Blog
8 hours ago
Ramkumar Ramachandra
9 hours ago

The behavior of std::optional<T>::operator<= is surprising when the first argument is std::nullopt and second argument is a T. It returns true! In my opinion, all comparisons between std::nullopt and T should return false. Someone reported my assumption making one of my supposed NFC patches to #LLVM cause huge regressions on their benchmarks. #cpp

Sean Murthy
11 hours ago

Which of these two versions of the C++ function `isdigit(char)` would you recommend? Why, under what circumstances? 🤔 🧐

Assume architecture-agnostic programs but make (and state) reasonable assumptions.

Compare -O0 and -O3 in GCC and clang for x86-64 on Linux: https://sigcpp.godbolt.org/z/67734GbWP

💭 🔃 🙏

#cpp #cplusplus #programming #question #softwareEngineering #education #learning

Syntax-highlighted C++ code in a dark theme:

bool isdigit1(char c) {
    return (c >= '0' and c <= '9');
}

bool isdigit2(char c) {
    switch (c) {
    case '0': 
    case '1': 
    case '2': 
    //other cases 3 to 8 
    case '9': return true;
    default: return false;
    }
}
Šimon Tóth
11 hours ago

📆 Day 4 of Advent of Code 2023 is here. Today, we are analyzing the winning numbers on scratchcards.

🤔 How did you find today's problem? Was it easier for you than Day 3?

https://open.substack.com/pub/simontoth/p/daily-bite-of-c-advent-of-code-day-677?r=1g4l8a&utm_campaign=post&utm_medium=web

#cpp #cplusplus #coding #programming #dailybiteofcpp #adventofcode

Sonny Bonds
13 hours ago

One sad reality of helpers like these is that while an optimized build will generate identical code as a regular for loop in this case, an non-optimized build will have function calls to operators instead of a simple increment.

#cpp #programming

C & C++ Weekly
14 hours ago

C & C++ recap for week 48/2023

https://discu.eu/weekly/candcpp/2023/48/

#cpp #cprogramming #programming

Get RSS feeds and support this bot with the premium plan: https://discu.eu/premium

matt 🦕
15 hours ago

The #cpp 'runner' is here https://github.com/mattjbones/advent-of-code/blob/main/2023-cpp/src/runner.cpp / https://github.com/mattjbones/advent-of-code/blob/main/2023-cpp/src/runner.hpp

The #rust 'runner' is here https://github.com/mattjbones/advent-of-code/blob/main/2022-rusty/src/runner.rs

In the rust impl I separated the sample / input functions whereas in c++ I overloaded the `run_input_part_1` with a path or path and expected value.

For now the C++ isn't generic as most of the questions have only required numbers but I can see this moving to a `.tcc` file and be made generic.

Šimon Tóth
16 hours ago

I'm bringing you the second quick update for the template repository for Advent of Code.

If you bump the version of the docker image to 20231203 (in .devcontainer), you will get pretty-printing for GDB.

This also applies to the VSCode UI, so VSCode will no longer show the internals of data structures.

I have also added a short section about debugging to the original article:

https://open.substack.com/pub/simontoth/p/daily-bite-of-c-advent-of-code-2023?r=1g4l8a&utm_campaign=post&utm_medium=web

#cpp #cplusplus #coding #programming #dailybiteofcpp #adventofcode

Fell
17 hours ago

I just found a piece of old code where I encoded some information into an 8-bit bitfield just to decode it again 3 lines later.

I am certainly wiser now.

#programming #cpp #cplusplus #gamedev #gamedevelopment

Sonny Bonds
17 hours ago

C++ standard lib doesn't have any mechanism for range based for loops over just plain numbers, right? Something like python's range. Could look like:
for(int i : range(10)) ...

I know it's trivial to create, I'm just wondering if it's in there somewhere and I've missed it. It's happened before.

#cpp #programming

KDAB
18 hours ago

In November's newsletter, we bring you new videos as well as two new blogs, a new whitepaper, a manual for KDDockWidgets, a video interview: Why Rust?, two releases: CXX-Qt 0.6 & Slint 1.3, and some great news on KDAB Training. #QtDev #cpp #rustlang

🔗 https://www.kdab.com/https-www-kdab-com-2023-november-newsletter/

John
23 hours ago

I've completed "Scratchcards" - Day 4 - Advent of Code 2023 #AdventOfCode https://adventofcode.com/2023/day/4
#aoc2023 #cpp #AdventOfCode2023 #aoc23_cpp

Sean Murthy
1 day ago

I don't do Advent of Code, but browsing a few #cpp solutions to Day 1, Part 1, I fear I misunderstand the problem, or I just don't know enough C++. I'm not sure why the solution requires vectors, ranges, algorithms, etc. when it can be done in a single pass over the input stream.

Maybe others' solutions are that way due to Part 2? Na, more likely I'm doing something wrong. 😨

#Spoiler: Images reveal (uncommented) solution

https://adventofcode.com/2023/day/1

#aoc23 #aoc23_cpp #AdventOfCode #programming

Syntax-highlighted C++ code in a dark theme:

uintmax_t calibration_sum(std::istream& in)
{
    if (!in) //empty or erred stream
        return 0;

    char c;
    uintmax_t sum = 0;
    int8_t d1 = -1, d2 = -1;
    while (in.get(c)) {   //not EOF or error
        if (c == '\n') {  //end of line
            sum += calibration_value(d1, d2);
            d1 = -1;
            d2 = -1;
        }
        else if (auto v = value(c); v >= 0) {
            if (d1 < 0)
                d1 = v;
            else
                d2 = v;
        }
    }

    return sum + calibration_value(d1, d2);
}
Syntax-highlighted C++ code in a dark theme:

constexpr int8_t value(char c) {
    switch (c) {
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default: return -1;
    }
}

constexpr uint8_t calibration_value(int8_t d1, int8_t d2)
{
    if (d1 < 0)
        return 0;
    else if (d2 < 0)
        d2 = d1;

    return d1 * 10 + d2;
}
Šimon Tóth
1 day ago

📆 Day 3 of Advent of Code 2023 is here. Today, we are decoding an engine schematic.

😊 Part two today was perhaps the first interesting problem, so how did you do?

💡 Share your solutions.

https://simontoth.substack.com/p/daily-bite-of-c-advent-of-code-day-5ab?r=1g4l8a&utm_campaign=post&utm_medium=web

#cpp #cplusplus #coding #programming #dailybiteofcpp #adventofcode

Šimon Tóth
2 days ago

OK, seriously #gcc what the hell? I'm trying to build GCC from sources and it fails non-deterministically.

And this is inside a Docker Image, so the environment is completely deterministic.

Almost no problems on x86-64, but arm64 is a nightmare. #cpp

matt 🦕
2 days ago

Started Day three but decided I'd figure out type generics in #cpp for my many `print_line` functions..

Enter `Templates` and after a bit of trial and error I now have `logging.tcc` which contains a bunch of sensible templated functions.

https://github.com/mattjbones/advent-of-code/commit/fe8ab137a48f667a11aa3d614d8442623421e38b

Rust Weekly 🦀
2 days ago

I got roasted by Prime (Youtuber) - and lived to love it. Why C++ is better than Rust.

https://www.youtube.com/watch?v=Wz0H8HFkI9U

Discussions: https://discu.eu/q/https://www.youtube.com/watch?v=Wz0H8HFkI9U

#cpp #programming #rustlang

Steve Maclellan
2 days ago

'Pure magical thinking': Albertans filled premier's inbox with emails opposing provincial pension plan

https://libranet.de/display/0b6b25a8-1965-6b98-da37-bd2380135967

'Pure magical thinking': Albertans filled premier's inbox with emails opposing provincial pension plan
Suryavarman
2 days ago

Le cube est fonctionnel. Le voici avec les faces inversées et normales. :P
#panda3d 🐼
#cpp

faces inversées
faces dans le sens anti-horaires (le sens par défaut)
Šimon Tóth
2 days ago

📆 Day 2 of Advent of Code 2023 is here. Today, we are parsing information about cubes.

😱 Did you struggle with the parsing?
😉 What was your approach?

https://open.substack.com/pub/simontoth/p/daily-bite-of-c-advent-of-code-day-e49?r=1g4l8a&utm_campaign=post&utm_medium=web

#cpp #cplusplus #coding #programming #dailybiteofcpp #adventofcode

Somē
2 days ago

c++ solution of part 2 of today's #adventofcode WITHOUT for loops: https://github.com/somecho/aoc23.cpp/blob/main/src/day_2_2.cpp

#cpp

Somē
3 days ago

Today's solving of #adventofcode in C++ is mostly me implementing my own utility functions liketrim (why does C++ not have this) andindexOf, and just generally figuring out how std::map(I still haven't really figured it out) and iterators work.

#cpp

matt 🦕
3 days ago

So.. #clangd is a thing and I started using it and the #VSCode has come alive with argument annotations and way more feedback on the C-style #cpp that I'm writing.

matt 🦕
3 days ago

where is the simple `.split(delimiter)` for strings in #cpp

fwrret
3 days ago
// Initialize the result vector R
for (size_t i = 0; i < m; i++) {
h_R[m] = 0;
}

8 hours of my life threw away because I was too lazy to configure the debugger.

#cpp

Šimon Tóth
3 days ago

Just a quick update for the AOC template repository.

I only now noticed that the debugger used by the CMake extension was not configured correctly. Right-click on a binary in the CMake panel, and selecting debug will now work correctly.

Either update or change your configuration to:
https://github.com/HappyCerberus/aoc-2023-cpp/commit/e79aa276a6ad1856820fa2cd7bb0a4230de05b13

#cpp #AdventOfCode #dailybiteofcpp

matt 🦕
3 days ago

wow, you sure have to do a lot of the heavy lifting with #cpp includes?

Today I'm tryig to add a bit of structure to my #AdventOfCode and I'm learning all about guarding `#include` .. fun!

Rachel Wil Singh ~ Moos-a-dee
3 days ago

Oh also I implemented the minimap. Still a lot of debug text everywhere and placeholder objects, but building out the systems before deciding what exactly I'm going to do with the game.

#ChristmasHorse #gamedev #indiedev #cpp #sfml

Screenshot of Christmas Horse -
There's a HUD with a minimap that is working, doors are outlined in red rectangles to show their collision regions, and there are interactable objects on the ground.
Šimon Tóth
3 days ago

📆 Day 1 of Advent of Code 2023 is here. Today, we are extracting digits from text.

🥰 Let me know how you managed today.

🔥 Did you take the time to implement a proper optimal solution for part two? 🔥

https://open.substack.com/pub/simontoth/p/daily-bite-of-c-advent-of-code-day?r=1g4l8a&utm_campaign=post&utm_medium=web

#cpp #cplusplus #coding #programming #dailybiteofcpp #adventofcode

Somē
3 days ago

This year, I'm doing Advent of Code for the second time. Last year I did it (half way) while learning Rust. This year, I'm doing it in C++ with a functional style! I'll be sharing my solutions to this repo: https://github.com/somecho/aoc23.cpp

#advent #adventofcode #cplusplus #cpp #FunctionalPrograming

matt 🦕
4 days ago

Ok, here we go, ready for #AdventOfCode with #CPP characteristics... https://github.com/mattjbones/advent-of-code/blob/main/2023-cpp/src/main.cpp

Also displaying my incomplete #Rust attempt from last year and even the #TypeScript escape hatch

matt 🦕
4 days ago

Ok so.. #cpp package manager or build tools, what's the Cargo of the C++ world?

I'm gonna try #poac as it seems pretty nice: https://github.com/poac-dev/poac though the builds failling on GitHub aren't encouraging.

C & C++ Weekly
4 days ago

MISRA C++:2023 (Guidelines for the use C++:17 in critical systems) published

https://forum.misra.org.uk/thread-1668.html

Discussions: https://discu.eu/q/https://forum.misra.org.uk/thread-1668.html

#cpp #programming

jbz
5 days ago

⚡ Modern-CPP-Programming: Modern C++ Programming Course (C++11/14/17/20) | Federico Busato
https://github.com/federico-busato/Modern-CPP-Programming

#cpp #programming #tutorial

matt 🦕
5 days ago

@m4tt_314 mmm yeah, a decent chunk of the problems is parsing the input data. #cpp has got to have some nice packages for this though?

dana :blobhaj_witch:
5 days ago

Chrome is in the news for another 0-day that makes use of integer overflow in C++.

This is a solvable problem, and these bugs can be eliminated to make software safer by design. Please enjoy a blog post about how!

http://orodu.net/2023/11/29/overflow.html

#MemorySafety #Infosec #Cpp #SubspaceCpp

Aut
5 days ago

Unplanned, but I've recently found about about the Entity, Component, System design pattern and found a professor that put his lectures online for making a game engine in C++ using SFML and I've been following along.

I have no plans to do anything with the knowledge or code I write but it makes me really miss being a University student and learning all day.

If anyone finds that sort of thing interesting, here is the playlist on YouTube
https://youtube.com/playlist?list=PL_xRyXins848nDj2v-TJYahzvs-XW9sVV&si=jueh2gwkh3HgJiWb
#cpp #ecs #gamedev #sfml #programming

Šimon Tóth
5 days ago

std::as_const is a C++17 utility that simplifies const-casting, specifically the safe variant of adding a const qualifier.

Notably, this utility is more ergonomic in generic contexts than the standard const_cast.

Compiler Explorer link: https://compiler-explorer.com/z/sP5MeEP6b

#cpp #cplusplus #coding #programming #dailybiteofcpp

Astra Kernel :verified:
6 days ago

✨ Rust std fs slower than Python!? No, it's hardware!

https://xuanwo.io/2023/04-rust-std-fs-slower-than-python/

#rustlang #python #rust #cpp

mort
1 week ago

When writing C++, I consistently find myself wanting to use std::string_view, because I want to take a view into a string. Then, as time goes on, I eventually want to pass that string to something which eventually has to interact with a #C (usually #POSIX) API. At that point, I need a 0-terminated string. string_view isn't zero terminated, so I revert back to using a const char * instead of a string_view.

Why oh why isn't there a std::c_string_view which contains a zero-terminated string

#cpp

Sean Murthy
1 week ago

Modern C++, especially C++17 and later, is much like German. Both languages meant for people already skilled in them.

At least German has the excuse of being an organically-grown human language.

#cpp #cplusplus #german #deutsch #programming #complexity

Martin Geisler
1 week ago

@CppCon At Android, we can see the effects of shifting more and more code to memory safe languages (Java and Rust): https://security.googleblog.com/2022/12/memory-safe-languages-in-android-13.html. The absolute number of critical/high memory safety vulnerabilities was halved from 2019 to 2022. The drop is correlated with the introduction of more and more memory safe code.

It will be very interesting to see the effect of C++ profiles! This assumes they become standardized and widely adopted in the next 5-10 years.

#memorysafety #rust #cpp #android

Martin Geisler
1 week ago

@CppCon There is also a comment about unsafe constructs being unmentioned. Unsafe Rust is part of Rust and I think it's super important that we acknowledge this. The power of unsafe is that it gives us a structured way to build safe abstractions on top of unsafe primitives. The standard library is a great example of this.

However, it's true that it can be hard or impossible to encapsulate program-wide safe effects. See https://security.googleblog.com/2023/10/bare-metal-rust-in-android.html, which touches on this.

#cpp #rust #interop

Martin Geisler
1 week ago

@CppCon Rust is not mentioned at all throughout the talk. But Bjarne again points out that any alternative language would need to have interoperability with C and C++. He claims this is often underestimated.

I don't agree with that it is ignored or down-played: Google (and other companies) are investing into Rust and C++ interop, see https://github.com/google/crubit and https://github.com/google/autocxx as important examples of work in this area.

#cpp #rust #interop #google

Astra Kernel :verified:
1 week ago

🦀 Fish evolved into Crab

#rustlang #rust #cpp #programming #linux

reddit post with title "fish shell has finally been converted into a rust based product'. it received a reply "Fish has evolved into Crab"
Sonny Bonds
2 weeks ago

@c_discussions std::vector performing better than any set for small inputs.

#algorithms #cpp

C & C++ Weekly
2 weeks ago

C++ std::unordered_set performing worse than a std::set for large inputs

https://cses.fi/problemset/

Discussions: https://discu.eu/q/https://cses.fi/problemset/

#algorithms #compsci #cpp #learnmachinelearning #programming

Sean Murthy
2 weeks ago

Given all the ad block conversation around YouTube, I wonder what it would take for conferences to post their videos to PeerTube or similar video service. I mean they have the content ready to go.

Various conferences in a topic could even together start their own instance and share the infrastructure cost. There won't be any need for content moderation.

Looking at you Cpp North, C++ on Sea, C++ Now, Meeting CPP, AdaCon, ...

https://joinpeertube.org/

#cpp #cPlusPlus #video #peerTube #cpp_video

dana :blobhaj_witch:
2 weeks ago

An unsafe Rust can still solve a ton of safety problems, leaving lifetimes to mitigations like smart pointers (like raw_ptr in Chrome). This seems like the viable incremental migration/adoption strategy for Safe Rust. Swift is nailing this. I think Carbon is trying to go this direction too.

Anyway, enjoy an interesting chat with the Swift team manager:

https://mastodon.social/@rust_discussions/111454394522188951

2/2

#Cpp #Rust #Swift #CarbonLang

dana :blobhaj_witch:
2 weeks ago

Swift is getting really mature. Stable ABI. Using clang to access and represent C++ types natively. No ffi bindings required. Foundation library available on all desktop platforms.

I hope Rust will start putting some serious effort behind C++ migration/interop. Or I can see a future where the C++ industry migrates largely to Swift, with perhaps Rust libraries for specific tasks like codecs. Which is fine but I worry about some companies, that would be willing to use Rust, never catching up to that.

C++ code will never migrate directly into Safe Rust. Swift found a middle ground for it that Rust will need too. Unsafe Rust needs to become a language people can do their daily work in that is better than C++. That’s what migration can look like.

I was skeptical of Carbon’s plan to build out an unsafe language that is good to work in, since I felt like the safe language is where people should be. I still worry about coming in and building the safe language later, but I can see the value of making an ergonomic unsafe language (nullability for pointers for example), because they are taking seriously the idea of migrating whole C++ codebases to this language. AND understanding that people will be working in that (unsafe) language full time.

1/2

#Cpp #Rust #Swift #CarbonLang

Thanks to Ryan Jespersen for having me on today to talk about the fall of X, the future of Mastodon, the fate of Bill C-18, the problems with an Alberta Pension Plan, the troubling rise of antisemitism and Islamophobia sparked by the tragedies in Israel and Gaza, AND the #yegquest Henday chicken hunt. https://www.youtube.com/live/ysQ1k2gseCg?si=RbtcaLph6ckmh_3f #Mastodon #C18 #CPP #AlbertaPensionPlan #yeg #Edmonton #Alberta #SenateofCanada #cdnpoli #abpoli #ableg #LRT

Sonny Bonds
3 weeks ago

So I just had a thing with a constant like:
static const float someConstant = someExpression;

(Yes it should be a constexpr but it isn't. Yet.)

In one build someConstant is calculated compile time and in another build it's calculated runtime, with slightly different floating point results. The difference turned out to be a compiler flag, but not one I guessed:
/JMC

I can't manage to reproduce it in godbolt but it's consistent in my actual code.

More like /JFC amirite

#cpp #cplusplus #msvc

Changelog
3 weeks ago

Zig is a significant improvement over C++

...To be honest...

Even C is a significant improvement over C++

🤣🤣🤣 @mcollina on @jsparty

#zig #ziglang #cpp #c #programming #javascript #bunjs

🎥 https://youtube.com/shorts/HNVnk1E5ask

⚛️Revertron
3 weeks ago

Unsafe in #Rust and C++

#cpp

C & C++ Weekly
3 weeks ago
Fell
4 weeks ago

Engine programmers literally only want one thing and it's fucking disgusting:

> The game has PASSED the Hardware/Software Compatibility and Performance Check with a great majority of systems obtaining excellent performance results.

(Actual results of my work, I am SO proud!!! 🥳)

#GameDev #GameDevelopment #GameProgramming #Gaming #Programming #CPlusPlus #CPP #CPP20 #OpenGL #GameEngine #Performance #Hardware #Software #Compatibility #Graphics #ComputerGraphics

Stas Kolenikov
1 month ago

I am working in a project that has bits of #rstats, bits of #python and bits of #cpp and they are all supposed to be united by #ApacheArrow. How do I access externally created Arrow objects in R? Everything that is in https://r4ds.hadley.nz/arrow.html, https://arrow-user2022.netlify.app/ (with huge thanks to @djnavarro), https://arrow.apache.org/cookbook/r (thanks to @nic_crane) talks about creating large Arrow-ish objects in R by reading external data in csv or parquet rather than connecting to the existing Arrow sources.

Sonny Bonds
1 month ago

Apparently popen won't take 65k long command lines on Windows.

Don't ask me how I know.

#cpp #cplusplus #softwareengineering

Fell
1 month ago

@SonnyBonds We use C++ bitfields:
```
struct Object {
bool is_active:1 = 0;
bool is_dirty:1 = 0;
}
```
So, each member is just one bit. The default value only works in C++20 but the bitfields are C++11 I think.

#cpp20 #cpp #cplusplus #programming

Sonny Bonds
1 month ago

What's your favorite way of doing type safe flags in C++? I typically just use some enum/int combo, but it's not really type safe and you can combine flags from different sets.

#cpp #cplusplus

Astra Kernel :verified:
1 month ago

✨ How Rust can
Facilitate New
Contributors while Decreasing
Vulnerabilities

🦀 1st time contributors to Rust projects are about
70 times less likely to introduce vulnerabilities
than 1st time contributors to C++ project

https://cypherpunks.ca/~iang/pubs/gradingcurve-secdev23.pdf

#rustlang #rust #cpp #infosec #dfir

probability visualization of Rust and Cpp programmers making vulnerability (from non experienced to experienced )

Cheers people, anyone into C++ #CPP would like to help both the #Python and #Java communities at once?

I have this #jpype issue that affects many Portuguese-speaking users (and I bet, other international users) that have non-ascii chars in their folder names scattered through their OSs.... https://github.com/jpype-project/jpype/issues/1111

This causes trouble for me personally because #py5 depends on jpype and my students have #ThonnyIDE frequently in a directory with non-ascii chars in its path, due to their usernames or on "Área de Trabalho" (desktop)... etc.

Emily C Taylor
1 month ago

I don't know who originally created this but it was too true not to share. What else would you add to this list?

#abpoli #cdnpoli #cpp #ucp #ableg

A photo of Danielle Smith squinting slightly, and below it a list reading as follows:

Things I Trust More Than Danielle Smith 

1) The weather man 
2) Gas station sushi 
3) That guy who never paid you back 
4) A raccoon in my kitchen 
5) A Grizzly Bear 
6) A Canada Goose with a 'pet me' sign on it