0

Learning how templates and operator() work!

preview

#include <iostream>

template <typename T, const int length=5> class vector { public: T v[length]; vector operator +(const vector &obj) { vector tmp; for(int i = 0; i < length; i++) tmp.v[i] = v[i] + obj.v[i]; return tmp; /* This method below only works if length is a fixed size return {v[0] + obj.v[0], v[1] + obj.v[1], v[2] + obj.v[2], v[3] + obj.v[3], v[4] + obj.v[4]};*/ } }; int main() { vector<int> a={1,2,3,4,5}; vector<int> b={1,2,3,4,5};

auto c = a + b;

std::cout << "(int) ";
for(int i = 0; i < 5; i++)
    std::cout << c.v[i] << " ";
std::cout << std::endl;

}

#include <iostream>

template <typename T, const int length=5> class vector { public: T v[length]; vector operator +(const vector &obj) { vector tmp; for(int i = 0; i < length; i++) tmp.v[i] = v[i] + obj.v[i]; return tmp; /* This method below only works if length is a fixed size return {v[0] + obj.v[0], v[1] + obj.v[1], v[2] + obj.v[2], v[3] + obj.v[3], v[4] + obj.v[4]};*/ } }; int main() { vector<int> a={1,2,3,4,5}; vector<int> b={1,2,3,4,5};

auto c = a + b;

std::cout << "(int) ";
for(int i = 0; i < 5; i++)
    std::cout << c.v[i] << " ";
std::cout << std::endl;

}

0

Inlining Library functions

preview

So I have the following problem. I am currently writing some Libraries in C++ as a way to get started with the language. In my library I want to use the inline keyword for a function to reduce the overhead caused by lots of function calls. The problem I have is, that it seems like it is not possible to inline functions, if I dont define them in my libraries header file.

So I got three files, that I am working with. My library (lib.cpp), its header file (lib.h) and my main code (main.cpp). My testing code for my library looks like this (this is just example code that has the same structure, but with different functionality):

main.cpp

#include <iostream>
#include "lib.h"
using namespace std;

int main(){
  int count = 5;
  float sum = get_sum(count);
  cout << "Sum of 0-" << count << ": " << sum << endl;


  int num = get_num(6);
  cout << "Got num: " << num << endl;
  return 0;
  return 0;
}

And my library looks like this:
lib.cpp

#include "lib.h"
inline int get_num(int num){
  return num;
}

int get_sum (int count){
  int sum = 0;
  for(int i = 0; i < count; i++){
    sum = sum + get_num(i);
  }
  return sum;
}

Naturally I created my header file like this:
lib.h

#ifndef LIB_H
#define LIB_H
inline int get_num(int num);
int get_sum (int count);
#endif 

The problem with this is, that this code will throw an compile error that theres no definition for get_num in main.cpp. This can be fixed by simply moving the entire function with its body into the header file.

The problem I have with doing it like this is, that this causes my inline function to not show up inside my lib.cpp file and gets hidden away in the header file. Is there a way that I can define my inline functions in my libraries source code, and expose it as a public function through my header file?

So I have the following problem. I am currently writing some Libraries in C++ as a way to get started with the language. In my library I want to use the inline keyword for a function to reduce the overhead caused by lots of function calls. The problem I have is, that it seems like it is not possible to inline functions, if I dont define them in my libraries header file.

So I got three files, that I am working with. My library (lib.cpp), its header file (lib.h) and my main code (main.cpp). My testing code for my library looks like this (this is just example code that has the same structure, but with different functionality):

main.cpp

#include <iostream>
#include "lib.h"
using namespace std;

int main(){
  int count = 5;
  float sum = get_sum(count);
  cout << "Sum of 0-" << count << ": " << sum << endl;


  int num = get_num(6);
  cout << "Got num: " << num << endl;
  return 0;
  return 0;
}

And my library looks like this:
lib.cpp

#include "lib.h"
inline int get_num(int num){
  return num;
}

int get_sum (int count){
  int sum = 0;
  for(int i = 0; i < count; i++){
    sum = sum + get_num(i);
  }
  return sum;
}

Naturally I created my header file like this:
lib.h

#ifndef LIB_H
#define LIB_H
inline int get_num(int num);
int get_sum (int count);
#endif 

The problem with this is, that this code will throw an compile error that theres no definition for get_num in main.cpp. This can be fixed by simply moving the entire function with its body into the header file.

The problem I have with doing it like this is, that this causes my inline function to not show up inside my lib.cpp file and gets hidden away in the header file. Is there a way that I can define my inline functions in my libraries source code, and expose it as a public function through my header file?

0

iceoryx2 0.10 released: full flatbuffer integration, zero copy ipc with unbounded data, robust event

preview

geteilt von: programming.dev/post/56750248

Checkout the release notes: ekxide.io/blog/iceoryx2-0.10-release/

Git: github.com/eclipse-iceoryx/iceoryx2

iceoryx2 book: ekxide.github.io/iceoryx2-book/main/

geteilt von: programming.dev/post/56750248

Checkout the release notes: ekxide.io/blog/iceoryx2-0.10-release/

Git: github.com/eclipse-iceoryx/iceoryx2

iceoryx2 book: ekxide.github.io/iceoryx2-book/main/

0

Live talk on evaluating expressions in the custom programming language

preview

This webinar will explore how to represent the results of computations in a custom language and show how to evaluate expressions step by step. Join the live session on September 24, 1:00 PM UTC+1.

This webinar will explore how to represent the results of computations in a custom language and show how to evaluate expressions step by step. Join the live session on September 24, 1:00 PM UTC+1.

0

Live talk on implementing functions in the toy programming language

preview

The upcoming episode in a series of live talks on building a custom programming language using C++ is dedicated to one of the core building blocks of any language: functions. Join the live session on August 20, 1:00 PM UTC+1.

The upcoming episode in a series of live talks on building a custom programming language using C++ is dedicated to one of the core building blocks of any language: functions. Join the live session on August 20, 1:00 PM UTC+1.

0

Learn about variables during this live talk on building a custom C++-based programming language

preview

The next part of a live talk series on building a custom programming language using C++ is coming on July 23 at 1:00 PM UTC+1.

During this episode, the host will walk through the implementation step by step, showing how variables are represented and processed in the language, and how to add this functionality to your language in C++.

Register to join the live session here.

The next part of a live talk series on building a custom programming language using C++ is coming on July 23 at 1:00 PM UTC+1.

During this episode, the host will walk through the implementation step by step, showing how variables are represented and processed in the language, and how to add this functionality to your language in C++.

Register to join the live session here.

0

Cross Language Data Types

ekxide Cross-Language Data Types ekxide.io
preview

geteilt von: programming.dev/post/52041408

Have you ever thought about sharing data across language boundaries without serialization? This blog post highlights the challenges behind this endeavor and how they can be overcome.

Note: I’m not the original author of the blog post, but since the author does not have a programming.dev account, I post it on his behalf.

geteilt von: programming.dev/post/52041408

Have you ever thought about sharing data across language boundaries without serialization? This blog post highlights the challenges behind this endeavor and how they can be overcome.

Note: I’m not the original author of the blog post, but since the author does not have a programming.dev account, I post it on his behalf.

0

iceoryx2 v0.9 released: Fast and Robust Inter-Process Communication (IPC) Library

ekxide Announcing iceoryx2 v0.9.0 ekxide.io
preview

geteilt von: programming.dev/post/50633812

Hello everyone

We released iceoryx2 v0.9 tonight. With the release, we are pushing more and more iceoryx2 into the embedded world. We have written a test runner that runs on std and no_std environments, stabilized the decentralized recovery, and added a ton of quality of life improvements.

For those who haven’t heard of it yet: iceoryx2 is a zero-copy inter-process communication library.

The basic idea is: instead of serializing data, copying it through sockets, pipes, message queues, or some broker process, iceoryx2 lets processes communicate via shared memory. That makes it useful when you care about latency, throughput, or moving large amounts of data between processes without wasting CPU cycles on copies.

It supports C, C++, Python, Rust, and C#, and runs on Linux, macOS, Windows, FreeBSD, and QNX, with experimental support for Android and VxWorks.

It is not limited to plain pub/sub either. iceoryx2 supports publish-subscribe, events, request-response streams, and a blackboard pattern, which is basically a key-value repository directly in shared memory.

The architecture is fully decentralized: no central broker, no daemon that everything depends on, and no single process that becomes the obvious bottleneck or failure point.

Happy to answer questions about the release, the no_std work, or zero-copy IPC in general.

geteilt von: programming.dev/post/50633812

Hello everyone

We released iceoryx2 v0.9 tonight. With the release, we are pushing more and more iceoryx2 into the embedded world. We have written a test runner that runs on std and no_std environments, stabilized the decentralized recovery, and added a ton of quality of life improvements.

For those who haven’t heard of it yet: iceoryx2 is a zero-copy inter-process communication library.

The basic idea is: instead of serializing data, copying it through sockets, pipes, message queues, or some broker process, iceoryx2 lets processes communicate via shared memory. That makes it useful when you care about latency, throughput, or moving large amounts of data between processes without wasting CPU cycles on copies.

It supports C, C++, Python, Rust, and C#, and runs on Linux, macOS, Windows, FreeBSD, and QNX, with experimental support for Android and VxWorks.

It is not limited to plain pub/sub either. iceoryx2 supports publish-subscribe, events, request-response streams, and a blackboard pattern, which is basically a key-value repository directly in shared memory.

The architecture is fully decentralized: no central broker, no daemon that everything depends on, and no single process that becomes the obvious bottleneck or failure point.

Happy to answer questions about the release, the no_std work, or zero-copy IPC in general.

0

Learn how to create your own programming language using C++

preview

PVS-Studio devs are continuing the series of talks on building a custom C++ based programming language.

In this session, the speaker will explain what a parser is, walk through the recursive descent approach, and show how to build your own expression parser from scratch.

Join the talk here.

PVS-Studio devs are continuing the series of talks on building a custom C++ based programming language.

In this session, the speaker will explain what a parser is, walk through the recursive descent approach, and show how to build your own expression parser from scratch.

Join the talk here.

0

stackless coroutines for gamedev in ~200 lines of C++

stackless coroutines for gamedev in ~200 lines of C++ vittorioromeo.com
preview

C++20 coroutines have lovely syntax. They are also a terrible fit for game development. In this article, the author will present sfex::Coroutine: a ~200-line stackless macro-based coroutine library built around a variant of the classic switch + LINE trick.

C++20 coroutines have lovely syntax. They are also a terrible fit for game development. In this article, the author will present sfex::Coroutine: a ~200-line stackless macro-based coroutine library built around a variant of the classic switch + LINE trick.