November 12th, 2013, 04:58 AM
Improper Pointer/integer combination: cIndex
Getting a few warning when trying to compile the following code
The warnings are as follows
I've been looking over it but I can't see what is causing these errors other than maybe... the casting type of cIndex?
extern void GetMBJobData( fh, iDrv, iOccType)
long lLoRec = 0L, lHiRec;
uchar Index[ 4];
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))
MapAbiError( fh, cIndex, sizeof(adt.mcjobs.code),"driver.occflag");
err( _ET_FATAL, _ER_FUNC, "GetMBJobData()");
ASTR( mcjobs, flags, driver.occflag[ iDrv]);
Could someone please help am a bit stuck.
November 12th, 2013, 10:32 AM
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.
November 12th, 2013, 11:29 AM
My apologies, likes 444 and 447 are the following
strcpy( cIndex, abiocc.occcode[ iDrv]);
if( !LocateData( FpMBJob, cIndex, lLoRec, lHiRec,(long)sizeof( adt.mcjobs), (long)sizeof(adt.mcjobs.code),adt.buff))
short LocateData( FILE *, uchar *, long, long, long, long, uchar *);
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.
short LocateData( fp, cIndex, lLoRec, lHiRec, lSizeRec, lSizeIdx, cBuff)
int strval = 0, count = 0;
long lRec = 0L, lOldRec = 0L, lPos = 0L;
lRec = (long)((( lHiRec-lLoRec) / 2L)+ lLoRec);
if( lRec == lHiRec || lRec == lOldRec)
lOldRec = lRec;
lPos = lRec * lSizeRec;
if( !ReadRec( fp, cBuff, lPos, lSizeRec))
cBuff[ lSizeRec] = 0;
strval = strncmp( cIndex, cBuff, lSizeIdx);
if( strval == 0) return( TRUE);
else if( strval < 0) lHiRec = lRec;
else lLoRec = lRec;
}while( count < 30);
November 12th, 2013, 11:55 AM
Read that error message again:
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.
November 12th, 2013, 12:17 PM
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:
Comments on this post
November 12th, 2013, 12:24 PM
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.