Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Using Oracle ProC/C++ and Use of Global Variables

Re: Using Oracle ProC/C++ and Use of Global Variables

From: Mark Miller <mmille10_at_earthlink.net>
Date: 1998/11/25
Message-ID: <365C9127.1A79@earthlink.net>#1/1

bryankim_at_netspace.org wrote:
>
> The following is a problem I've encountered with use of global variables and
> ProC and after hitting a wall, I would greatly appreciate any input on the
> following question:
>
> I am writing a C++ program which uses a BEGIN DECLARE SECTION to declare all
> the host variables I use throughout the program. In order to make the
> variables global, the DECLARE SECTION is placed outside of main within the
> main.C file. The problem I'm encountering is how to make globally declared
> host variables accessible to other .H and .C files.

I am not familiar with the specific situation you are talking about (using global host variables in a C++ environment), but a coworker ran into a similar problem using the C language. I recommended doing this:

EXEC SQL BEGIN DECLARE SECTION;
#include "headers.h"
EXEC SQL END DECLARE SECTION; and doing it in each file where they were needed. I never found out whether this worked or not, but it's worth a try.

Another method, and one that is better from a design standpoint, would be to define access routines, and make your globals be module scope, instead of actually making them global. Here is a C example:

in module1.c:

EXEC SQL BEGIN DECLARE SECTION;
static char a[5];
EXEC SQL END DECLARE SECTION; char *GetA(void)

   {
   return &a; /* not sure if you need to get the address of "a" here, but just in */

              /* case... */
   }

in module2.c:

#include <string.h>

#include "module1.h" /* contains prototype for GetA() */

EXEC SQL BEGIN DECLARE SECTION;
static char b[5];
EXEC SQL END DECLARE SECTION; static void ModuleBRout(void)

   {
   strcpy(b, GetA());
   }

---Mark
mmiller_at_nyx.net Received on Wed Nov 25 1998 - 00:00:00 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US