void pointers

Discussion in 'C Programming' started by bcpkh, Aug 5, 2008.

  1. bcpkh

    bcpkh Guest

    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
     
    bcpkh, Aug 5, 2008
    #1
    1. Advertising

  2. bcpkh

    santosh Guest

    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
     
    santosh, Aug 5, 2008
    #2
    1. Advertising

  3. bcpkh

    bcpkh Guest

    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];
    >
     
    bcpkh, Aug 5, 2008
    #3
  4. bcpkh

    Ike Naar Guest

    In article <>,
    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.'
    >
    >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);
    }
     
    Ike Naar, Aug 5, 2008
    #4
  5. On 5 Aug, 07:16, bcpkh <> 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
     
    Nick Keighley, Aug 5, 2008
    #5
  6. On Mon, 4 Aug 2008 23:32:14 -0700 (PDT), bcpkh
    <> 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
     
    Barry Schwarz, Aug 5, 2008
    #6
  7. On Mon, 4 Aug 2008 23:16:56 -0700 (PDT), 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 )
    >
    >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
     
    Barry Schwarz, Aug 5, 2008
    #7
  8. bcpkh

    bcpkh Guest

    >
    > 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.
     
    bcpkh, Aug 5, 2008
    #8
  9. bcpkh

    bcpkh Guest

    On Aug 5, 9:12 am, blargg <> wrote:
    > In article <g78rnd$>,
    >
    >
    >
    >  santosh <> 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.
     
    bcpkh, Aug 5, 2008
    #9
  10. bcpkh

    santosh Guest

    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.
     
    santosh, Aug 5, 2008
    #10
  11. bcpkh <> writes:

    > 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.


    This suggests that your prototype for init is wrong. It should look
    the above. You were accessing the first parameter, whereas now it
    looks like thge seond is the one you want, and rather than being a
    void * it points to an array of void pointers. You function must look
    like the above if that is what the called expects.

    Note also that your previous code should have had errors saying, in
    effect, that the definition of init does not match its prototype. If
    you did not, then either you did not include this header (and it is
    probably a good thing to do that) or you have the warning level set
    rather low on your compiler.

    --
    Ben.
     
    Ben Bacarisse, Aug 5, 2008
    #11
  12. bcpkh

    CBFalconer Guest

    bcpkh 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 )


    You are definitely on the wrong group. We deal with standard C,
    and things programmable in standard C. You have omitted the source
    of the "OCI environment", without which there is no answer on this
    newsgroup. I believe that has something to do with Oracle, so you
    should find a newsgroup that deals with Oracle.

    --
    [mail]: Chuck F (cbfalconer at maineline dot net)
    [page]: <http://cbfalconer.home.att.net>
    Try the download section.
     
    CBFalconer, Aug 5, 2008
    #12
  13. CBFalconer <> writes:

    >> 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;

    <snip>
    > You are definitely on the wrong group. We deal with standard C,
    > and things programmable in standard C.


    That does not seem to be the case. For example, you discussed your
    allocator here and I doubt that is programmable in standard C.

    > You have omitted the source
    > of the "OCI environment", without which there is no answer on this
    > newsgroup.


    Enough has (now) been posted to suggest an answer that is topical --
    the OP's function does not match the prototype used to call it.

    > I believe that has something to do with Oracle, so you
    > should find a newsgroup that deals with Oracle.


    Yes, I agree. The OP will probably get better answers in an Oracle
    group, provided there is one populated with good C programmers.

    --
    Ben.
     
    Ben Bacarisse, Aug 5, 2008
    #13
  14. bcpkh

    CBFalconer Guest

    Ben Bacarisse wrote:
    > CBFalconer <> writes:
    >

    .... snip ...
    >
    >> You are definitely on the wrong group. We deal with standard C,
    >> and things programmable in standard C.

    >
    > That does not seem to be the case. For example, you discussed your
    > allocator here and I doubt that is programmable in standard C.


    Huh? What is this 'allocator' jazz? One of us is confused.

    --
    [mail]: Chuck F (cbfalconer at maineline dot net)
    [page]: <http://cbfalconer.home.att.net>
    Try the download section.
     
    CBFalconer, Aug 5, 2008
    #14
  15. bcpkh

    santosh Guest

    CBFalconer wrote:

    > Ben Bacarisse wrote:
    >> CBFalconer <> writes:
    >>

    > ... snip ...
    >>
    >>> You are definitely on the wrong group. We deal with standard C,
    >>> and things programmable in standard C.

    >>
    >> That does not seem to be the case. For example, you discussed your
    >> allocator here and I doubt that is programmable in standard C.

    >
    > Huh? What is this 'allocator' jazz? One of us is confused.


    Nmalloc presumably.
     
    santosh, Aug 5, 2008
    #15
  16. CBFalconer <> writes:

    > Ben Bacarisse wrote:
    >> CBFalconer <> writes:
    >>

    > ... snip ...
    >>
    >>> You are definitely on the wrong group. We deal with standard C,
    >>> and things programmable in standard C.

    >>
    >> That does not seem to be the case. For example, you discussed your
    >> allocator here and I doubt that is programmable in standard C.

    >
    > Huh? What is this 'allocator' jazz? One of us is confused.


    I agree.

    --
    Ben.
     
    Ben Bacarisse, Aug 5, 2008
    #16
  17. On Tue, 5 Aug 2008 03:19:23 -0700 (PDT), bcpkh
    <> wrote:

    snip

    >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.


    Now that you have shown us the true signature of the function,
    everything you coded before invokes undefined behavior and the
    previous recommendations you received from this group were based on a
    false assumption that led, for the most part, to undefined behavior.

    When you code your function to match this signature, statements of the
    form
    envhp = ociEnvInfo[0];
    svchp = ociEnvInfo[1];
    will be both syntactically and logically correct as long as the target
    variables have the correct type.

    What you do with them as well as what you do with the other parameters
    needs to be discussed in a topical newsgroup (someone mentioned
    Oracle). Once you know what to do with them, questions about how to
    do it in standard C can be asked here but odds are the real expertise
    will still reside in that topical newsgroup.

    --
    Remove del for email
     
    Barry Schwarz, Aug 5, 2008
    #17
  18. bcpkh

    bcpkh Guest

    On Aug 5, 7:23 pm, Barry Schwarz <> wrote:
    > On Tue, 5 Aug 2008 03:19:23 -0700 (PDT), bcpkh
    >
    > <> wrote:
    >
    > snip
    >
    > >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.

    >
    > Now that you have shown us the true signature of the function,
    > everything you coded before invokes undefined behavior and the
    > previous recommendations you received from this group were based on a
    > false assumption that led, for the most part, to undefined behavior.
    >
    > When you code your function to match this signature, statements of the
    > form
    >     envhp = ociEnvInfo[0];
    >     svchp = ociEnvInfo[1];
    > will be both syntactically and logically correct as long as the target
    > variables have the correct type.
    >
    > What you do with them as well as what you do with the other parameters
    > needs to be discussed in a topical newsgroup (someone mentioned
    > Oracle).  Once you know what to do with them, questions about how to
    > do it in standard C can be asked here but odds are the real expertise
    > will still reside in that topical newsgroup.
    >
    > --
    > Remove del for email


    Thank you for all the replies and suggestions, like I said might be
    the wrong group but I did receive new insight into my problem. Thanks.

    B
     
    bcpkh, Aug 6, 2008
    #18
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ollej Reemt
    Replies:
    7
    Views:
    568
    Jack Klein
    Apr 22, 2005
  2. Stig Brautaset

    `void **' revisited: void *pop(void **root)

    Stig Brautaset, Oct 25, 2003, in forum: C Programming
    Replies:
    15
    Views:
    812
    The Real OS/2 Guy
    Oct 28, 2003
  3. Peter Goddard

    void pointers & void function pointers

    Peter Goddard, May 16, 2005, in forum: C Programming
    Replies:
    3
    Views:
    527
    Peter Goddard
    May 16, 2005
  4. Replies:
    5
    Views:
    850
    S.Tobias
    Jul 22, 2005
  5. Replies:
    1
    Views:
    419
    Victor Bazarov
    May 23, 2007
Loading...

Share This Page