Thread: dereferencing pointer to incomplete type

  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    50

    dereferencing pointer to incomplete type

    Hi

    Can anyone tell me why following error gets generated?

    "dereferencing pointer to incomplete type"

    What does it mean and what is its exact reason?

    Thanks in advance
    Sas

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    It sounds like only the declaration of the type is available at that point; the type definition must be available to, otherwise you cannot access an object of that type (though you can have a pointer to it).
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jan 2010
    Posts
    50
    Thanks for you reply..

    What i am trying to acomplish is i am fetching some records from database and putting that records in dynamically generated pointer array and returning the pointer to main function. In the main function i am trying to get the value oif the structure member by dereferencing.While compiling the code i am getting the error.

    Can you please help me what went wrong in the code..

    The structure is declared in a0TargInp.h header file
    Code:
    #include <stdio.h>
    #include <string.h>
    #include <sqlda.h>
    #include <sqlcpr.h>
    #include <stdlib.h>
    #include "a0TargInp.h"
    
    EXEC SQL INCLUDE SQLCA.H;
    /*
    struct a0_targ_inp
            {
            char equip_cd[10];
            float min_chg;
            float max_chg;
            float ao_incv;
            char apply_cnstrn_flag[4];
            char hard_cnstrn_flag[4];
            int bank_start;
            int bank_end;
            };
    
    struct a0_targ_inp * getA0TargInp();
    */
    int main()
    {
    
    
    
            struct ao_targ_inp * a0,a0_data=NULL;
    
            int cnt,i;
    
            a0=(struct ao_targ_inp *)calloc(1,sizeof(a0_data));
    
    /*
            struct a0_targ_inp * getA0TargInp();
    */
            dbConnect();
    
            cnt=getRecordCount();
            a0=getA0TargInp();
    
    
            for(i=0;i<cnt;i++)
            {
    
                    printf("\n %s  %f  %f  %f  %s  %s  %d  %d\n",a0->equip_cd, a0->min_chg,a0->max_chg,a0->ao_incv,a0->apply_cnstrn_flag,a0->hard_cnstrn_flag,a0->bank_start,a0->bank_end);
    
                    a0=a0+1;
            }
    
    
    
            free(a0);
            EXEC SQL COMMIT WORK RELEASE;
            return 0;
    
    
    
            errexit:
    
            printf("\nConnection failed\n");
    
            return 0;
    
            sqlerr:
            printf("\n SQL error occured during execution of sql\n");
    
    
    }
    
    struct a0_targ_inp * getA0TargInp()
    {
    
    
    
    
            int i=0;
    
            struct a0_targ_inp * a0,*tmp,a0_data;
    
    
           EXEC SQL DECLARE get_a0_targ_inp CURSOR FOR
                    SELECT b.equip_cd,
                          a.minm_a0_chg_allw,
                          a.max_a0_chg_allw,
                          a.a0_inctv,
                          a.apply_cnstrn_flag,
                          a.hard_cnstrn_flag,
                          a.bank_start,
                          a.bank_end
                    FROM a0_targ_inp a,a0_targ_inp_equip b
                    WHERE a.A0_TARG_INP_ID=b.a0_targ_inp_id
                    AND a.da_mon='Y'
                    AND a.da_tue='Y'
                    AND a.da_wed='Y'
                    AND a.da_thur='Y'
                    AND a.da_fri='Y'
                    AND a.da_sat='Y'
                    AND a.da_sun='Y'
                    AND a.eff_dt<='12-OCT-10'
                    AND a.discont_dt>='12-OCT-10'
                    AND b.EQUIP_GRP_FLAG='N'
                    OR b.equip_grp_flag='Y';
    
            EXEC SQL WHENEVER sqlerror DO  printSQLError();
    
    
            a0=(struct ao_targ_inp *)calloc(cnt,sizeof(a0_data));
            tmp=a0;
    
    
            EXEC SQL OPEN get_a0_targ_inp;
    
    
            EXEC SQL WHENEVER NOT FOUND DO break;
    
            for(;;)
            {
                    EXEC SQL FETCH get_a0_targ_inp INTO :a0;
                    a0=a0+1;
            }
    
    
            EXEC SQL CLOSE get_a0_targ_inp;
              return tmp;
    
    }
    
    void dbConnect()
    {
    
            EXEC SQL BEGIN DECLARE SECTION;
    
            char oracleid[50]="sdouser01/sdoual1@SDO_DEV_LINUX";
    
            EXEC SQL END DECLARE SECTION;
    
            EXEC SQL WHENEVER sqlerror DO printError();
            EXEC SQL CONNECT :oracleid;
    
    
    }
    
    
    
    int getRecordCount()
    {
    
            EXEC SQL BEGIN DECLARE SECTION;
             int cnt=0;
            EXEC SQL END DECLARE SECTION;
    
    
    
            EXEC SQL WHENEVER sqlerror DO  printSQLError();
    
              EXEC SQL SELECT COUNT(*) INTO :cnt FROM ( SELECT b.equip_cd,
                  a.minm_a0_chg_allw,
                  a.max_a0_chg_allw,
                  a.a0_inctv,
                  a.apply_cnstrn_flag,
                  a.hard_cnstrn_flag,
                  a.bank_start,
                  a.bank_end
            FROM a0_targ_inp a,a0_targ_inp_equip b
            WHERE a.A0_TARG_INP_ID=b.a0_targ_inp_id
            AND a.da_mon='Y'
            AND a.da_tue='Y'
            AND a.da_wed='Y'
            AND a.da_thur='Y'
            AND a.da_fri='Y'
            AND a.da_sat='Y'
            AND a.da_sun='Y'
            AND a.eff_dt<='12-OCT-10'
            AND a.discont_dt>='12-OCT-10'
            AND b.EQUIP_GRP_FLAG='N'
            OR b.equip_grp_flag='Y');
    
            return cnt;
    }
    
    void printError()
    {
    
            printf("\n Unable to connect to database\n");
    
    }
    
    void printSQLError()
    {
    
            printf("\n Error ocurred during execution of SQL\n");
    
    }
    Header file( a0TargInp.h
    ) is as below

    Code:
    struct a0_targ_inp
            {
            char equip_cd[10];
            float min_chg;
            float max_chg;
            float ao_incv;
            char apply_cnstrn_flag[4];
            char hard_cnstrn_flag[4];
            int bank_start;
            int bank_end;
            };
    
    struct a0_targ_inp * getA0TargInp();

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. error: dereferencing pointer to incomplete type
    By kiros88 in forum C Programming
    Replies: 4
    Last Post: 09-16-2009, 02:43 PM
  2. error: dereferencing pointer to incomplete type
    By surlyTomato in forum C Programming
    Replies: 10
    Last Post: 08-22-2009, 08:04 AM
  3. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  4. Replies: 5
    Last Post: 04-04-2009, 03:45 AM
  5. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 03:49 PM