2014-12-09 2 views
0

int 형의 변수를 선언하는 for 루프가 있는데 실제로 int를 입력하는 것과는 반대로 사용되는 이유는 모르겠습니다. 나는 두 가지의 차이점을 이해하지만 int32_t가 필요한지 모르겠다.루프 변수 선언에 대한 int32_t 유형

class Alarm_Parameter_List 
    { 
    public : 
     Alarm_Parameters alarm_Parameter[50]; 
     int Count; 
     Alarm_Parameter_List(){ Count = 0;} 
    }; 

    } 

난 그냥 int32_t 대신 INT의 사용 이유를 이해 해달라고 :

void AlarmProcess::AlarmProcess_alarm_Timer_1Sec() 
{ 
    //Timer function called every 50ms 
    static AlarmParams alarm_Params; 
    //Update LED and buzzer 
    //Buzzer is on for 1 second and off for 10 seconds then repeats. 
    //Why define index as int32_t? 
    for(int32_t i32_Index = 0;i32_Index < AlarmProcess_getInstance()->alarm_Parameter_List.Count; i32_Index++) 
    { 
     //Check for non latching mode 
     if(AlarmProcess_getInstance()->alarm_Parameter_List.alarm_Parameter[i32_Index].Latching == false) 
     { 
      //Get channel number 
      int32_t i32_Channel_Num = AlarmProcess_getInstance()->alarm_Parameter_List.alarm_Parameter[i32_Index].Channel_Number; 
      //Get alarm detection type 
      int32_t i32_Detection = AlarmProcess_getInstance()->alarm_Parameter_List.alarm_Parameter[i32_Index].Detection; 
      //Check detection type and channel number mapping 
      if((i32_Detection == HIGH && AlarmProcess_getInstance()->m_mapHighAlarmRaised[i32_Channel_Num] == true) || 
       (i32_Detection == LOW && AlarmProcess_getInstance()->m_mapLowAlarmRaised[i32_Channel_Num] == true) || 
       (i32_Detection == WINDOW_IN && AlarmProcess_getInstance()->m_mapWindowInAlarmRaised[i32_Channel_Num] == true) || 
       (i32_Detection == WINDOW_OUT && AlarmProcess_getInstance()->m_mapWindowOutAlarmRaised[i32_Channel_Num] == true)) 
      { 
       // check for buzzer on or off 
       if(s_bIsActivate == true) 
       { 
        //Check for one second elapse 
        if((s_i32alarmTimerCount[i32_Channel_Num]) >= ONE_SECOND) 
        { 
         RETAILMSG(DEBUG_ALARM_PROCESS,(_T("Buzzer off:%d\r\n"),s_i32alarmTimerCount)); 
         //Update counter variable 
         s_i32alarmTimerCount[i32_Channel_Num] = 0; 

         //Get alarm settings 
         AlarmProcess_getInstance()->b_AlarmProcess_GetAlarmsettingDetails(i32_Index,alarm_Params); 

         // Turn off the the buzzer 
         b_AlarmProcess_control_Buzzer(false,ZERO); 
         // update the flag 
         s_bIsActivate = false; 
        } 
        //Increment timer count variable 
        s_i32alarmTimerCount[i32_Channel_Num] += GPT_TIMER_RESOLUTION; 
       } 
       else 
       { 
        //Check for 10 second elapse 
        if((s_i32alarmTimerCount[i32_Channel_Num]) >= TEN_SECOND) 
        { 
         // Reinitialize the counter variable 
         s_i32alarmTimerCount[i32_Channel_Num] = 0; 
         RETAILMSG(DEBUG_ALARM_PROCESS,(_T("Buzzer ON:%d\r\n"),s_i32alarmTimerCount)); 

         //Check if buzzer need to be enabled 
         if(s_bIsBuzzer == true) 
         { 
          //Enable buzzer 
          b_AlarmProcess_control_Buzzer(true,i32_Detection); 

         } 

         // update the flag 
         s_bIsActivate = true; 
        } 
        //increment timer count variable 
        s_i32alarmTimerCount[i32_Channel_Num] += GPT_TIMER_RESOLUTION; 
       } 
      } 
     } 
    } 

그리고 Alarm_Parameter_List 클래스는 다음과 같다.

+0

이 질문에 대한 대답은 모두 "원래의 코더의 마음을 읽을 수 없습니다"범주에 속합니다. – cdhowie

+0

'AlarmProcess_getInstance() -> alarm_Parameter_List.Count' 타입이'int'이므로,'int'를 직접 사용했을 것입니다. –

+0

@RSahu :하지만'int32_t'는 _signed_ 정수형입니다. – TonyK

답변

1

내 의견으로는 그것은 단순히 나쁜 코드 일뿐입니다. 데이터 멤버 Count은 형식 지정자 int32_t 또는 int32_Index으로 선언해야하며 형식은 int이어야하며 다른 이름을 사용해야합니다. 그렇지 않으면 코드가 독자에게 혼란을줍니다.

나를 위해 다음 숫자가 음수를 저장할 수없는 경우 size_t 유형이있는 것으로 선언합니다.

-1

모든 C 플랫폼에서 32 비트 int를 사용한다고 가정하지 마십시오. 이 코드는 알람 시계에 내장 된 컨트롤러의 코드처럼 보입니다. 임베디드 컨트롤러는 더 짧은 네이티브 인 int 유형을 가진 8 비트 또는 16 비트 프로세서를 가질 가능성이 큽니다.

+0

'Count'가 'int'이기 때문에 루프 변수는 항상 'int'이어야합니다. – TonyK

+0

코드는 내장 된 장치 용이지만 알람 시계가 아닙니다. 특정 임계 조건이 충족되었다는 것을 사용자에게 알리는 경보 기능이 있습니다. 마찬가지로 프리 스케일 iMX537 마이크로 프로세서를 사용하고 있으며 OS 및 응용 프로그램 기반을 위해 WinCE7을 사용하고 있습니다. – Javia1492

관련 문제