File tree Expand file tree Collapse file tree 7 files changed +26
-35
lines changed
Expand file tree Collapse file tree 7 files changed +26
-35
lines changed Original file line number Diff line number Diff line change @@ -53,6 +53,7 @@ add_test(NAME C++_Fortran_error
5353)
5454
5555add_executable (cxx_fortran_struct cxx/struct_main.cxx)
56+ target_include_directories (cxx_fortran_struct PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} /c)
5657target_link_libraries (cxx_fortran_struct PRIVATE struct_fortran)
5758set_target_properties (cxx_fortran_struct PROPERTIES LINKER_LANGUAGE CXX)
5859add_test (NAME C++_Fortran_struct COMMAND $<TARGET_FILE:cxx_fortran_struct>)
Original file line number Diff line number Diff line change 1+ #ifdef __cplusplus
2+ extern "C" {
3+ #endif
4+
5+ enum { LMAX = 1000 };
6+
7+ struct params {
8+ // order and lengths must match in Fortran and C
9+ int my_int ;
10+ bool my_bool ;
11+ char my_char [LMAX ];
12+ };
13+
14+ void struct_check (struct params );
15+
16+ #ifdef __cplusplus
17+ }
18+ #endif
Original file line number Diff line number Diff line change 33#include <stdlib.h>
44#include <stdio.h>
55
6- struct params {
7- // order and lengths must match in Fortran and C
8- int my_int ;
9- bool my_bool ;
10- char my_char [1000 ];
11- };
6+ #include "my_struct.h"
127
13- void struct_check (struct params );
148
159void struct_check (struct params s ) {
1610
Original file line number Diff line number Diff line change 22#include <string.h>
33#include <stdlib.h>
44
5- enum { Lchar = 1000 };
6-
7- struct params {
8- // order and lengths must match in Fortran and C
9- int my_int ;
10- bool my_bool ;
11- char my_char [Lchar ];
12- };
13-
14- extern void struct_check (struct params * );
5+ #include "my_struct.h"
156
167int main (void ) {
178
@@ -21,7 +12,7 @@ s.my_int = 123;
2112s .my_bool = true;
2213strcpy (s .my_char , "Hello" );
2314
24- struct_check (& s );
15+ struct_check (s );
2516
2617return EXIT_SUCCESS ;
2718
Original file line number Diff line number Diff line change 11add_library (math_cxx OBJECT math_lib.cxx)
22
33add_library (struct_cxx OBJECT struct_lib.cxx)
4+ target_include_directories (struct_cxx PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} /../c)
Original file line number Diff line number Diff line change 22#include < cstring>
33#include < cstdlib>
44
5- struct params {
6- // order and lengths must match in Fortran and C
7- int my_int;
8- bool my_bool;
9- char my_char[1000 ];
10- };
11-
12- extern " C" void struct_check (struct params );
5+ #include " my_struct.h"
136
147void struct_check (struct params s) {
158
Original file line number Diff line number Diff line change 11#include < cstring>
22#include < cstdlib>
33
4- struct params {
5- // order and lengths must match in Fortran and C
6- int my_int;
7- bool my_bool;
8- char my_char[1000 ];
9- };
10-
11- extern " C" void struct_check (struct params *);
4+ #include " my_struct.h"
125
136int main () {
147
@@ -18,7 +11,7 @@ s.my_int = 123;
1811s.my_bool = true ;
1912strcpy (s.my_char , " Hello" );
2013
21- struct_check (& s);
14+ struct_check (s);
2215
2316return EXIT_SUCCESS;
2417
You can’t perform that action at this time.
0 commit comments