This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Ellipsis use with C51 for 8051


I have some legacy code that was originally compiled with Franklin and it also compiles with my Keil compiler. The problem is that the source code does some things that make no sense and I cannot find any documentation in my Keil manuals or on the website about this topic. I want to ensure that 1) the code still operates the same using Keil vs Franklin compiler 2) I understand how it works. The manuals reference va_start,va_end macros. Can the code below be written to use those macros? How? If so, would this be a better option? Looking at the ouput src file, it appears that keil makes a undocumented library call.

I look forward to your inputs.

Thanks,

Paul Calvert
256-704-4134

Here is the code snipet:

int sscanf(char *inBfrPtr, char *fmtPtr, ...)
{
Byte scanResult = 0;
void *argPtr = &ellipsis_40; //THIS IS THE STATEMENT THAT I CAN FIND NO REFERNCE TO: ELLIPSIS_40. THERE ARE NO MACROS OR OTHER DECLARATIONS ANYWHERE IN MY CODE REFERENCING "ELLIPSIS_"
register char tmpDigit;

while(1){
if(*fmtPtr == '\0')
break;
else if(*fmtPtr == '%'){
fmtPtr++;
if(*fmtPtr == 'c'){
**(char **)argPtr = *inBfrPtr;
argPtr += 3;
fmtPtr++;
inBfrPtr++;
scanResult += 1;
continue;
}
else if(*fmtPtr == 'd'){
if(inBfrPtr[0] == '+' || inBfrPtr[0] == '-')
tmpDigit = inBfrPtr[1];
else
tmpDigit = inBfrPtr[0];
if(tmpDigit >= '0' && tmpDigit <= '9'){
**(int **)argPtr = atoi(inBfrPtr);
while(1){
inBfrPtr++;
if(inBfrPtr[0] < '0' || inBfrPtr[0] > '9')
break;
}
fmtPtr++;
argPtr += 3;
scanResult += 1;
continue;
}
else
break;
}
else if(*fmtPtr == '%'){
/* fall through to continue string comparison */
}
else{ /* unknown format specifier */
break;
}
}
if(*fmtPtr++ != *inBfrPtr++)
break;
}
return(scanResult);
}

Parents
  • Could you not just use the standard sscanf from the Keil library?

    You first need to understand how the legacy code was supposed to work; for that you'll need to look in the Franklin manuals - you can't expect Keil to document Franklin's implementation-specific details! ;-)

    My guess is that ellipsis_40 is specific to Franklin's implementation of variable-length argument lists.

    Keil implements the standard va_arg, va_end and va_start functions - see the Keil C51 User's Guide, and K&R.

    BTW: your code would look better if you enclosed it within &ltpre&gt and &lt/pre&gt tags - see "Tips for Posting," http://www.keil.com/forum/tips.asp

Reply
  • Could you not just use the standard sscanf from the Keil library?

    You first need to understand how the legacy code was supposed to work; for that you'll need to look in the Franklin manuals - you can't expect Keil to document Franklin's implementation-specific details! ;-)

    My guess is that ellipsis_40 is specific to Franklin's implementation of variable-length argument lists.

    Keil implements the standard va_arg, va_end and va_start functions - see the Keil C51 User's Guide, and K&R.

    BTW: your code would look better if you enclosed it within &ltpre&gt and &lt/pre&gt tags - see "Tips for Posting," http://www.keil.com/forum/tips.asp

Children
  • Cannot use the std library because cannot make library calls during program code reload.

    I am puzzled HOW Keil compiles this without warning or error --given no ellipsis documentation AT ALL. Keil should not document Franklin specific macros or library calls, but if it compiles under Keil, it should have documentation, no?

    I am still searching.... Thanx.

  • Sorry, I hadn't realised that this was actually compiling under Keil!

    "but if it compiles under Keil, it should have documentation, no?"

    Unfortunately, I'm afraid that's a little naive.
    I've seen too many projects where "clever" programmers have somehow discovered - and relied upon - undocumented features of their specific compiler release. Such "cleverness" is highly likely to trip you up when the compiler is upgraded, and almost certainly if you need to change compilers!