We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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); }
Thanks for all your suggestions. Sorry about the <pre > problems with my posts. I tried the PREPRINT that was suggested. The resultant preprocessor file had no reference to ellipsis_40 at all. Worth a shot, but.... Thank you Mark Odell for the last printf example you posted. I think I can figure it out from here. Did you see anything wrong with the way I implemented va_ macros? I realize I was half-*ssed doing it--in an effort to retain as much original code as possible, but it 'seemed' to work (I have yet to try on target hardware). Before this week I had never heard of or seen an ellipsis. Thanks for all your insights..... Paul
Paul, I did see something wrong with your use of va_* macros:
argList[0] = va_arg(vargList, Byte); argPtr = &argList[0]; if(*fmtPtr == 'c'){ **(char **)argPtr = *inBfrPtr; // How you can add 3 to a void pointer is beyond me, // C doesn't know how to scale with void pointers. argPtr += 3;
char one, two; short three; long four; one = va_arg(vargList, char); two = va_arg(vargList, char); three = va_arg(vargList, short); four = va_arg(vargList, long);
Paul, Have you ever used printf in your programs? If so, you have used a function with a variable length argument list. That's what the ...'s are. Jon