Advertisement
Appendko

C: seperate header/function

Apr 19th, 2021
1,092
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.08 KB | None | 0 0
  1. /* You need three files: */
  2. /*---------------------------*/
  3. /* b.h */
  4. #include <stdio.h>
  5. #include <gsl/gsl_vector.h>
  6.  
  7. struct output_template{
  8.   gsl_vector *v1;
  9.   gsl_vector *v2;
  10. };
  11.  
  12. struct output_template afunc();
  13.  
  14.  
  15. /*---------------------------*/
  16. /* b.c */
  17. #include <stdio.h>
  18. #include <gsl/gsl_vector.h>
  19. #include "b.h"
  20.  
  21. struct output_template afunc(){
  22.   struct output_template output;
  23.   output.v1=gsl_vector_alloc(2);
  24.   output.v2=gsl_vector_alloc(2);
  25.  
  26.   gsl_vector_set(output.v1,0,0.2);
  27.   gsl_vector_set(output.v1,1,5.7);
  28.  
  29.   gsl_vector_set(output.v2,0,-0.2);
  30.   gsl_vector_set(output.v2,1,1.5);
  31.  
  32.   return output;
  33. }
  34.  
  35. /*---------------------------*/
  36. /* c.c */
  37. #include <stdio.h>
  38. #include <gsl/gsl_vector.h>
  39. #include "b.h"
  40.  
  41. int main()
  42. {
  43.   struct output_template output=afunc();
  44.  
  45.   printf("v1_1=%.5f\n",gsl_vector_get(output.v1,0));
  46.  
  47.   return(0);
  48. }
  49.  
  50. /*---------------------------*/
  51. /*---Compile these files-----*/
  52. /*--- I use mkl for cblas needed by gsl -----*/
  53.  
  54. icc -c b.c
  55. icc -c c.c
  56. icc -o c.out b.o c.o -mkl -lgsl
  57.  
  58. /*---------------------------*/
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement