GCC中嵌套函数的正确语法是什么?

时间:2018-03-11 00:16:04

标签: c gcc nested-function

所以这里是原始的源代码(没有main()函数,但这里并不重要):

u_long nextrpm(u_long rpm)
{


   u_long num  = rpm;
   u_long maxrpm = 8*num;
   u_int n = log10(num) + 1;



   u_long L = rpm*10;
   u_int  ssd = 0;
   u_int  D[n];

   for(u_int i = 0; i < n ; i++){

       L = L/10;
       D[i] = (L%10);

   }


   for(u_int j = 0; j < n; j++){

     ssd = ssd + (D[j]*D[j]);

   }

   char buf[n];
   sprintf(buf,"%lu",num);



   char sbuf[n];
   sbuf [0]  = buf[n-1];
   sbuf [n-1] = buf[n-2];


   for(u_int i = 1; i < (n-1); i++){

        sbuf[i]= buf[i-1];    
   }

   u_long b1  = (u_long)atol(sbuf);
   u_int  b2  = (u_int)(b1 % 100);



   u_long result = (323*ssd)+b2;

   return (result);

}

u_long newrpm(u_long rpm, u_int y)
{


    u_long frpm = nextrpm(rpm);
    u_long maxrpm = 8*rpm;
    u_long tempo;
    u_int  years = 1;   
    bool   halt =   false;


    while(halt==false){

         tempo = nextrpm(frpm);

         if(tempo >= maxrpm){
                halt = true;  
         }

         frpm = tempo;
         years++;

         if(years >= y){
                halt = true;
         }
     }


    return frpm; 


}

现在我要做的是将nextrpm()函数作为嵌套函数插入到newrpm()函数体中。那么使用GCC这样的嵌套函数的正确语法是什么?我需要任何特殊标识符还是只需复制粘贴?

0 个答案:

没有答案