Hi ptillisch, many thanks. My PC is a few years old, but quite capable:
(Intel(R) Core(TM) i5-2400S CPU @ 2.50GHz 2.50 GHz, 4-core).
(My M: drive is just a separate partition on the main drive. I always keep my data separate from Windows C: drive, having worked with many MS engineers over the years :-).)
I am aware that there is a lot more 'under the hood', but that does not explain why a one-line change to the sketch takes 17s (or in your case, 6s) to compile.
For example, the code below (rather more complex) takes 290 milliseconds to compile, firing up GCC from scratch: pulling in the .h files, with almost all checking enabled (I use -C99, -wall, and many more), and maximum optimisation.
Of course first time use is expensive -- but when just changing one line the IDE is 59 times slower to recompile a small test program compared to compiling a more complex test program using GCC as a command.
Something must be wrong, surely?
// test charnum function
// call as e.g.,: charnum 1.234
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h> // for strtod
#include <math.h>
#define MAXLEN 20
#define DUBLEN 24
#define Int int
char *charnumber(char *chars, double number, Int frac);
int main(int argc, char *argv[]) {
if (argc>0) printf("Running: %s\n", argv[0]);
char buff[MAXLEN+1];
int arglen=0;
if (argc>1) arglen=strlen(argv[1]);
if (arglen==0 || arglen>MAXLEN) strcpy(buff, "2.123456");
else strcpy(buff, argv[1]);
char *end;
double num=strtod(buff, &end);
if (end==buff) {
printf("Bad number: %s\n", buff);
return -1;
}
char db[DUBLEN]; // work
charnumber(db, num, 3);
printf("\ncharnumber(%f) -> %s\n\n", num, db);
return 0;
} // main
/* --------------------------------------------------------------- */
/* charnumber -- format a number like 'f' but with 'g' trimming */
/* */
/* chars -- buffer into which to format [>=DUBLEN chars] */
/* number -- number to format */
/* frac -- maximum number of digits after the decimal point */
/* */
/* returns chars */
/* */
/* This formats with the printf 'f' pattern, then trims trailing */
/* zeros and decimal point, if any. */
/* --------------------------------------------------------------- */
char *charnumber(char *chars, double number, Int frac) {
snprintf(chars, DUBLEN, "%1.*f", frac, number);
if (frac==0) return chars; // no fractional part to trim
for (Int i=strlen(chars)-1; i>0; i--) {
if (chars[i]=='.') {
chars[i]='\0'; // trim '.'
break;}
if (chars[i]!='0') break; // non-0 found
chars[i]='\0'; // trim '0'
}
return chars;
} // charnumber