Skip to content

Commit 7bfb924

Browse files
author
Bryan Henderson
committed
Silence compiler warnings, fix error in complex compare function.
1 parent 227015b commit 7bfb924

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

src/tutorial/C-code/complex.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/******************************************************************************
2+
This file contains routines that can be bound to a Postgres backend and
3+
called by the backend in the process of processing queries. The calling
4+
format for these routines is dictated by Postgres architecture.
5+
******************************************************************************/
6+
17
#include <stdio.h>
28
/* do not include libpq-fe.h for backend-loaded functions*/
39
/* #include "libpq-fe.h" */
@@ -11,6 +17,20 @@ typedef struct Complex {
1117
double y;
1218
} Complex;
1319

20+
/* These prototypes declare the requirements that Postgres places on these
21+
user written functions.
22+
*/
23+
Complex * complex_in(char *str);
24+
char * complex_out(Complex *complex);
25+
Complex * complex_add(Complex *a, Complex *b);
26+
bool complex_abs_lt(Complex *a, Complex *b);
27+
bool complex_abs_le(Complex *a, Complex *b);
28+
bool complex_abs_eq(Complex *a, Complex *b);
29+
bool complex_abs_ge(Complex *a, Complex *b);
30+
bool complex_abs_gt(Complex *a, Complex *b);
31+
int4 complex_abs_cmp(Complex *a, Complex *b);
32+
33+
1434
/*****************************************************************************
1535
* Input/Output functions
1636
*****************************************************************************/
@@ -48,7 +68,7 @@ complex_out(Complex *complex)
4868
return(NULL);
4969

5070
result = (char *) palloc(60);
51-
sprintf(result, "(%lg,%lg)", complex->x, complex->y);
71+
sprintf(result, "(%g,%g)", complex->x, complex->y);
5272
return(result);
5373
}
5474

@@ -131,6 +151,7 @@ complex_abs_cmp(Complex *a, Complex *b)
131151
* POSTGRES crashing, it is impossible to tell whether the bug is in your
132152
* code or POSTGRES's.
133153
*/
154+
void test_main(void);
134155
void
135156
test_main()
136157
{

src/tutorial/C-code/funcs.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,29 @@
1+
/******************************************************************************
2+
These are user-defined functions that can be bound to a Postgres backend
3+
and called by Postgres to execute SQL functions of the same name.
4+
5+
The calling format for these functions is defined by the CREATE FUNCTION
6+
SQL statement that binds them to the backend.
7+
*****************************************************************************/
8+
19
#include <string.h>
210
#include <stdio.h>
311
#include "postgres.h" /* for char16, etc. */
412
#include "utils/palloc.h" /* for palloc */
513
#include "libpq-fe.h" /* for TUPLE */
14+
#include "executor/executor.h" /* for GetAttributeByName() */
15+
16+
/* The following prototypes declare what we assume the user declares to
17+
Postgres in his CREATE FUNCTION statement.
18+
*/
19+
20+
int add_one(int arg);
21+
char16 * concat16(char16 *arg1, char16 *arg2);
22+
text * copytext(text *t);
23+
bool c_overpaid(TUPLE t, /* the current instance of EMP */
24+
int4 limit);
25+
26+
627

728
int
829
add_one(int arg)

0 commit comments

Comments
 (0)