excessive increase in program code size

Discussion about projects that used PIC Microcontroller, Hardware Interface, Programming Algorithm and etc......

excessive increase in program code size

Postby ArthurMk » Wed Mar 27, 2019 7:29 am

can anyone explain why this function takes up a lot of space when compiling (42kb)
char* DoubleToChar(double integer ,uint8_t mantis)
{
char buf[10];
uint8_t ch;
int j,i=0;
double tiv;
int size=0;
tiv=integer*pow(10,mantis);
if(tiv<0){
buf[i]=0x2D; // "-" minus
i++;
}
while(pow(10,size)<tiv){
size++;
}
j=size;
while(j!=0){
if(j==mantis){
buf[i]=0x2E; // "." ket
i++;
}
ch=tiv/(pow(10,j-1));
buf[i]=ch + 0x30; //ASCII
i++;
tiv=tiv-ch*(pow(10,j-1));
j--;
}
//=========== delete 0 =========== format "#0.0##"
for(i=size;i>0;i--){
if(buf[i]==0x30){
buf[i]=0x00;
}
else {
if(buf[i]==0x2E){
buf[i]=0x30;
}
size=0;
}
}
char *y = (char *)&buf;
return y;
}
Attachments
1.png
2.png
ArthurMk
Fledgling
 
Posts: 1
Joined: Wed Mar 27, 2019 7:26 am

Return to PIC Microcontroller

Who is online

Users browsing this forum: No registered users and 4 guests