r_cpp | Unsorted

Telegram-канал r_cpp - C++ - Reddit

-

Stay up-to-date with everything C++! Content directly fetched from the subreddit just for you. Join our group for discussions : @programminginc Powered by : @r_channels

Subscribe to a channel

C++ - Reddit

Why does MSVC's optimizer gets confused when copying a trivial struct

Hi everyone!

I was micro-optimizing some compression code when an innocuous change made a huge performance difference.


At first I expected some weird hardware pipelining effects, but looking at the disassembly revealed that MSVC sometimes generates atrocious code when trying to copy a trivial 8 byte struct (with /O2 ofc):



For this struct struct entry { uint32_t a; uint32_t b; };:

target = entry {a, b};

Creates a temporary `entry` on the stack, reads it into `rax` and only then move `rax` into `target`.

But:

target->a = a;
target->b = b;

Sets `a` and `b` into `target` directly.


Bizarrely when the struct is already instantiated, it's the opposite:

target->a = e.a;
target->b = e.b;

Does two 32 bits moves, while

target = e;

Does one 64 bit move.




Here is the godbolt link.



It also happens in C, so it isn't some constructor shenanigan.

Unsurprisingly reading members from a local copy, rather than through the pointer directly also generate shit code.




This seems so incredibly trivial that I can't help but think that I am missing something. But GCC and clang both produce much better code (and more importantly, generate the same code for both the ..._good and ..._bad functions).

Is this just an "MSVC moment" ? If so, where can I report it assuming it hasn't been already.

https://redd.it/1cacaxd
@r_cpp

Читать полностью…

C++ - Reddit

Is Senders and Receivers a replacement for Executors?

I am currently trying to understand how asynchronous programming and networking will work in future C++. (Networking is just one of several applications of asynchronous processes that I have.)

As I recall, the Networking TS was based on Executors. Asio implements this, right?

Is Senders and Receivers a supplement or a replacement for Executors?

Is the current Asio a good choice for asynchronous processes if you want to migrate to functions from the C++ standard in the future?

https://redd.it/1caa7fn
@r_cpp

Читать полностью…

C++ - Reddit

Machine Learning for C++ developers - the hard way: DirectML
https://www.codeproject.com//Articles/5380834/Machine-Learning-for-Cplusplus-developers-the-hard

https://redd.it/1ca40f2
@r_cpp

Читать полностью…

C++ - Reddit

Pointers or Smart Pointers

I am so confused about traditional pointers and smart pointers.
I had read that, “anywhere you could think you can use pointers just write smart pointers instead - start securing from your side”.
But I rarely see legacy codes which have smart pointers, and still tradition pointers are widely promoted more than smart pointers.
This confuses me, if traditional and smart pointers have completely different use cases or, I should just stop using traditional pointers and start using smart pointers where ever I have work of pointers/memory.
What do you recommend and what’s your say on this experienced developers, please help.

https://redd.it/1c9xi30
@r_cpp

Читать полностью…

C++ - Reddit

Applying for a "very senior c++ role"

I had a recruiter reach out to me for a potential position described as "a very senior technical role". I know this is vague, but what are some topics you would expect someone who is "very senior" to be familiar with?

https://redd.it/1c9vnjq
@r_cpp

Читать полностью…

C++ - Reddit

Cost of destruction of unique/shared pointer?

Does the cost of destroying a smart pointer is much higher than creation? I created 20K unique objects and insert it on std::map it only took 0.2 second and erase all item in the map took 2.7 seconds, I'm not sure if the culprit is removing items on the map or the destruction of smart pointer is really slow than creation.

Creating ........................
Done creating ................... 0.231295
Destroying.......................
Done Destroying................... 2.74911

https://redd.it/1c9omdb
@r_cpp

Читать полностью…

C++ - Reddit

C++ compile time initialization for a class.

I'm coming from an embedded background. I often have driver tables constructed as arrays of compile time initialized structures, I'd like to do the same thing in C++, but I need the basic structure to be a C structure because legacy code is C only, not C++.
Thus, I have a 'struct gpio_info' - which has details about a GPIO pin on a chip.
I want to create a C++ Class for my GPIO driver and am trying to figure out how to create
I'm looking over this *SIMPLE* C++ question:
https://stackoverflow.com/questions/49802012/different-ways-of-initializing-an-object-in-c
And I want to know how to do "compile time initialization" of the C++ class.
more specifically - I am trying to do what I know how to do in C code.
In C code(more correctly, C99) - Issue #1 - is I want the class to be in constant (aka: FLASH memory) - not in RAM. Issue #2 - this means in C99 I would declare the struct as a CONST, and use member based initialization. The result of this would be constant ASM level data used as the variable initializer.
In the embedded world this data would live in the ".text" or ".rodata" section. This is important because I do not want to pay the cost of two copies of the structure (one in the initializer memory, and another copies into the RAM - because the RAM may be corrupted over time - but the FLASH will not be corrupted.
In C++ it seems I can only do run time initialization where the class it self is store in the BSS, I want it stored in the text or rodata section.
And it seems C++ always requires a constructor to initialize things which by definition is a "run time initialization" - exactly what I do not want.
```
\#include <stdio.h>
struct gpio_info { unsigned long id; int x; int y; };
class GPIO : gpio_info {
// Disallow constructor
GPIO() = delete;
// disallow "new()" of this class
void *operator new(size_t) = delete;
void *operator new[\] (size_t) = delete;
void operator delete(void *) = delete;
void operator delete[\](void *) = delete;
static GPIO *Initialize( unsigned long );
static int DoSomething( unsigned long );
int DoSomething( void );
static int DoSomethingElse( unsigned long valueA, int valueB );
int DoSomethingElse( int valueB );
};
// In C99 I would do this and the compiler does it for me.
const struct gpio_info c_foo = { .id = 1 ,.x = 2, .y = 3 };
// I want to do the same thing in C++
const GPIO example1 : gpio_info( .id = 1, .x=2, .y=3 );
// expecations: "example1" is in the text or ".rodata" section.
// example1 construction is at compile time not run time
```


https://redd.it/1c9gx3g
@r_cpp

Читать полностью…

C++ - Reddit

announcing estra/diol, a new c++/rust benchmarking library with a tui visualizer

https://github.com/sarah-ek/estra
https://github.com/sarah-ek/diol

https://github.com/sarah-ek/diol-cbind

`diol` is a a c++/rust benchmarking framework. the internals of the library are written in rust, but the c++ wrapper is designed with good ergonomics in mind, while also keeping the ffi overhead to a minimum (the cost is a couple nanoseconds on my desktop)

the benchmarking code looks like this

#include "diol.hpp"

using namespace diol;

void foo(Bencher bencher, PlotArg arg) {
auto v = std::vector<double>(arg.n);
std::move(bencher).bench([&] {
for (auto &x : v) {
x *= 2.0;
}
});
}

void bar(Bencher bencher, PlotArg arg) {
auto v = std::vector<double>(arg.n);
std::move(bencher).bench([&] {
for (auto &x : v) {
x *= 0.1;
}
});
}

int main() {
auto config = BenchConfig::from_args();
config.set_metric("f64/s", HigherIsBetter,
[](std::uintptr_t n, double time) { return n / time; });

auto bench = Bench::from_config(config);

{
Function<PlotArg> funcs[] = {{"foo", foo}, {"bar", bar}};
PlotArg args[] = {1, 2, 4, 512};
bench.register_funcs<PlotArg>(funcs, args);
}
bench.run();
}

and the output looks like this

╭────────────────┬──────┬──────────┬───────────┬───────────┬───────────┬───────────╮
│ benchmark │ args │ f64/s │ fastest │ median │ mean │ stddev │
├────────────────┼──────┼──────────┼───────────┼───────────┼───────────┼───────────┤
│ foo │ 1 │ 4.869e8 │ 2.05 ns │ 2.05 ns │ 2.06 ns │ 141.00 ps │
│ bar │ 1 │ 4.868e8 │ 2.05 ns │ 2.05 ns │ 2.06 ns │ 107.00 ps │
├────────────────┼──────┼──────────┼───────────┼───────────┼───────────┼───────────┤
│ foo │ 2 │ 9.743e8 │ 2.05 ns │ 2.05 ns │ 2.06 ns │ 102.00 ps │
│ bar │ 2 │ 9.741e8 │ 2.05 ns │ 2.05 ns │ 2.06 ns │ 100.00 ps │
├────────────────┼──────┼──────────┼───────────┼───────────┼───────────┼───────────┤
│ foo │ 4 │ 1.455e9 │ 2.73 ns │ 2.73 ns │ 2.76 ns │ 266.00 ps │
│ bar │ 4 │ 1.349e9 │ 2.73 ns │ 2.96 ns │ 2.97 ns │ 248.00 ps │
├────────────────┼──────┼──────────┼───────────┼───────────┼───────────┼───────────┤
│ foo │ 512 │ 1.038e10 │ 49.12 ns │ 49.13 ns │ 49.41 ns │ 3.10 ns │
│ bar │ 512 │ 1.039e10 │ 49.12 ns │ 49.13 ns │ 49.37 ns │ 2.87 ns │
╰────────────────┴──────┴──────────┴───────────┴───────────┴───────────┴───────────╯

`estra` is a tui visualizer that can display the benchmark results in a way that's easy to navigate. for info on how to customize the library's behavior and generate the output for `estra`, you can run the program with `--help`

[screenshot](https://private-user-images.githubusercontent.com/40109184/324247091-4de9e290-0180-40bc-8857-5cb8a277f33d.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTM3MDQ4MzgsIm5iZiI6MTcxMzcwNDUzOCwicGF0aCI6Ii80MDEwOTE4NC8zMjQyNDcwOTEtNGRlOWUyOTAtMDE4MC00MGJjLTg4NTctNWNiOGEyNzdmMzNkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA0MjElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNDIxVDEzMDIxOFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTI3Yzg4YmViYTA0ZTE3MTE5MDI5ODdlMDA1ODZhMWFkNjc0YTAwZTQzYWU0NDFjMDNmNzgyNzg0ZGIyMWZiNWEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.bJK5ppuv3-xVITuvY6Qg1qiOu_wjPruTFcOXzVZyx_A)

https://redd.it/1c9hez6
@r_cpp

Читать полностью…

C++ - Reddit

How To Use Skia Images in C++ Builder?
https://learncplusplus.org/how-to-use-skia-images-in-c-builder/

https://redd.it/1c9ewve
@r_cpp

Читать полностью…

C++ - Reddit

Which containers initialize data?

I know that a C style array doesn't initialize simple types like int, char, etc. So int64_t my_array[1024\]; will have undefined values. Does the same apply to std::set<int>, std::unordered_set<int>, std::vector<int>, std::array<int>?

https://redd.it/1c9c9l3
@r_cpp

Читать полностью…

C++ - Reddit

has anyone a good nvim config (dotfiles) for cpp for me?

hi i im looking for a good coding editor for c/cpp and i came up to use neovim but i dont have a config for it i just want to have autosuggestion etc..

https://redd.it/1c8uyxo
@r_cpp

Читать полностью…

C++ - Reddit

The Math Sorcerer: Learn C++
https://www.youtube.com/watch?v=orDoBDM4Rlg

https://redd.it/1c8opzc
@r_cpp

Читать полностью…

C++ - Reddit

i need to find the problem

hi, i try to create a game, my idea is when i put a boat in the zone "A5" in "A5" comes out a emoji in this case a "0 o 0" but in my code if i put in "A5" in "A1,A2,A3,A4,A5" comes out the emoji too, but i need to fix that becouse i want the emoji comes out only in "A5". under that i attach the code, the librery i use is "iostream","conio.h","windows.h":

p.s. the code is in italian void posizionamento(char riga,int colonna, int barca) { do{

gotoxy(120,20);

cout<<"scegli la riga = ";

cin>>riga;

int lineaa[8\];

int lineab[8\];

int lineac[8\];

int linead[8\];

int lineae[8\];

int lineaf[8\];

int lineag[8\];

switch (riga)

{

case 'a':

gotoxy(120,21);

cout<<"scegli la colonna = ";

cin>>colonna;

lineaacolonna=1;

barca++;

break;


case 'b':

gotoxy(120,21);

cout<<"scegli la colonna = ";

cin>>colonna;

lineabcolonna=1;

barca++;

break;

case 'c':

gotoxy(120,21);

cout<<"scegli la colonna = ";

cin>>colonna;

lineaccolonna=1;

barca++;

break;

case 'd':

gotoxy(120,21);

cout<<"scegli la colonna = ";

cin>>colonna;

lineadcolonna=1;

barca++;

break;

case 'e':

gotoxy(120,21);

cout<<"scegli la colonna = ";

cin>>colonna;

lineaecolonna=1;

barca++;

break;

case 'f':

gotoxy(120,21);

cout<<"scegli la colonna = ";

cin>>colonna;

lineafcolonna=1;

barca++;

break;

case 'g':

gotoxy(120,21);

cout<<"scegli la colonna = ";

cin>>colonna;

lineagcolonna=1;

barca++;

break;

}

for(int i=0;i<56;i++)

{

if (lineaa[i\]==1)

{

if(lineaa1== 1)

{

gotoxy(32,4);

cout<<"0 o 0";

}

else if(lineaa[2\]== 1) {

gotoxy(40,4);

cout<<"0 o 0";

}

else if(lineaa3== 1)

{

gotoxy(48,4);

cout<<"0 o 0";

}

}

else if(lineaa[i\]== 1)

{

gotoxy(32,8);

cout<<"0 o 0";

}

else if(lineac[i\]==1)

{

gotoxy(32,12);

cout<<"0 o 0";

}

else if(linead[i\]==1)

{

gotoxy(32,4);

cout<<"0 o 0";

}

else if(lineae[i\]==1)

{

gotoxy(32,4);

cout<<"0 o 0";

}

else if(lineaf[i\]==1)

{

gotoxy(32,4);

cout<<"0 o 0";

}

else if(lineag[i\]==1)

{

gotoxy(32,4);

cout<<"0 o 0";

} } }while(barca<8); }

https://redd.it/1c8o7oz
@r_cpp

Читать полностью…

C++ - Reddit

Is there a compiler flag that can detect this specific behavior

vector<int> v;
int j = vj;


Can happen often when you're using short variable names and autopiloting. Would much appreciate if somebody knows a compiler flag for this.

-Wpedantic and -Wall doesn't catch this.

Any automated solutions appreciated.

https://redd.it/1c1sty5
@r_cpp

Читать полностью…

C++ - Reddit

Problem with FFT using MPI

I have implemented a c++ program that calculates the fast Fourier transform, but for some reason it does not work. Can you tell me what the problem is?
\#include <iostream>
\#include <cmath>
\#include <mpi.h>
\#define PI 3.14159265
struct num1
{
float real;
float img;
};
int reverseBits(int number, int NO_OF_BITS)
{
int reverse_num = 0, i, temp;
for (i = 0; i < NO_OF_BITS; i++)
{
temp = (number & (1 << i));
if (temp)
reverse_num |= (1 << ((NO_OF_BITS - 1) - i));
}
return reverse_num;
}
int main(int argc, char** argv)
{
int rank, size, num, i, key, div;
double bb1time, ab1time, bb2time, ab2time, starttime, endtime;
MPI_Status status;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Datatype num1type;
MPI_Datatype type[2\] = { MPI_FLOAT, MPI_FLOAT };
int blocklen[2\] = { 4, 4 };
MPI_Aint disp[2\];
num = 256;
bb1time = MPI_Wtime();
MPI_Bcast(&num, 1, MPI_INT, 0, MPI_COMM_WORLD);
ab1time = MPI_Wtime();
struct num1* input = new num1[num + 1\];
struct num1* seq = new num1[num + 1\];
struct num1* temp = new num1[num + 1\];
input[0\].real = 0.0;
input[0\].img = 0.0;
seq[0\].real = 0.0;
seq[0\].img = 0.0;
temp[0\].real = 0.0;
temp[0\].img = 0.0;
disp[0\] = 0;
disp[1\] = 4;

MPI_Type_create_struct(2, blocklen, disp, type, &num1type);
MPI_Type_commit(&num1type);
if (rank == 0)
{
bb1time = MPI_Wtime();
srand(time(NULL));
for (i = 1; i < num + 1; i++)
{
input[i\].real = static_cast <float> (rand()) / static_cast <float> (RAND_MAX);
input[i\].img = 0.0;
}
for (i = 1; i < num + 1; i++)
{
seq[i\].real = input[reverseBits(i - 1, log2(num) / log2(2)) + 1\].real;
seq[i\].img = 0.0;
}
}
bb2time = MPI_Wtime();
MPI_Bcast(seq, num + 1, num1type, 0, MPI_COMM_WORLD);
ab2time = MPI_Wtime();
key = log2(num);
div = 1;
starttime = MPI_Wtime();
while (key--)
{
if (rank != 0)
{
if (((rank + div - 1) / div) % 2 == 0)
{
temp[rank\].real = seq[rank - div\].real +
(cos(PI * ((rank - 1) % (div * 2)) / div) * (seq[rank\].real)) +
(sin(PI * ((rank - 1) % (div * 2)) / div) * (seq[rank\].img));
temp[rank\].img = seq[rank - div\].img +
(cos(PI * ((rank - 1) % (div * 2)) / div) * (seq[rank\].img)) -
(sin(PI * ((rank - 1) % (div * 2)) / div) * (seq[rank\].real));
MPI_Send(&temp[rank\], 1, num1type, 0, 0, MPI_COMM_WORLD);
}
else
{
temp[rank\].real = seq[rank\].real +
(cos(PI * ((rank - 1) % (div * 2)) / div) * (seq[rank + div\].real)) +
(sin(PI * ((rank - 1) % (div * 2)) / div) * (seq[rank + div\].img));
temp[rank\].img = seq[rank\].img +
(cos(PI * ((rank - 1) % (div * 2)) / div) * (seq[rank + div\].img)) -
(sin(PI * ((rank - 1) % (div * 2)) / div) * (seq[rank + div\].real));
MPI_Send(&temp[rank\], 1, num1type, 0, 0, MPI_COMM_WORLD);
}
}
else
{
for (i = 1; i < num; i++) {
MPI_Recv(&temp[i\], 1, num1type, MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, &status);
}
}
MPI_Barrier(MPI_COMM_WORLD);
if (rank == 0)
{
for (i = 1; i < num + 1; i++)
{
seq[i\].real = temp[i\].real;
seq[i\].img = temp[i\].img;
}
div *= 2;
}
MPI_Bcast(seq, num + 1, num1type, 0, MPI_COMM_WORLD);
MPI_Bcast(&div, 1, MPI_INT, 0, MPI_COMM_WORLD);
}
endtime = MPI_Wtime();
if (0 == rank)
{
std::cout << std::endl;
for (i = 1; i < num + 1; i++)
{
std::cout << "X[" << i - 1 << "\] : " << seq[i\].real;
if (seq[i\].img >= 0)
std::cout << "+j" << seq[i\].img << std::endl;
else
std::cout << "-j" << seq[i\].img - 2 * seq[i\].img << std::endl;
}
std::cout << std::endl;
std::cout << "Time to broadcast num variable: " << (ab1time - bb1time) * 1000 << " ms" << std::endl;
std::cout << "Time to broadcast input and seq arrays: " << (ab2time - bb2time) * 1000 << " ms" << std::endl;
std::cout << "Time to compute FFT parallely: " << (endtime -

Читать полностью…

C++ - Reddit

The Performance Impact of C++'s `final` keyword.
https://16bpp.net/blog/post/the-performance-impact-of-cpp-final-keyword/

https://redd.it/1caarda
@r_cpp

Читать полностью…

C++ - Reddit

return consteval lambda composed of 2 other consteval lambdas

I'm trying to build a validator function at compile time. But with using consteval I have a problem: code,source:'%23include+%3Cfunctional%3E%0A%23include+%3Ciostream%3E%0A%23include+%3Carray%3E%0A%0Atemplate%3Ctypename+T,+typename...+Ts%3E%0Aconsteval+auto+andpredicates(T+pred,+Ts...+preds)%0A%7B%0A++++return+%5B%3D%5D+(auto+a)+consteval+%7B+return+pred(a)+%26%26+(std::invoke(preds,+a)+%26%26+...)%3B+%7D%3B%0A%7D%0A%0Aint+main()%0A%7B%0A++++constexpr+auto+f1+%3D+%5B%5D+(int+a)+consteval+%7B+return+a+%3C+10%3B+%7D%3B%0A++++constexpr+auto+f2+%3D+%5B%5D+(int+a)+consteval+%7B+return+a+%3E+0%3B+%7D%3B%0A%0A++++constexpr+auto+validator+%3D+andpredicates(f1,+f2)%3B%0A%0A++++std::printf(%22%25d%5Cn%22,+validator(5))%3B%0A%0A++++return+0%3B%0A%7D'),l:'5',n:'0',o:'C%2B%2B+source+%231',t:'0')),k:46.69956815175755,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:executor,i:(argsPanelShown:'1',compilationPanelShown:'0',compiler:g132,compilerName:'',compilerOutShown:'0',execArgs:'',execStdin:'',fontScale:14,fontUsePx:'0',j:1,lang:c%2B%2B,libs:!(),options:'-O2+-std%3Dc%2B%2B20',overrides:!(),runtimeTools:!(),source:1,stdinPanelShown:'1',wrap:'1'),l:'5',n:'0',o:'Executor+x86-64+gcc+13.2+(C%2B%2B,+Editor+%231)',t:'0')),k:32.0430886946212,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:g132,filters:(b:'0',binary:'1',binaryObject:'1',commentOnly:'0',debugCalls:'1',demangle:'0',directives:'0',execute:'1',intel:'0',libraryCode:'0',trim:'1',verboseDemangling:'0'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:1,lang:c%2B%2B,libs:!(),options:'-O2+-std%3Dc%2B%2B20',overrides:!(),selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1),l:'5',n:'0',o:'+x86-64+gcc+13.2+(Editor+%231)',t:'0')),k:21.257343153621253,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4)

Anybody can explain why this doesn't work?

https://redd.it/1ca91h2
@r_cpp

Читать полностью…

C++ - Reddit

C++ VsCode issues

Okay, so i just finished a python course in college and now im on to C++. I installed python just fine with no issues. I got to C++ and I have no clue how to make my programs run. I installed GINMW and changed my path directory and all of that stuff. I checked it was all installed in cmd prompt. The first time i open vs code and run a program in C++ it says Loaded about 20 times and everything loads. Then i run the exact same program a second time and it just says "\^C" at the end of my directory in the terminal. I have been googling for hours but i cant find anything to help with this. If anyone has any suggestions it would be greatly appreciated.

https://redd.it/1c9zujo
@r_cpp

Читать полностью…

C++ - Reddit

RGFW.h | Single-header graphics framework cross-platform library | managing windows/system apis

[RGFW](https://github.com/ColleagueRiley/RGFW) is a single-header graphics framework cross-platform library. It is very simular in utility to GLFW however it has a more SDL-like structure. It is meant to be used as a very small and flexible alternative library to GLFW. Much like GLFW it does not do much more than the minimum in terms of functionality. However it still is a very powerful tool and offers a quick start so the user can focus on graphics programming while RGFW deals with the complexities of the windowing APIs.

RGFW also can be used to create a basic graphics context for OpenGL, buffer rendering, Vulkan or Direct X. Currently the backends it supports include, XLib (UNIX), Cocoas (MacOS) and WinAPI (Windows) and it is flexible so implementing a custom backend should be easy.

RGFW comes with many examples, including buffer rendering, opengl rendering, opengl 3 rendering, direct X rendering and Vulkan rendering. However there are also some projects that can be used as examples that use RGFW. Including PureDoom-RGFW which is my example DOOM source port using RGFW and pureDOOM, and RSGL which is my GUI library that uses RGFW as a base.

Here is very basic example code to show off how RGFW works.

#define RGFW_IMPLEMENTATION
#include "RGFW.h"
int main() {
RGFW_window* win = RGFW_createWindow("name", 500, 500, 500, 500, (u64)0);

while (!RGFW_window_shouldClose(win)) {
while (RGFW_window_checkEvent(win)) {
if (win->event.type == RGFW_quit)))
break;
}

RGFW_window_swapBuffers(win);

glClearColor(0xFF, 0XFF, 0xFF, 0xFF);
glClear(GL_COLOR_BUFFER_BIT);
}

RGFW_window_close(win);
}

More information can be found on the github, such as screenshots, a size comparison table and RGFW itself.

github : [https://github.com/ColleagueRiley/RGFW](https://github.com/ColleagueRiley/RGFW)

https://redd.it/1c9wh7b
@r_cpp

Читать полностью…

C++ - Reddit

C# to C++

I am a student who mostly uses C# for all my programming needs. While I also know Java, I find it difficult to accomplish certain tasks and be as independent as I want to be in Java. Therefore, I prefer C# as it allows me to work on good projects. Currently, I am interested in working on scientific projects that require CPU control. For this reason, I am planning to learn C++. Although it has always been a challenging language for me, I am eager to learn it. Could you suggest any useful resources that I can use? Also, how can I make my learning curve more exponential I suppose?

https://redd.it/1c9tzgq
@r_cpp

Читать полностью…

C++ - Reddit

Why does std::unordered_multi{map,set}::find() not guaranteed to return the first matching element?

Today I just find out that if there are several elements with the requested key in a `std::unordered_multi{map,set}` container, the `find()` method gives any one of them, not necessarily the first one.

[https://en.cppreference.com/w/cpp/container/unordered\_multimap/find](https://en.cppreference.com/w/cpp/container/unordered_multimap/find)

[https://en.cppreference.com/w/cpp/container/unordered\_multiset/find](https://en.cppreference.com/w/cpp/container/unordered_multiset/find)

This forces me to use the `equal_range()` method instead, which is less efficient, because it must iterate through all matched elements unconditionally. This is like how `count()` is less efficient than `contains()` in the pre-c++20 days.

For example, the below two snippets are not equivalent.
```
for (auto iter = ummap.find(x); iter != ummap.end() && iter->first == x; ++iter)
{
if (iter->second.some_condition()) [[likely]]
return iter;
}
```
```
for (auto [iter, end] = ummap.equal_range(x); iter != end; ++iter)
{
if (iter->second.some_condition()) [[likely]]
return iter;
}
```
I wonder why the standard doesn't guarantee this. Implementation should be easy. Isn't it?

https://redd.it/1c9k9dx
@r_cpp

Читать полностью…

C++ - Reddit

Engineer with EE background and the programming work.

Hi programming legends,

I came from EE background and I’m fresh engineer ( first 9 months), and C++ are required in most of my work.

I have just only small question..

How to know if am I good enough for programming and coding ??

I felt like everyone think I’m not that good enough and I need to stick with the hardware things as my background…

But, for me I really enjoy coding!
Yes, I take long time to figure things out and start code and formalize things and concepts as implemented code…

But Idk, is that learning curve and normal?
Or programming not suits me …

How to figure out the right things and right direction?

I would appreciate a real and honest opinion and advice, please don’t tell me things to just make me relief… just a sincere truth 🙏🏻


https://redd.it/1c9ihrb
@r_cpp

Читать полностью…

C++ - Reddit

Accepting pesentation proposals for Boston C++ meetup

We are accepting presentation proposals for future meetups! Do you have something awesome to share? Best practices that you feel others may benefit from? Please submit your proposal below and we will take it into consideration for upcoming meetups! We are interested in prioritizing diversity in our presenters and we would like to encourage people from underrepresented groups to join us in this effort. We prefer in person meetings so please take into consideration that you may have to present in person.

https://forms.gle/uSXitfPWBzV525NR9

https://redd.it/1c9g6s9
@r_cpp

Читать полностью…

C++ - Reddit

Wants to Advance Multithreading in C++

Hi C++ legends ,

I’m rookie in cpp, and I’m in the middle of my journey to advance my learning in programming and c++.

And currently, I need to learn multithreading very well, I need to do some small projects for practice.

What’s resources do you recommended?
And small real projects I can do.

Many thanks & sorry if the question was repetitive



https://redd.it/1c9dbm6
@r_cpp

Читать полностью…

C++ - Reddit

The Hunt for the Elusive Bug: A C++ Developer's Odyssey



Hey C++ aficionados of r/cpp,

Prepare yourselves for a saga from the trenches of C++ development—a tale of perseverance, frustration, and the relentless pursuit of elusive bugs. Join me on a journey through the labyrinthine corridors of code, where attention to detail reigns supreme and every misplaced semicolon is a potential landmine.

Imagine yourself knee-deep in C++ code, navigating the treacherous waters of memory management and pointer arithmetic. You're on the trail of a bug that has eluded capture for far too long—a bug that mocks your efforts with its stubborn resilience.

Hours turn into days as you comb through your codebase, searching for the elusive culprit that dares to defy your logic. And then, just when you're on the brink of despair, you spot it—a tiny oversight that has evaded your gaze until now: a missing long keyword. Such a seemingly innocuous detail, yet its absence has thrown your entire project into disarray, leaving you grappling with frustration and disbelief.

But in the world of C++, where elegance meets complexity, every bug is a lesson waiting to be learned. You debug, you iterate, and you emerge stronger than before, armed with newfound knowledge and a steely resolve.

So, to all my fellow C++ developers, I offer this advice: Embrace the challenge of debugging, for it is through the crucible of trial and error that we refine our craft. Stay vigilant, stay determined, and never underestimate the importance of attention to detail in the pursuit of elegant solutions.

Have you ever encountered a bug that tested your patience in the world of C++? Share your tales of triumph (or tribulation) in the comments below!

Link to "Powers of Ten" Video

Comments are welcome!

https://redd.it/1c99bxa
@r_cpp

Читать полностью…

C++ - Reddit

Implementing C++ STL in C.

Ahmm, yes i am trying to implement C++ stl in C, just like any other guy who does C/C++. The reason for my doing this project is the learning outcomes. I will get to learn about C++ STL, a lot about C programming and data structures and algorithm, and also i will have a great project with me that i can showcase to my teachers and recruiters. here thats what i have done so far. Can i get some views of the more expert people on how can i structure it better, because thats the main problem i am currently focusing. I just want this to be a self project so im not trying to make it completely like C++ also that would be impossible.


Another issue is the generics that i am struggling with the most i have found my way through using enum values as data types and then checking the values and casting them on push or pop.
Any help is appreciated.


https://redd.it/1c8rl2l
@r_cpp

Читать полностью…

C++ - Reddit

Experimental CMake import std support works, but is impractical with MSVC

I was pretty excited to hear that next CMake release would support import std, so I installed nightly build and did some experiments on MSVC. I tried to convert my project to use import std.

The problem is that if any of your dependencies internally include standard headers, you simply can not use import std, since MSVC currently does not support mixing of both includes and import std. Mixing both will result in errors. This limitation has existed always, but personally I didn't fully understand the ramifications of this before my failed experiment.

Here is a minimal example that demonstrates the problem. Since Boost headers internally includes standard headers, import std will result in compile errors:

module;
#include <boost/container/flatmap.hpp>
export module my
module;

// error C2572: 'std::constructat': redefinition of default argument: parameter 1
// error C2572: 'std::enable
if': redefinition of default argument: parameter 1
import std;

// ...

I'm sure Microsoft will fix this eventually, but because of current state of the tools I don't recommend using import std yet, unless you own every single line of code in your project and ship binaries only.

However I'm still optimistic about modules and now that I've started to report every bug I encounter, I've also learned that eventually those bugs will get fixed.

https://redd.it/1c8p4rj
@r_cpp

Читать полностью…

C++ - Reddit

When building a 64bit app, do I need to use 64 bit types?

I've always written my C++ code in MSVC and compiled with 64bit, with never really thinking about variable types and stuff. But I've been wondering lately if I should also use 64bit types, like std::int64_t over something like just plain int, or 64 bit float/double over regular floats?

https://redd.it/1c8k56k
@r_cpp

Читать полностью…

C++ - Reddit

starttime) * 1000 << " ms" << std::endl;
std::cout << "Total Time: " << ((endtime - starttime) + (ab2time - bb2time) + (ab1time - bb1time)) * 1000 << " ms" << std::endl;
std::cout << std::endl;
}
MPI_Finalize();
return 0;
}


https://redd.it/1c1rumk
@r_cpp

Читать полностью…

C++ - Reddit

C++ support with ROS2 for Industrial applications?

Hi, I wanted to know the current ecosystem, support and usage for ROS2 with C++.

I have worked with ROS1 with Python connecting a Linux system to a raspberry pi, which in turn is connected to a Arduino as the microcontroller for encoder DC motors. This whole system basically used off the shelf ROS packages and some ros specific Arduino libraries l.

So building onto this, I want how ROS is actually used in large scale Industrial setup and what are certain other frameworks or tools that are utilised in case of custom components and PCBs.

https://redd.it/1c1o2eg
@r_cpp

Читать полностью…
Subscribe to a channel