Skip to content

Commit 61c0177

Browse files
committed
best practices
1 parent 59a564b commit 61c0177

8 files changed

Lines changed: 22 additions & 7 deletions

File tree

src/bool/logbool.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
#include <stdio.h>
2+
3+
#if __STDC_VERSION__ < 202311L
24
#include <stdbool.h>
5+
#endif
36

47
#include "my_bool.h"
58

69
bool logical_not(bool a)
710
{
8-
printf("C input boolean: %d size %zu\n", a, sizeof(a));
11+
printf("C boolean sizeof(%d) = %zu\n", a, sizeof(a));
912

1013
return !a;
1114
}

src/bool/logbool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
bool logical_not(const bool a)
66
{
7-
std::cout << "C++ input boolean: " << a << " size " << sizeof(a) << "\n";
7+
std::cout << "C++ boolean sizeof(" << a << ") = " << sizeof(a) << "\n";
88

99
return !a;
1010
}

test/bool/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
set_property(DIRECTORY PROPERTY LABELS bool)
22

3-
add_library(bool_fortran ${PROJECT_SOURCE_DIR}/src/bool/logbool.f90)
3+
add_library(bool_fortran OBJECT ${PROJECT_SOURCE_DIR}/src/bool/logbool.f90)
44
target_include_directories(bool_fortran INTERFACE ${PROJECT_SOURCE_DIR}/src/bool)
55

6-
add_library(bool_cxx ${PROJECT_SOURCE_DIR}/src/bool/logbool.cpp)
6+
add_library(bool_cxx OBJECT ${PROJECT_SOURCE_DIR}/src/bool/logbool.cpp)
77
target_include_directories(bool_cxx PUBLIC ${PROJECT_SOURCE_DIR}/src/bool)
88

9-
add_library(bool_c ${PROJECT_SOURCE_DIR}/src/bool/logbool.c)
9+
add_library(bool_c OBJECT ${PROJECT_SOURCE_DIR}/src/bool/logbool.c)
1010
target_include_directories(bool_c PUBLIC ${PROJECT_SOURCE_DIR}/src/bool)
1111

1212
add_executable(c_fortran_bool main.c)

test/bool/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
#if __STDC_VERSION__ < 202311L
12
#include <stdbool.h>
3+
#endif
4+
25
#include <stdio.h>
36
#include <stdlib.h>
47

test/nullptr/nullptr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
#ifdef __cplusplus
33
extern "C" {
4-
#else
4+
#elif __STDC_VERSION__ < 202311L
55
#include <stdbool.h>
66
#endif
77

test/real/main.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#include <stdio.h>
2-
#include <stdbool.h>
32
#include <stdlib.h>
43

4+
#if __STDC_VERSION__ < 202311L
5+
#include <stdbool.h>
6+
#endif
7+
58
#include "mynan.h"
69

710

test/struct/lib.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
#if __STDC_VERSION__ < 202311L
12
#include <stdbool.h>
3+
#endif
4+
25
#include <string.h>
36
#include <stdlib.h>
47
#include <stdio.h>

test/struct/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
#if __STDC_VERSION__ < 202311L
12
#include <stdbool.h>
3+
#endif
4+
25
#include <string.h>
36
#include <stdlib.h>
47

0 commit comments

Comments
 (0)