Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > void pointers

Reply
Thread Tools

void pointers

 
 
bcpkh
Guest
Posts: n/a
 
      08-05-2008
Hello All

Hope someone can help me, please note that at first this might look as
if it is posted to the wrong group but if you ignore the specifics I
think it is general pointer referencing issue.

I am building a plug-in library and is passed, according to the
documentation the following;

'A pointer to the OCI environment handle and server context handle are
supplied via elements zero and one of ociEnvInfo respectively.
Implementations are free to ignore this parameter, and should do so
unless it is intended to use the Oracle connection of the calling
process.'

void init(void *ociEnvInfo )

What I have tried is the following;

OCIEnv *envhp; /*OCI environment handle*/
OCISvcCtx *svchp; /*Server context handle*/

void init(void *ociEnvInfo) {

envhp = (OCIEnv*)ociEnvInfo[0];
svchp = (OCISvcCtx*)ociEnvInfo[1];

}

This compiles fine but I keep on getting an OCI_INVALID_HANDLE
error which means I am probably not referencing the passed pointers
correctly.

Can someone please point me in the right direction.

Thank you,

B

PS: Running HP-UX on Itanium


 
Reply With Quote
 
 
 
 
santosh
Guest
Posts: n/a
 
      08-05-2008
bcpkh wrote:

> Hello All
>
> Hope someone can help me, please note that at first this might look as
> if it is posted to the wrong group but if you ignore the specifics I
> think it is general pointer referencing issue.
>
> I am building a plug-in library and is passed, according to the
> documentation the following;
>
> 'A pointer to the OCI environment handle and server context handle are
> supplied via elements zero and one of ociEnvInfo respectively.
> Implementations are free to ignore this parameter, and should do so
> unless it is intended to use the Oracle connection of the calling
> process.'
>
> void init(void *ociEnvInfo )


This is a syntax error.

> What I have tried is the following;
>
> OCIEnv *envhp; /*OCI environment handle*/
> OCISvcCtx *svchp; /*Server context handle*/
>
> void init(void *ociEnvInfo) {
>
> envhp = (OCIEnv*)ociEnvInfo[0];
> svchp = (OCISvcCtx*)ociEnvInfo[1];


Try:

envhp = ((OCIEnv*)ociEnvInfo)[0];
svchp = ((OCISvcCtx*)ociEnvInfo)[1];

>
> }
>
> This compiles fine but I keep on getting an OCI_INVALID_HANDLE
> error which means I am probably not referencing the passed pointers
> correctly.
>
> Can someone please point me in the right direction.
>
> Thank you,
>
> B
>
> PS: Running HP-UX on Itanium


 
Reply With Quote
 
 
 
 
bcpkh
Guest
Posts: n/a
 
      08-05-2008
Hello Santosh

I gave your suggestion a try but my compiler returns the following
error;

error #2852: expression must be a pointer to a
complete object type
envhp = ((OCIEnv*)ociEnvInfo)[0];
^

error #2852: expression must be a pointer to a
complete object type
svchp = ((OCISvcCtx*)ociEnvInfo)[1];
^
Any ideas?

> This is a syntax error.
>
> > What I have tried is the following;

>
> > OCIEnv * * * * * * * * * * * **envhp; /*OCI environment handle*/
> > OCISvcCtx * * * * * * *svchp; /*Server context handle*/

>
> > void init(void *ociEnvInfo) {

>
> > * envhp = (OCIEnv*)ociEnvInfo[0];
> > * svchp = (OCISvcCtx*)ociEnvInfo[1];

>
> Try:
>
> * envhp = ((OCIEnv*)ociEnvInfo)[0];
> * svchp = ((OCISvcCtx*)ociEnvInfo)[1];
>


 
Reply With Quote
 
Ike Naar
Guest
Posts: n/a
 
      08-05-2008
In article <(E-Mail Removed)>,
bcpkh <(E-Mail Removed)> wrote:
>'A pointer to the OCI environment handle and server context handle are
>supplied via elements zero and one of ociEnvInfo respectively.
>Implementations are free to ignore this parameter, and should do so
>unless it is intended to use the Oracle connection of the calling
>process.'
>
>void init(void *ociEnvInfo )
>
>What I have tried is the following;
>
>OCIEnv *envhp; /*OCI environment handle*/
>OCISvcCtx *svchp; /*Server context handle*/
>
>void init(void *ociEnvInfo) {
>
> envhp = (OCIEnv*)ociEnvInfo[0];
> svchp = (OCISvcCtx*)ociEnvInfo[1];
>
>}
>
>This compiles fine but I keep on getting an OCI_INVALID_HANDLE
>error which means I am probably not referencing the passed pointers
>correctly.


From your description I guess that init() expects an array of
pointers to void.
In your situation you want to pass an array of two pointers,
the first being a pointer to OCIEnv, the second being a pointer to OCISvcCtx.
If my assumption is wrong, please give more details, and ignore the rest
of this post.

The following works for me:

/* defining your types here as dummies, just to make it compile */
typedef struct OCIEnv_t OCIEnv;
typedef struct OCISvcCtx_t OCISvcCtx;

void init(void * vinfo)
{
void ** info = vinfo; /* treat passed vinfo as array of pointers to void */
OCIEnv * envhp = info[0];
OCISvcCtx * svchp = info[1];
/* more code */
}

void call_init(void)
{
OCIEnv * the_oci;
OCISvcCtx * the_svc;
void * the_info[2];
/* insert code that properly initializes the_oci and the_svc */
the_info[0] = the_oci;
the_info[1] = the_svc;
init(the_info);
}
 
Reply With Quote
 
Nick Keighley
Guest
Posts: n/a
 
      08-05-2008
On 5 Aug, 07:16, bcpkh <(E-Mail Removed)> wrote:

> Hope someone can help me, please note that at first this might look as
> if it is posted to the wrong group but if you ignore the specifics I
> think it is general pointer referencing issue.
>
> I am building a plug-in library and is passed, according to the
> documentation the following;
>
> 'A pointer to the OCI environment handle and server context handle are
> supplied via elements zero and one of ociEnvInfo respectively.
> Implementations are free to ignore this parameter, and should do so
> unless it is intended to use the Oracle connection of the calling
> process.'
>
> void init(void *ociEnvInfo )
>
> What I have tried is the following;
>
> OCIEnv * * * * * * * * **envhp; /*OCI environment handle*/
> OCISvcCtx * * * * * * * *svchp; /*Server context handle*/
>
> void init(void *ociEnvInfo) {
>
> * envhp = (OCIEnv*)ociEnvInfo[0];
> * svchp = (OCISvcCtx*)ociEnvInfo[1];
>
> }
>
> This compiles fine but I keep on getting an OCI_INVALID_HANDLE
> error which means I am probably not referencing the passed pointers
> correctly.


I really would try this on an Oracle group (they don't bite!).
The clc people seem to be guessing wildly. The Oracle people
may *really* know what's going on.


--
Nick Keighley

 
Reply With Quote
 
Barry Schwarz
Guest
Posts: n/a
 
      08-05-2008
On Mon, 4 Aug 2008 23:32:14 -0700 (PDT), bcpkh
<(E-Mail Removed)> wrote:

>Hello Santosh


Please don't top-post. Your response belongs immediately following
the text it relates to.

>
>I gave your suggestion a try but my compiler returns the following
>error;
>
>error #2852: expression must be a pointer to a
> complete object type


This error tells you the compiler does not know the details of what an
OCIEnv is. It is probably a structure of some kind but the
declaration of the structure, including all its members, is not in
scope.

> envhp = ((OCIEnv*)ociEnvInfo)[0];
> ^
>
>error #2852: expression must be a pointer to a
> complete object type


Ditto for OCISvcCtx.

> svchp = ((OCISvcCtx*)ociEnvInfo)[1];
> ^
>Any ideas?
>
>> This is a syntax error.
>>
>> > What I have tried is the following;

>>
>> > OCIEnv * * * * * * * * * * * **envhp; /*OCI environment handle*/
>> > OCISvcCtx * * * * * * *svchp; /*Server context handle*/

>>
>> > void init(void *ociEnvInfo) {


You don't show how you call this function. Since the argument is
apparently an array containing pointers of different types, the only
way that makes sense is an array of void pointers. In this case, the
correct parameter type would be void**. If this is not what your code
does, then we need to see how you call the function.

>>
>> > * envhp = (OCIEnv*)ociEnvInfo[0];
>> > * svchp = (OCISvcCtx*)ociEnvInfo[1];

>>
>> Try:
>>
>> * envhp = ((OCIEnv*)ociEnvInfo)[0];
>> * svchp = ((OCISvcCtx*)ociEnvInfo)[1];
>>


--
Remove del for email
 
Reply With Quote
 
Barry Schwarz
Guest
Posts: n/a
 
      08-05-2008
On Mon, 4 Aug 2008 23:16:56 -0700 (PDT), bcpkh
<(E-Mail Removed)> wrote:

>Hello All
>
>Hope someone can help me, please note that at first this might look as
>if it is posted to the wrong group but if you ignore the specifics I
>think it is general pointer referencing issue.
>
>I am building a plug-in library and is passed, according to the
>documentation the following;
>
>'A pointer to the OCI environment handle and server context handle are
>supplied via elements zero and one of ociEnvInfo respectively.
>Implementations are free to ignore this parameter, and should do so
>unless it is intended to use the Oracle connection of the calling
>process.'
>
>void init(void *ociEnvInfo )
>
>What I have tried is the following;
>
>OCIEnv *envhp; /*OCI environment handle*/
>OCISvcCtx *svchp; /*Server context handle*/
>
>void init(void *ociEnvInfo) {
>
> envhp = (OCIEnv*)ociEnvInfo[0];
> svchp = (OCISvcCtx*)ociEnvInfo[1];
>
>}
>
>This compiles fine but I keep on getting an OCI_INVALID_HANDLE


This cannot compile fine. [] binds tighter than (cast). The
expression is equivalent to (OCIEnv*)(ociEnfInfo[0]). You are
attempting to dereference ociEnvInfo. Since that variable is a
pointer to void, you cannot dereference it. Your compiler is required
to issue a diagnostic. If it does not, up the warning level or
upgrade to a competent implementation.

>error which means I am probably not referencing the passed pointers
>correctly.
>
>Can someone please point me in the right direction.
>
>Thank you,
>
>B
>
>PS: Running HP-UX on Itanium
>


--
Remove del for email
 
Reply With Quote
 
bcpkh
Guest
Posts: n/a
 
      08-05-2008
>
> You don't show how you call this function. *Since the argument is
> apparently an array containing pointers of different types, the only
> way that makes sense is an array of void pointers. *In this case, the
> correct parameter type would be void**. *If this is not what your code
> does, then we need to see how you call the function.
>
>
>
> >> > * envhp = (OCIEnv*)ociEnvInfo[0];
> >> > * svchp = (OCISvcCtx*)ociEnvInfo[1];

>
> >> Try:

>
> >> * envhp = ((OCIEnv*)ociEnvInfo)[0];
> >> * svchp = ((OCISvcCtx*)ociEnvInfo)[1];

>
> --
> Remove del for email


Unfortunately I don't call the function, the library that this
function sits in, an implementation of a published interface, gets
called by the process that loads the library, access to this
application is not possible.

Below a cut and paste from the supplied header;

void init(GER_t *pStatus,
void *ociEnvInfo[],
OMinfo_t *pInfo);

init gets called by the 'parent' process once when it starts and I
need to use the passed DB info to interact with the database.
 
Reply With Quote
 
bcpkh
Guest
Posts: n/a
 
      08-05-2008
On Aug 5, 9:12*am, blargg <(E-Mail Removed)> wrote:
> In article <g78rnd$(E-Mail Removed)>,
>
>
>
> *santosh <(E-Mail Removed)> wrote:
> > bcpkh wrote:
> > [...]
> > > 'A pointer to the OCI environment handle and server context handle are
> > > supplied via elements zero and one of ociEnvInfo respectively.
> > > Implementations are free to ignore this parameter, and should do so
> > > unless it is intended to use the Oracle connection of the calling
> > > process.'
> > > [...]
> > > OCIEnv * * * * * * * **envhp; /*OCI environment handle*/
> > > OCISvcCtx * * * * * * *svchp; /*Server context handle*/

>
> > > void init(void *ociEnvInfo) {

>
> > > * envhp = (OCIEnv*)ociEnvInfo[0];
> > > * svchp = (OCISvcCtx*)ociEnvInfo[1];

>
> > Try:

>
> > * envhp = ((OCIEnv*)ociEnvInfo)[0];
> > * svchp = ((OCISvcCtx*)ociEnvInfo)[1];

>
> (which also gives an error)
>
> Sounds like init is supposed to take a void**:
>
> void init(void **ociEnvInfo) {
>
> * envhp = ociEnvInfo[0];
> * svchp = ociEnvInfo[1];
>
> }
>
> If for some reason it's misdeclared to take a void* in the interface,
> then make a local variable that's a cast of the parameter:
>
> void init(void *param) {
>
> * void **ociEnvInfo = param;
> * envhp = ociEnvInfo[0];
> * svchp = ociEnvInfo[1];
>
> }
>
> Since this is C, there's no need to do any pointer casts as all the
> source operands are void*.


Have tried your suggestion but, compile fine but still getting the
OCI_INVALID_HANDLE error. Thanks.
 
Reply With Quote
 
santosh
Guest
Posts: n/a
 
      08-05-2008
bcpkh wrote:

>>
>> You don't show how you call this function. *Since the argument is
>> apparently an array containing pointers of different types, the only
>> way that makes sense is an array of void pointers. *In this case, the
>> correct parameter type would be void**. *If this is not what your
>> code does, then we need to see how you call the function.
>>
>>
>>
>> >> > envhp = (OCIEnv*)ociEnvInfo[0];
>> >> > svchp = (OCISvcCtx*)ociEnvInfo[1];

>>
>> >> Try:

>>
>> >> envhp = ((OCIEnv*)ociEnvInfo)[0];
>> >> svchp = ((OCISvcCtx*)ociEnvInfo)[1];

>>
>> --
>> Remove del for email

>
> Unfortunately I don't call the function, the library that this
> function sits in, an implementation of a published interface, gets
> called by the process that loads the library, access to this
> application is not possible.
>
> Below a cut and paste from the supplied header;
>
> void init(GER_t *pStatus,
> void *ociEnvInfo[],
> OMinfo_t *pInfo);
>
> init gets called by the 'parent' process once when it starts and I
> need to use the passed DB info to interact with the database.


You can do:

evnc_something_or_the_other_ptr = ociEnvInfo[0];

and similarly for the other one.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the difference between void proba(); and void proba(void); ??? PencoOdStip@gmail.com C++ 1 05-23-2007 07:12 PM
what is the difference, void func(void) and void fucn() noblesantosh@yahoo.com C Programming 5 07-22-2005 04:38 PM
void pointers & void function pointers Peter Goddard C Programming 3 05-16-2005 09:44 PM
"void Method()" vs "void Method(void)" Ollej Reemt C++ 7 04-22-2005 03:47 AM
`void **' revisited: void *pop(void **root) Stig Brautaset C Programming 15 10-28-2003 09:03 AM



Advertisments