Subject: User Defined Functions...

From: Ravi Lingam <[email-masked]>
Date: Thu, 5 Aug 93 13:15:50 EDT

Hi!

When I tried to compile my C code, I got the 
error messages as shown below. 

I appeciate any suggestions in this regard. 

Thanks
R. Lingam 
###############################################
# Error messages 
###############################################
[c] ->gcc -c -I. -I/store3/postgres/src/lib/H s.c
In file included from ./tmp/libpq-fe.h:21, from s.c:2:
./tmp/libpq.h:215: warning: `struct sockaddr_in' declared inside parameter list
./tmp/libpq.h:215: warning: its scope is only this definition or declaration,
./tmp/libpq.h:215: warning: which is probably not what you want.
./tmp/libpq.h:216: warning: `struct sockaddr_in' declared inside parameter list

###############################################
# C code 
###############################################
/* My function */ 
#include <stdio.h>
#include <tmp/libpq-fe.h> 
#include <tmp/postgres.h>

bool vout(TUPLE);

bool
vout(t)
TUPLE t; 
{ 
  extern char *GetAttributeByName();
  int4 value; 
  oid left; 
  
  value = (int4) GetAttributeByName(t, "value");
  left = (oid) GetAttributeByName(t, "left"); 
  
  if (value > 4)
    return(TRUE);
  return(FALSE); 
}

---

From: [email-masked] (James Woods 61-89-895257)
Date: Thu, 5 Aug 93 18:41:42 -0700

> ./tmp/libpq.h:216: warning: `struct sockaddr_in' declared inside parameter list

This problem is caused by the fact that gcc is an ANSI compiler and I thing that
in general postgres has been written and tested with a non ANSI compiler, but
an attempt to support ANSI has been made in the include files.  I remmember this
particular error from 4.0.1 but it has been fixed in 4.1.  What you need to do
is find the include file which defines `struct sockaddr_in' and include in
tmp/libpq-fe.h.

I do have a number of patches to get 4.1 to work with gcc (though I gave up
trying to compile postgres itself with gcc) but I have forgotten what I did
for 4.0.1.

James Woods
[email-masked]

---

From: [email-masked] (James Woods 61-89-895257)
Date: Tue, 10 Aug 93 15:42:52 -0700

I just found the patches I made to fix this bug:

$ diff -c ./src/backend/tmp/libpq.h ./src/backend/tmp/libpq.orig.h
*** ./src/backend/tmp/libpq.h   Tue Apr 13 13:18:40 1993
--- ./src/backend/tmp/libpq.orig.h      Tue Aug  4 03:47:51 1992
***************
*** 22,28 ****
  #include <stdio.h>
  #include <string.h>
  #include <sys/types.h>
- #include <netinet/in.h> /* jaws:24/3/93 added in for sockaddr_in */
  #include "tmp/simplelists.h"
  #include "utils/exc.h"
  
--- 22,27 ----

you will of course have to propogate this change to:
./include/libpq.h
./include/tmp/libpq.h

If you don't have access to change the postgres include files, hassle your 
sys-admin and in the meantime just include netinet/in.h before the rest of the postgres include files in your code.

I can't help you as far as switching off warnings within the file in gcc, but I
think the above will solve your problems.

While I'm at it here are a few more patches for 4.1:

$ diff tmp/c.orig.h tmp/c.h -c
*** tmp/c.orig.h        Tue Feb 23 05:57:38 1993
--- tmp/c.h     Tue Apr 13 13:53:49 1993
***************
*** 473,479 ****
          char    *p
  ));
  #else /* PALLOC_DEBUG */
! #if defined(PORTNAME_bsd44) || defined(PORTNAME_alpha)
  #include <stdlib.h>
  #else
  extern
--- 473,479 ----
          char    *p
  ));
  #else /* PALLOC_DEBUG */
! #if defined(PORTNAME_bsd44) || defined(PORTNAME_alpha) || defined(__GNUC__)
  #include <stdlib.h>
  #else
  extern

$ diff tmp/postgres.orig.h tmp/postgres.h -c
*** tmp/postgres.orig.h Mon Apr 19 08:27:29 1993
--- tmp/postgres.h      Mon Apr 19 08:29:13 1993
***************
*** 525,531 ****
--- 525,533 ----
   * ----------------------------------------------------------------
   */
  
+ #ifndef X_H
  typedef uint32        Time;                   /* XXX this will disappear */
+ #endif
  
  typedef uint32        RelativeTime;
  #define InvalidRelativeTime   0
***************
*** 550,556 ****
--- 552,560 ----
   *            Section 8: old types being obsoleted
   * ----------------------------------------------------------------
   */
+ #ifndef X_H
  typedef       long    XID;
+ #endif
  #define       CID     unsigned short
  #define       ABSTIME long
  #define       RELTIME long

James Woods

---

From: Ranen Goren <[email-masked]>
Date: Thu, 12 Aug 1993 19:00:46 +0300

Thanks for the patches!

	Ranen