Skip to content

Commit 77d216d

Browse files
committed
add malloc new C++
1 parent b19a584 commit 77d216d

File tree

5 files changed

+41
-1
lines changed

5 files changed

+41
-1
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ include (cmake/compilers.cmake)
1010

1111
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
1212

13-
foreach(d array bool error opaque pointer poly_function poly_type struct submodule tictoc vector)
13+
foreach(d array bool error malloc opaque pointer poly_function poly_type struct submodule tictoc vector)
1414
set(td src/${d})
1515
add_subdirectory(${td})
1616
get_property(targets DIRECTORY ${td} PROPERTY BUILDSYSTEM_TARGETS)

src/array/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,7 @@ int main()
2020
}
2121
}
2222

23+
std::cout << "OK: array" << std::endl;
24+
2325
return EXIT_SUCCESS;
2426
}

src/malloc/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
set_directory_properties(PROPERTIES LABELS malloc)
2+
3+
add_executable(cxx_fortran_malloc main.cpp)
4+
target_link_libraries(cxx_fortran_malloc PRIVATE vector_fortran)
5+
add_test(NAME C++_Fortran_malloc COMMAND cxx_fortran_malloc)
6+
7+
get_property(test_names DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY TESTS)
8+
set_tests_properties(${test_names} PROPERTIES TIMEOUT 5)

src/malloc/main.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <iostream>
2+
3+
extern "C" void timestwo(int [], int [], const size_t*);
4+
5+
6+
int main()
7+
{
8+
const size_t N = 3;
9+
10+
auto x = new int[N];
11+
auto x2 = new int[N];
12+
13+
timestwo(&x[0], &x2[0], &N);
14+
15+
for (auto i=0u; i < N; i++){
16+
if (x2[i] != 2*x[i]){
17+
std::cerr << "value " << x2[i] << "!=" << x[i] << std::endl;
18+
return EXIT_FAILURE;
19+
}
20+
}
21+
22+
delete[] x;
23+
delete[] x2;
24+
25+
std::cout << "OK: C++ malloc new" << std::endl;
26+
27+
return EXIT_SUCCESS;
28+
}

src/vector/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,7 @@ int main()
2020
}
2121
}
2222

23+
std::cout << "OK: vector" << std::endl;
24+
2325
return EXIT_SUCCESS;
2426
}

0 commit comments

Comments
 (0)