#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    10
    Rep Power
    0

    Improper Pointer/integer combination: cIndex


    Hi guys

    Getting a few warning when trying to compile the following code
    Code:
    extern void GetMBJobData( fh, iDrv, iOccType)
     FH *fh;
     int iDrv;
     int iOccType;
    {
            ABIDATA adt;
            long lLoRec = 0L, lHiRec;
            uchar Index[ 4];
            FILE *FpMBJob;
    
            driver.occflag[ iDrv][ 0] = 0;
    
            FpMBJob = setpath( fh, "MBABIJOB.TAB", "rb");
            if( !FpMBJob) err( _ET_FATAL, _ER_OPENFILE, "MBABIJOB.TAB");
    
            lHiRec = NumRecs( FpMBJob, (long)sizeof( adt.mcjobs));
    
            strcpy( cIndex, abiocc.occcode[ iDrv]);
    
            if( !LocateData( FpMBJob, cIndex, lLoRec, lHiRec,
                    (long)sizeof( adt.mcjobs), (long)sizeof(adt.mcjobs.code),adt.buff))
            {
    #ifdef POL
                    MapAbiError( fh, cIndex, sizeof(adt.mcjobs.code),"driver.occflag");
    #else
                    err( _ET_FATAL, _ER_FUNC, "GetMBJobData()");
    #endif
            }
    
            ASTR( mcjobs, flags, driver.occflag[ iDrv]);
    
            close_file( FpMBJob);
            return;
    }
    The warnings are as follows
    UX:i386acomp: ERROR: "blah.c", line 444: error: undefined symbol: cIndex
    UX:i386acomp: WARNING: "blah.c", line 444: warning: improper pointer/integer combination: arg #1
    UX:i386acomp: WARNING: "blah.c", line 447: warning: improper pointer/integer combination: arg #2
    I've been looking over it but I can't see what is causing these errors other than maybe... the casting type of cIndex?

    Could someone please help am a bit stuck.

    Thanks
    Jim
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,145
    Rep Power
    2222
    Where did you dig up that ancient code from? That is K&R code, not ANSI C. K&R was replaced by ANSI C in 1989, over 20 years ago. At that time, compilers would allow you the option of compiling K&R, but I know of no modern compiler that will still allow K&R code.

    Trying to compile K&R code will generate all kinds of errors and warnings that will appear spurious. Convert your code to ANSI C and then compile that.

    Also, you gave us no indication of which lines are Line 444 and Line 447. And if those lines involve a function call, then you also need to provide us with that function's prototype.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    10
    Rep Power
    0
    My apologies, likes 444 and 447 are the following
    Line 444:
    Code:
     strcpy( cIndex, abiocc.occcode[ iDrv]);
    and

    Line 447:
    Code:
    if( !LocateData( FpMBJob, cIndex, lLoRec, lHiRec,(long)sizeof( adt.mcjobs), (long)sizeof(adt.mcjobs.code),adt.buff))
    LocateData Prototype
    Code:
    short   LocateData( FILE *, uchar *, long, long, long, long, uchar *);
    LocateData Function
    Code:
    short LocateData( fp, cIndex, lLoRec, lHiRec, lSizeRec, lSizeIdx, cBuff)
     FILE *fp;
     uchar *cIndex;
     long lLoRec;
     long lHiRec;
     long lSizeRec;
     long lSizeIdx;
     uchar *cBuff;
    {
            int strval = 0, count = 0;
            long lRec = 0L, lOldRec = 0L, lPos = 0L;
    
            do
            {
                    lRec = (long)((( lHiRec-lLoRec) / 2L)+ lLoRec);
    
                    if( lRec == lHiRec || lRec == lOldRec)
                            return( FALSE);
    
                    lOldRec = lRec;
    
                    lPos = lRec * lSizeRec;
    
                    if( !ReadRec( fp, cBuff, lPos, lSizeRec))
                            return( FALSE);
    
                    cBuff[ lSizeRec] = 0;
                    strval = strncmp( cIndex, cBuff, lSizeIdx);
    
                         if( strval == 0) return( TRUE);
                    else if( strval  < 0) lHiRec  = lRec;
                    else                  lLoRec  = lRec;
    
                    count++;
            }while( count < 30);
    
            return( FALSE);
    }
    As you have advised this is legacy stuff, which is why I'm looking at it as I am doing an overhaul of the programs written... converting everything to ANSI sounds like a good idea, however there is over 2000+ .c files (not to mention headers) each with about 3000+ lines of code. That's why I'm struggling, everything is still running on SCO Unix OpenServer, it is pretty archaic.
  6. #4
  7. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,145
    Rep Power
    2222
    Read that error message again:
    UX:i386acomp: ERROR: "blah.c", line 444: error: undefined symbol: cIndex
    UX:i386acomp: WARNING: "blah.c", line 444: warning: improper pointer/integer combination: arg #1
    UX:i386acomp: WARNING: "blah.c", line 447: warning: improper pointer/integer combination: arg #2
    I was about to ask what cIndex is declared to be, since I couldn't find its declaration in the code you posted. Then I looked at the messages again and saw that you don't declare it. C's legacy behavior towards undeclared functions and variables is to assume that they're of type int. So instead of passing a char pointer, which I guess you assume cIndex to be, the compiler sees you trying to pass an int, which raised those warnings.

    Declare cIndex. And since it's receiving data in that strcpy call, make sure that there's sufficient memory associated with it. I'm assuming that you're going to declare it as an array, though it could be a pointer that has had memory malloc/calloc'd to it.

    As for the K&R issue, as long as this is staying on an archaic system and you have an archaic compiler that can handle K&R, there shouldn't be any need to convert the code to ANSI C at this time. For one thing, there would be the risk of introducing bugs in that process. However, if you are ever going to migrate this software to a more modern platform, then you would eventually need to consider that conversion.

    SUGGESTION: When you post code here again, remember to state in the beginning that this is indeed K&R code and that it's on a legacy system. That should help to keep us from pointing out that it's K&R code as I did.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    10
    Rep Power
    0
    Thanks for all your help, only another 1400+ warnings and couple of errors to go, turns out that the genius who built this engine just decided to declare the character arrays as he saw fit, so some functions are expecting unsigned char arrays and other signed but using the same variable. The biggest problem I face currently is the oldest in the book... lazy copy'n'paste coding. :mad:

    Cheers
    Jim

    Comments on this post

    • clifford disagrees : You don't close the thread because you think you have an answer! You reserve that for when the thread ceases to be useful (like it descends into a flame war for example). I had something useful to tell you, but I guess you'll never know now!
  10. #6
  11. Contributing User

    Join Date
    Aug 2003
    Location
    UK
    Posts
    5,109
    Rep Power
    1802
    444 lines appear before this one, and in not one of them have you defined a uchar* variable called cIndex. The error message is entirely clear.

    The warnings may well go away once you have cleared the error, but it is not clear that they are not caused by something else without sight of the data types involved.

    My guess is that the ancient compiler you must be using to compile this antique code assumes that undeclared variables are of type int and then attempts to make sense of the remaining code on that basis. Applying what has been implicitly declared as int to a uchar* then produces a warning.

    Always fix errors and warnings from the top. Very often one will propagate many, so fixing the first often fixes messages that follow.

IMN logo majestic logo threadwatch logo seochat tools logo