Last active
April 1, 2020 13:43
-
-
Save hertzsprung/51fd51f1de907af3b57ce2e098ec0f46 to your computer and use it in GitHub Desktop.
C/C++ struct example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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