Skip to content

Commit 3c16fbe

Browse files
committed
PWR080: Improve code examples
By enforcing PWR003 and PWR007.
1 parent ffa7c05 commit 3c16fbe

5 files changed

Lines changed: 12 additions & 9 deletions

File tree

Checks/PWR080/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ typedef enum {
6666
OPTION_UNKNOWN,
6767
} TransformOption;
6868

69-
double transform_and_sum(const double *array, size_t size,
70-
TransformOption option) {
69+
__attribute__((pure)) double transform_and_sum(const double *array, size_t size,
70+
TransformOption option) {
7171
double sum = 0.0;
7272

7373
double factor;
@@ -146,6 +146,7 @@ the specified transformation:
146146
! example.f90
147147
148148
module options
149+
implicit none
149150
integer, parameter :: OPTION_HALF = 1
150151
integer, parameter :: OPTION_DOUBLE = 2
151152
integer, parameter :: OPTION_UNKNOWN = 3
@@ -163,7 +164,7 @@ program main
163164
164165
contains
165166
166-
real(kind=real32) function transform_and_sum(array, option)
167+
pure real(kind=real32) function transform_and_sum(array, option)
167168
implicit none
168169
169170
real(kind=real32), intent(in) :: array(:)

Checks/PWR080/example.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ typedef enum {
88
OPTION_UNKNOWN,
99
} TransformOption;
1010

11-
double transform_and_sum(const double *array, size_t size,
12-
TransformOption option) {
11+
__attribute__((pure)) double transform_and_sum(const double *array, size_t size,
12+
TransformOption option) {
1313
double sum = 0.0;
1414

1515
double factor;

Checks/PWR080/example.f90

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
! PWR080: Conditionally initialized variables can lead to undefined behavior
22

33
module options
4+
implicit none
45
integer, parameter :: OPTION_HALF = 1
56
integer, parameter :: OPTION_DOUBLE = 2
67
integer, parameter :: OPTION_UNKNOWN = 3
@@ -18,7 +19,7 @@ program main
1819

1920
contains
2021

21-
real(kind=real32) function transform_and_sum(array, option)
22+
pure real(kind=real32) function transform_and_sum(array, option)
2223
implicit none
2324

2425
real(kind=real32), intent(in) :: array(:)

Checks/PWR080/solution.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ typedef enum {
88
OPTION_UNKNOWN,
99
} TransformOption;
1010

11-
double transform_and_sum(const double *array, size_t size,
12-
TransformOption option) {
11+
__attribute__((pure)) double transform_and_sum(const double *array, size_t size,
12+
TransformOption option) {
1313
double sum = 0.0;
1414

1515
// Identity transformation by default

Checks/PWR080/solution.f90

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
! PWR080: Conditionally initialized variables can lead to undefined behavior
22

33
module options
4+
implicit none
45
integer, parameter :: OPTION_HALF = 1
56
integer, parameter :: OPTION_DOUBLE = 2
67
integer, parameter :: OPTION_UNKNOWN = 3
@@ -18,7 +19,7 @@ program main
1819

1920
contains
2021

21-
real(kind=real32) function transform_and_sum(array, option)
22+
pure real(kind=real32) function transform_and_sum(array, option)
2223
implicit none
2324

2425
real(kind=real32), intent(in) :: array(:)

0 commit comments

Comments
 (0)