atof with EABI / C++ file problem


#1

Hi,

I’ve found a major issue with the function atof.
Here is the context of the test:

  • Open AT Application Framework 2.37.4.201209061149
  • Developer Studio 2.3.0.201212051546-R10684
  • Embedded Module: Fastrack Xtend
  • The compilation is always done in DEBUG

Here is the source code:

#include "adl_global.h"
#include "generated.h"

void main_task(void)
{
    char szVal[64], szTrace[512];
    double dVal;
    int nRoundedVal;

    strcpy(szVal, "1.4");
    dVal = atof(szVal);
    nRoundedVal = (int)(dVal + 0.5);
    sprintf(szTrace, "%s => %d", szVal, nRoundedVal);
    TRACE((1, szTrace));

    strcpy(szVal, "1.6");
    dVal = atof(szVal);
    nRoundedVal = (int)(dVal + 0.5);
    sprintf(szTrace, "%s => %d", szVal, nRoundedVal);
    TRACE((1, szTrace));
}

This is a simple usage of the atof function.
But the result of atof is not correct in all the configurations.
The expected results are:
1.4 => 1
1.6 => 2

Here are the several configurations for the test (select a build configuration and put the code sample either in a C file or in a C++ file):

  • ARM_ELF_GCC / source code in a C file => OK
  • ARM_EABI_GCC / source code in a C file => OK
  • ARM_ELF_GCC / source code in a C++ file => OK
  • ARM_EABI_GCC / source code in a C++ file => FAILURE

For the test with a C file, just create a new empty Open AT project and copy the source code given above.
For the test with a C++ file, create a new empty Open AT project, rename main.c in main.cpp, copy the source code given above and add the required extern “C” { }

extern "C" {
#include "adl_global.h"
#include "generated.h"

void main_task(void)
{
//...
}

}

If the code sample is inside a C file, there is no problem.
But if the code sample is inside a C++ file, the conversion is not correct with ARM_EABI_GCC.
The results in this case are:
1.4 => 1
1.6 => 1
The second result is WRONG !

For ARM_EABI_GCC and a C++ file, another file should be added into the project (eabi_stuc.c).
This file is modified from the version given in the Developer Studio User Guide / Build System / Advanced topics / Adding C++ code to an Open AT project (methods _read_r, _write_r, _lseek_r and _close_r should be commented).

/*
 * eabi_stub.c
 */

#include "adl_global.h"

#ifndef __REMOTETASKS__

void _sys_exit ( int a )
{
	adl_errHalt ( 999, "Application exit!" );
}
void _ttywrch(int ch)
{
	// forget char
}

#ifdef __GNU_GCC__
/*long _read_r(void *reent, int fd, void *buf, size_t cnt)
{
	adl_errHalt ( 999, "_read_r call forbidden" );
	return 0;
}*/
/*long _write_r(void *reent, int fd, const void *buf, size_t cnt)
{
	adl_errHalt ( 999, "_write_r call forbidden" );
	return 0;
}*/
/*off_t _lseek_r(void *reent, int fd, off_t pos, int whence)
{
	adl_errHalt ( 999, "_lseek_r call forbidden" );
	return 0;
}*/
int _isatty_r(void *reent, int file)
{
	adl_errHalt ( 999, "_isatty_r call forbidden" );
	return 0;
}
int _fstat_r(void *reent, int fd, struct stat *pstat)
{
	adl_errHalt ( 999, "_fstat_r call forbidden" );
	return 0;
}
/*int _close_r(void *reent, int fd)
{
	adl_errHalt ( 999, "_close_r call forbidden" );
	return 0;
}*/
int _open_r(void *reent, const char *file, int flags, int mode)
{
	adl_errHalt ( 999, "_open_r call forbidden" );
	return 0;
}
#if __GNUC_MINOR__ >= 4
int _kill(int pid, int sig)
{
	adl_errHalt ( 999, "_kill call forbidden" );
	return 0;
}
int _getpid(void)
{
	adl_errHalt ( 999, "_getpid call forbidden" );
	return 0;
}
void _exit ( int a )
{
	adl_errHalt ( 999, "Application exit!" );
}
#endif
#endif

#endif

I have 2 questions:

  • Is the atof failure in C++ / EABI a known bug ?
  • Is C++ really supported by SierraWireless and specially with ARM_EABI_GCC ?

Thanks.


#2

Hi,

yes Sierra Wireless supports C++ with both compilers EABI GCC and ELF GCC.

Thanks.


#3

This is not a known issue for us, thanks for reporting it so clearly.
This sounds like a compiler bug, and the best way to address this is to give a try with a more recent version. We have a pending task on this aspect, and will also check if this particular bug is fixed.
Will keep you informed ASAP.