Skip to content

Instantly share code, notes, and snippets.

@MShrimp4
Created September 19, 2023 06:17
Show Gist options
  • Save MShrimp4/1f984727d3eefb3a1324424364bb9c04 to your computer and use it in GitHub Desktop.
Save MShrimp4/1f984727d3eefb3a1324424364bb9c04 to your computer and use it in GitHub Desktop.
Templated Inline
#include <stddef.h>
#include <stdio.h>
template<size_t x, size_t y>
void doSomething2(double (&arr)[x][y])
{
for (int i = 0; i < x; i++)
for (int j = 0; j < y; j++)
arr[i][j] = i * x + j;
}
int main()
{
double arr2[10][10][10];
doSomething2(arr2[0]);
}
#include <stddef.h>
#include <stdio.h>
int x = 10;
int y = 10;
void doSomething(double** arr) //arr[10][10]
{
for (int i = 0; i < x; i++)
for (int j = 0; j < y; j++)
arr[i][j] = i * x + j;
}
int main()
{
double*** arr = new double**[10];
for(int i = 0; i<10;i++)
{
arr[i] = new double*[10];
for(int j=0; j<10; j++)
arr[i][j] = new double[10];
}
doSomething(arr[0]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment