Other Parts Discussed in Thread: LAUNCHXL-F28379D
Tool/software: TI C/C++ Compiler
I am observing problems with the following code (extracted from a scanf-implementation):
#include <stdarg.h>
#include <stdlib.h>
#include <ctype.h>
int my_sscanf(const char *s, char *f, ...) {
va_list ap;
int nvars = 0;
va_start(ap, f);
while (*f) {
int lflag = 0, flen = -1, basis = 10;
unsigned long ulval = 0;
while (!(*s==0 || !isspace(*s))) s++;
switch (*f) {
case '%':
if (isdigit(*++f)) {
flen = atoi(f);
while (isdigit(*f)) f++;
}
if (*f == 'l') {f++; lflag = 1;}
switch (*f++) {
case 'X' :
case 'x' : basis = 16;
case 'u' :
while (flen-- && (isdigit(*s) || basis==16 && isxdigit(*s))) {
int d = *s>='a' ? *s-'a'+10 : *s>='A' ? *s-'A'+10 : *s-'0';
ulval = ulval*basis+d;
s++;
}
if (lflag)
*((unsigned long *)va_arg(ap, unsigned long *)) = ulval;
else
*((unsigned *)va_arg(ap, unsigned *)) = (unsigned) ulval;
if (flen <= 0) nvars++;
break;
}
}
}
va_end(ap);
return nvars;
}
unsigned long lval = 0;
unsigned val = 0;
/**
* main.c
*/
int main(void)
{
my_sscanf("42 24", "%lu%u", &lval, &val);
return 0;
}
When compiled with
"C:/ti/ccsv7/tools/compiler/ti-cgt-c2000_16.9.8.LTS/bin/cl2000" -v28 -ml -mt --cla_support=cla1 --float_support=fpu32 --tmu_support=tmu0 --vcu_support=vcu2 -O2 --opt_for_speed=3 --include_path="C:/ti/ccsv7/tools/compiler/ti-cgt-c2000_16.9.8.LTS/include" -g --diag_warning=225 --diag_wrap=off --display_error_number --preproc_with_compile --preproc_dependency="main.d_raw" "../main.c"
and run on a LAUNCHXL-F28379D I'm getting only the first digits of the two numbers 42 and 24 in lval and val respectively.
When compiled with --opt_for_speed values less than 3 I'm getting the expected numbers.
Could this be a compiler bug?
Best regards, Johannes