Skip to content

Instantly share code, notes, and snippets.

@hertzsprung
Last active April 1, 2020 13:43
Show Gist options
  • Save hertzsprung/51fd51f1de907af3b57ce2e098ec0f46 to your computer and use it in GitHub Desktop.
Save hertzsprung/51fd51f1de907af3b57ce2e098ec0f46 to your computer and use it in GitHub Desktop.
C/C++ struct example
#include "stdio.h"
#include "stdlib.h"
typedef double real;
struct SolverParams
{
real dt;
real tolh;
real end_time;
};
void print(struct SolverParams* solver_params)
{
printf("dt=%f tolh=%f end_time=%f\n",
solver_params->dt,
solver_params->tolh,
solver_params->end_time);
}
int main()
{
struct SolverParams solver_params =
{
.dt = 0.1,
.tolh = 1e-6,
.end_time = 10.0
};
print(&solver_params);
return EXIT_SUCCESS;
}
#include <cstdio>
#include <cstdlib>
typedef double real;
typedef struct SolverParams
{
real dt;
real tolh;
real end_time;
} SolverParams;
void print(SolverParams& solver_params)
{
printf("dt=%f tolh=%f end_time=%f\n",
solver_params.dt,
solver_params.tolh,
solver_params.end_time);
}
int main()
{
SolverParams solver_params =
{
.dt = 0.1,
.tolh = 1e-6,
.end_time = 10.0
};
print(solver_params);
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment