I created a qt application with qt creator, the code is like,
#include "mainwindow.h"
#include <QDebug>
#include <QApplication>
#include <stdlib.h>
int main(int argc, char *argv[])
{
double before = atof("3.1");
double x;
sscanf("3.1", "%lf", &x);
QApplication a(argc, argv);
double after = atof("3.1");
double y;
sscanf("3.1", "%lf", &y);
MainWindow w;
w.show();
qDebug() << before;
qDebug() << after;
qDebug() << x;
qDebug() << y;
return a.exec();
}
the output is
3.1
3
3.1
3
That means sscanf and atof truncates fractional parts after "QApplication a(argc, argv);". The problem only occurs in Qt5.3 under Linux Mint 17. I tested the same program in windows 8 and Mac OS 10.9, they don't have the same problem. Is it a bug in Linux Qt5.3 or it has something to do with linux c library?
The complete code can be accessed here