File tree Expand file tree Collapse file tree 5 files changed +19
-15
lines changed
Expand file tree Collapse file tree 5 files changed +19
-15
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ struct params {
1111 char my_char [LMAX ];
1212};
1313
14- void struct_check (struct params );
14+ void struct_check (struct params * );
1515
1616#ifdef __cplusplus
1717}
Original file line number Diff line number Diff line change 66#include "my_struct.h"
77
88
9- void struct_check (struct params s ) {
9+ void struct_check (struct params * s ) {
1010
11- if (s .my_int != 123 ) {
12- fprintf (stderr , "Error: my_int = %d\n" , s .my_int );
11+ struct params * p = s ;
12+
13+ if (p -> my_int != 123 ) {
14+ fprintf (stderr , "Error: my_int = %d\n" , p -> my_int );
1315 exit (EXIT_FAILURE );
1416}
1517
16- if (! s . my_bool ) {
18+ if (! p -> my_bool ) {
1719 fprintf (stderr , "Error: my_bool is false\n" );
1820 exit (EXIT_FAILURE );
1921}
2022
21- if (strncmp (s . my_char , "Hello" , 5 ) != 0 ) {
22- fprintf (stderr , "Error: my_char != Hello: %s\n" , s . my_char );
23+ if (strncmp (p -> my_char , "Hello" , 5 ) != 0 ) {
24+ fprintf (stderr , "Error: my_char != Hello: %s\n" , p -> my_char );
2325 exit (EXIT_FAILURE );
2426}
2527
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ s.my_int = 123;
1212s .my_bool = true;
1313strcpy (s .my_char , "Hello" );
1414
15- struct_check (s );
15+ struct_check (& s );
1616
1717return EXIT_SUCCESS ;
1818
Original file line number Diff line number Diff line change 44
55#include " my_struct.h"
66
7- void struct_check (struct params s) {
7+ void struct_check (struct params * s) {
88
9- if (s.my_int != 123 ) {
10- std::cerr << " Error: my_int = " << s.my_int << std::endl;
9+ struct params *p = s;
10+
11+ if (p->my_int != 123 ) {
12+ std::cerr << " Error: my_int = " << p->my_int << std::endl;
1113 exit (EXIT_FAILURE);
1214}
1315
14- if (! s. my_bool ) {
16+ if (! p-> my_bool ) {
1517 std::cerr << " Error: my_bool is false" << std::endl;
1618 exit (EXIT_FAILURE);
1719}
1820
19- if (strncmp (s. my_char , " Hello" , 5 ) != 0 ) {
20- std::cerr << " Error: my_char != Hello " << s. my_char << std::endl;
21+ if (strncmp (p-> my_char , " Hello" , 5 ) != 0 ) {
22+ std::cerr << " Error: my_char != Hello " << p-> my_char << std::endl;
2123 exit (EXIT_FAILURE);
2224}
2325
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ s.my_int = 123;
1111s.my_bool = true ;
1212strcpy (s.my_char , " Hello" );
1313
14- struct_check (s);
14+ struct_check (& s);
1515
1616return EXIT_SUCCESS;
1717
You can’t perform that action at this time.
0 commit comments